Skip to content

Commit 551df1c

Browse files
Adding python and MS SQL Devcontainer (#1)
* first draft * second changes * Update test-pr.yaml * cleanup * Update build.sh * Update build.sh * fixing issues. * removing requirements * Update Dockerfile * Update build.sh * Update docker-compose.yml * Update build.sh * Update build.sh * Update build.sh * Update devcontainer.json * Update devcontainer.json * Update .github/actions/smoke-test/build.sh Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com> * Update src/python-mssql/.devcontainer/devcontainer.json Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com> * Update devcontainer.json * Update build.sh * Update docker-compose.yml * Update devcontainer.json --------- Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
1 parent d1f51bc commit 551df1c

File tree

25 files changed

+640
-91
lines changed

25 files changed

+640
-91
lines changed

.devcontainer/devcontainer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// More info: https://containers.dev/implementors/json_reference/
2+
{
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"mads-hartmann.bash-ide-vscode",
11+
"dbaeumer.vscode-eslint"
12+
]
13+
}
14+
},
15+
"postCreateCommand": "npm install -g @devcontainers/cli"
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Smoke test'
2+
inputs:
3+
template:
4+
description: 'Template to test'
5+
required: true
6+
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Checkout main
11+
id: checkout_release
12+
uses: actions/checkout@v3
13+
14+
- name: Build template
15+
id: build_template
16+
shell: bash
17+
run: ${{ github.action_path }}/build.sh ${{ inputs.template }}
18+
19+
- name: Test template
20+
id: test_template
21+
shell: bash
22+
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
TEMPLATE_ID="$1"
3+
4+
set -e
5+
6+
shopt -s dotglob
7+
8+
SRC_DIR="/tmp/${TEMPLATE_ID}"
9+
cp -R "src/${TEMPLATE_ID}" "${SRC_DIR}"
10+
11+
pushd "${SRC_DIR}"
12+
13+
# Configure templates only if `devcontainer-template.json` contains the `options` property.
14+
OPTION_PROPERTY=( $(jq -r '.options' devcontainer-template.json) )
15+
16+
if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then
17+
OPTIONS=( $(jq -r '.options | keys[]' devcontainer-template.json) )
18+
19+
if [ "${OPTIONS[0]}" != "" ] && [ "${OPTIONS[0]}" != "null" ] ; then
20+
echo "(!) Configuring template options for '${TEMPLATE_ID}'"
21+
for OPTION in "${OPTIONS[@]}"
22+
do
23+
OPTION_KEY="\${templateOption:$OPTION}"
24+
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)
25+
26+
if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
27+
echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'"
28+
exit 1
29+
fi
30+
31+
echo "(!) Replacing '${OPTION_KEY}' with '${OPTION_VALUE}'"
32+
OPTION_VALUE_ESCAPED=$(sed -e 's/[]\/$*.^[]/\\&/g' <<<"${OPTION_VALUE}")
33+
find ./ -type f -print0 | xargs -0 sed -i "s/${OPTION_KEY}/${OPTION_VALUE_ESCAPED}/g"
34+
done
35+
fi
36+
fi
37+
38+
popd
39+
40+
TEST_DIR="test/${TEMPLATE_ID}"
41+
if [ -d "${TEST_DIR}" ] ; then
42+
echo "(*) Copying test folder"
43+
DEST_DIR="${SRC_DIR}/test-project"
44+
mkdir -p ${DEST_DIR}
45+
cp -Rp ${TEST_DIR}/* ${DEST_DIR}
46+
cp test/test-utils/test-utils.sh ${DEST_DIR}
47+
fi
48+
49+
export DOCKER_BUILDKIT=1
50+
echo "(*) Installing @devcontainer/cli"
51+
npm install -g @devcontainers/cli
52+
53+
echo "Building Dev Container"
54+
ID_LABEL="test-container=${TEMPLATE_ID}"
55+
devcontainer up --id-label ${ID_LABEL} --workspace-folder "${SRC_DIR}" --log-level trace

.github/actions/smoke-test/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
TEMPLATE_ID="$1"
3+
set -e
4+
5+
SRC_DIR="/tmp/${TEMPLATE_ID}"
6+
echo "Running Smoke Test"
7+
8+
ID_LABEL="test-container=${TEMPLATE_ID}"
9+
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'
10+
11+
# Clean up
12+
docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q)
13+
rm -rf "${SRC_DIR}"

.github/workflows/release.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "Release Dev Container Templates & Generate Documentation"
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
deploy:
7+
if: ${{ github.ref == 'refs/heads/main' }}
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: "Publish Templates"
13+
uses: devcontainers/action@v1
14+
with:
15+
publish-templates: "true"
16+
base-path-to-templates: "./src"
17+
generate-docs: "true"
18+
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Create PR for Documentation
23+
id: push_image_info
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
set -e
28+
echo "Start."
29+
30+
# Configure git and Push updates
31+
git config --global user.email github-actions@github.com
32+
git config --global user.name github-actions
33+
git config pull.rebase false
34+
35+
branch=automated-documentation-update-$GITHUB_RUN_ID
36+
git checkout -b $branch
37+
message='Automated documentation update'
38+
39+
# Add / update and commit
40+
git add */**/README.md
41+
git commit -m 'Automated documentation update [skip ci]' || export NO_UPDATES=true
42+
43+
# Push
44+
if [ "$NO_UPDATES" != "true" ] ; then
45+
git push origin "$branch"
46+
gh pr create --title "$message" --body "$message"
47+
fi

.github/workflows/test-pr.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "CI - Test Templates"
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
detect-changes:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
templates: ${{ steps.filter.outputs.changes }}
10+
steps:
11+
- uses: dorny/paths-filter@v2
12+
id: filter
13+
with:
14+
filters: |
15+
python-mssql: ./**/python-mssql/**
16+
17+
test:
18+
needs: [detect-changes]
19+
runs-on: ubuntu-latest
20+
continue-on-error: true
21+
strategy:
22+
matrix:
23+
templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }}
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Smoke test for '${{ matrix.templates }}'
28+
id: smoke_test
29+
uses: ./.github/actions/smoke-test
30+
with:
31+
template: "${{ matrix.templates }}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
**/.DS_Store

CHANGELOG.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,20 @@
1-
# Project Name
2-
3-
(short, 1-3 sentenced, description of the project)
4-
5-
## Features
6-
7-
This project framework provides the following features:
8-
9-
* Feature 1
10-
* Feature 2
11-
* ...
12-
13-
## Getting Started
14-
15-
### Prerequisites
16-
17-
(ideally very short, if any)
18-
19-
- OS
20-
- Library version
21-
- ...
22-
23-
### Installation
24-
25-
(ideally very short)
26-
27-
- npm install [package name]
28-
- mvn install
29-
- ...
30-
31-
### Quickstart
32-
(Add steps to get up and running quickly)
33-
34-
1. git clone [repository clone url]
35-
2. cd [repository name]
36-
3. ...
37-
38-
39-
## Demo
40-
41-
A demo app is included to show how to use the project.
42-
43-
To run the demo, follow these steps:
44-
45-
(Add steps to start up the demo)
46-
47-
1.
48-
2.
49-
3.
50-
51-
## Resources
52-
53-
(Any additional resources or related projects)
54-
55-
- Link to supporting information
56-
- Link to similar sample
57-
- ...
1+
# Python and MS SQL Server (Python-mssql)
2+
3+
> 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.
4+
5+
## Repo and Template Structure
6+
7+
This repository contains a template with the following structure:
8+
```
9+
├── src
10+
│ ├── python-mssql
11+
│ │ ├── devcontainer-template.json
12+
│ │ └──| .devcontainer
13+
│ │ └── devcontainer.json
14+
├── test
15+
│ ├── python-mssql
16+
│ │ └── test.sh
17+
│ └──test-utils
18+
│ └── test-utils.sh
19+
...
20+
```

0 commit comments

Comments
 (0)