Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding python and MS SQL Devcontainer #1

Merged
merged 22 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// More info: https://containers.dev/implementors/json_reference/
{
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"mads-hartmann.bash-ide-vscode",
"dbaeumer.vscode-eslint"
]
}
},
"postCreateCommand": "npm install -g @devcontainers/cli"
}
22 changes: 22 additions & 0 deletions .github/actions/smoke-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Smoke test'
inputs:
template:
description: 'Template to test'
required: true

runs:
using: composite
steps:
- name: Checkout main
id: checkout_release
uses: actions/checkout@v3

- name: Build template
id: build_template
shell: bash
run: ${{ github.action_path }}/build.sh ${{ inputs.template }}

- name: Test template
id: test_template
shell: bash
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
58 changes: 58 additions & 0 deletions .github/actions/smoke-test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
TEMPLATE_ID="$1"

set -e

shopt -s dotglob

SRC_DIR="/tmp/${TEMPLATE_ID}"
cp -R "src/${TEMPLATE_ID}" "${SRC_DIR}"

pushd "${SRC_DIR}"

# Configure templates only if `devcontainer-template.json` contains the `options` property.
OPTION_PROPERTY=( $(jq -r '.options' devcontainer-template.json) )

if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then
OPTIONS=( $(jq -r '.options | keys[]' devcontainer-template.json) )

if [ "${OPTIONS[0]}" != "" ] && [ "${OPTIONS[0]}" != "null" ] ; then
echo "(!) Configuring template options for '${TEMPLATE_ID}'"
for OPTION in "${OPTIONS[@]}"
do
OPTION_KEY="\${templateOption:$OPTION}"
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)

if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'"
exit 1
fi

echo "(!) Replacing '${OPTION_KEY}' with '${OPTION_VALUE}'"
OPTION_VALUE_ESCAPED=$(sed -e 's/[]\/$*.^[]/\\&/g' <<<"${OPTION_VALUE}")
find ./ -type f -print0 | xargs -0 sed -i "s/${OPTION_KEY}/${OPTION_VALUE_ESCAPED}/g"
done
fi
fi

popd

TEST_DIR="test/${TEMPLATE_ID}"
if [ -d "${TEST_DIR}" ] ; then
echo "(*) Copying test folder"
DEST_DIR="${SRC_DIR}/test-project"
mkdir -p ${DEST_DIR}
cp -Rp ${TEST_DIR}/* ${DEST_DIR}
cp test/test-utils/test-utils.sh ${DEST_DIR}
fi

export DOCKER_BUILDKIT=1
echo "(*) Installing @devcontainer/cli"
npm install -g @devcontainers/cli

echo "Building Dev Container"
ID_LABEL="test-container=${TEMPLATE_ID}"
echo "I am up to here 1"
echo "${SRC_DIR}"
devcontainer up --id-label ${ID_LABEL} --workspace-folder "${SRC_DIR}"
msetbar marked this conversation as resolved.
Show resolved Hide resolved
echo "I am up to here 2"
13 changes: 13 additions & 0 deletions .github/actions/smoke-test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
TEMPLATE_ID="$1"
set -e

SRC_DIR="/tmp/${TEMPLATE_ID}"
echo "Running Smoke Test"

ID_LABEL="test-container=${TEMPLATE_ID}"
devcontainer exec --workspace-folder "${SRC_DIR}" --id-label ${ID_LABEL} /bin/sh -c 'set -e && if [ -f "test-project/test.sh" ]; then cd test-project && if [ "$(id -u)" = "0" ]; then chmod +x test.sh; else sudo chmod +x test.sh; fi && ./test.sh; else ls -a; fi'

# Clean up
docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q)
rm -rf "${SRC_DIR}"
47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Release Dev Container Templates & Generate Documentation"
on:
workflow_dispatch:

jobs:
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: "Publish Templates"
uses: devcontainers/action@v1
with:
publish-templates: "true"
base-path-to-templates: "./src"
generate-docs: "true"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create PR for Documentation
id: push_image_info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
echo "Start."

# Configure git and Push updates
git config --global user.email [email protected]
git config --global user.name github-actions
git config pull.rebase false

branch=automated-documentation-update-$GITHUB_RUN_ID
git checkout -b $branch
message='Automated documentation update'

# Add / update and commit
git add */**/README.md
git commit -m 'Automated documentation update [skip ci]' || export NO_UPDATES=true

# Push
if [ "$NO_UPDATES" != "true" ] ; then
git push origin "$branch"
gh pr create --title "$message" --body "$message"
fi
31 changes: 31 additions & 0 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "CI - Test Templates"
on:
pull_request:

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
templates: ${{ steps.filter.outputs.changes }}
steps:
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
python-mssql: ./**/python-mssql/**

test:
needs: [detect-changes]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }}
steps:
- uses: actions/checkout@v3

- name: Smoke test for '${{ matrix.templates }}'
id: smoke_test
uses: ./.github/actions/smoke-test
with:
template: "${{ matrix.templates }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

**/.DS_Store
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE.md

This file was deleted.

77 changes: 20 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,20 @@
# Project Name

(short, 1-3 sentenced, description of the project)

## Features

This project framework provides the following features:

* Feature 1
* Feature 2
* ...

## Getting Started

### Prerequisites

(ideally very short, if any)

- OS
- Library version
- ...

### Installation

(ideally very short)

- npm install [package name]
- mvn install
- ...

### Quickstart
(Add steps to get up and running quickly)

1. git clone [repository clone url]
2. cd [repository name]
3. ...


## Demo

A demo app is included to show how to use the project.

To run the demo, follow these steps:

(Add steps to start up the demo)

1.
2.
3.

## Resources

(Any additional resources or related projects)

- Link to supporting information
- Link to similar sample
- ...
# Python and MS SQL Server (Python-mssql)

> This repo provides a template for Python and MS SQL Server development. It is intended to be used with the [VS Code Remote - Containers](https://aka.ms/vscode-remote/containers) extension.

## Repo and Template Structure

This repository contains a template with the following structure:
```
├── src
│ ├── python-mssql
│ │ ├── devcontainer-template.json
│ │ └──| .devcontainer
│ │ └── devcontainer.json
├── test
│ ├── python-mssql
│ │ └── test.sh
│ └──test-utils
│ └── test-utils.sh
...
```
18 changes: 18 additions & 0 deletions src/color/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Favorite color",
"image": "mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant}",

// 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features.
// "features": {},

// 👇 Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

"postCreateCommand": "echo '${templateOption:favorite}' > /tmp/color.txt"

// 👇 Configure tool-specific properties.
// "customizations": {},

// 👇 Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
17 changes: 17 additions & 0 deletions src/color/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# My Favorite Color (color)

A Template to remind you of your favorite color

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| imageVariant | Debian version (use bullseye on local arm64/Apple Silicon): | string | bullseye |
| favorite | Choose your favorite color. | string | red |



---

_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/devcontainers/template-starter/blob/main/src/color/devcontainer-template.json). Add additional notes to a `NOTES.md`._
32 changes: 32 additions & 0 deletions src/color/devcontainer-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "color",
"version": "1.0.0",
"name": "My Favorite Color",
"description": "A Template to remind you of your favorite color",
"documentationURL": "https://github.com/devcontainers/template-starter/tree/main/src/color",
"licenseURL": "https://github.com/devcontainers/template-starter/blob/main/LICENSE",
"options": {
"imageVariant": {
"type": "string",
"description": "Debian version (use bullseye on local arm64/Apple Silicon):",
"proposals": [
"bullseye",
"buster"
],
"default": "bullseye"
},
"favorite": {
"type": "string",
"description": "Choose your favorite color.",
"proposals": [
"red",
"gold",
"green"
],
"default": "red"
}
},
"platforms": [
"Any"
]
}
Loading
Loading