From a6c26332f04fd249a8b51b4ff4668fa1d4c4c3d8 Mon Sep 17 00:00:00 2001 From: Alexander Ilyin Date: Thu, 22 Aug 2024 15:52:26 +0000 Subject: [PATCH] Create initial template; --- .devcontainer/devcontainer-lock.json | 45 +++++++ .devcontainer/devcontainer.json | 151 ++++++++++++++++++++-- .env | 1 + .github/actions/smoke-test/action.yaml | 2 +- .github/actions/smoke-test/build.sh | 2 +- .github/workflows/test-pr.yaml | 5 +- .pre-commit-config.yaml | 12 ++ README.md | 113 +--------------- op.ps1 | 11 ++ src/color/.devcontainer/devcontainer.json | 18 --- src/color/README.md | 17 --- src/color/devcontainer-template.json | 32 ----- src/hello/.devcontainer/Dockerfile | 4 - src/hello/.devcontainer/devcontainer.json | 21 --- src/hello/README.md | 17 --- src/hello/devcontainer-template.json | 34 ----- src/ubik/.devcontainer/devcontainer.json | 75 +++++++++++ src/ubik/NOTES.md | 7 + src/ubik/README.md | 23 ++++ src/ubik/devcontainer-template.json | 22 ++++ test/color/test.sh | 10 -- test/hello/test.sh | 10 -- test/test-utils/test-utils.sh | 4 +- test/ubik/test.sh | 14 ++ 24 files changed, 356 insertions(+), 294 deletions(-) create mode 100644 .devcontainer/devcontainer-lock.json create mode 100644 .env create mode 100644 .pre-commit-config.yaml create mode 100644 op.ps1 delete mode 100644 src/color/.devcontainer/devcontainer.json delete mode 100644 src/color/README.md delete mode 100644 src/color/devcontainer-template.json delete mode 100644 src/hello/.devcontainer/Dockerfile delete mode 100644 src/hello/.devcontainer/devcontainer.json delete mode 100644 src/hello/README.md delete mode 100644 src/hello/devcontainer-template.json create mode 100644 src/ubik/.devcontainer/devcontainer.json create mode 100644 src/ubik/NOTES.md create mode 100644 src/ubik/README.md create mode 100644 src/ubik/devcontainer-template.json delete mode 100644 test/color/test.sh delete mode 100644 test/hello/test.sh create mode 100644 test/ubik/test.sh diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json new file mode 100644 index 0000000..936a902 --- /dev/null +++ b/.devcontainer/devcontainer-lock.json @@ -0,0 +1,45 @@ +{ + "features": { + "ghcr.io/deep-space-cartel/devcontainers-features/apt:1": { + "version": "1.1.0", + "resolved": "ghcr.io/deep-space-cartel/devcontainers-features/apt@sha256:3a8ef060a682ecded4d2b68c951a4f58d22629df4f169534ae9b4e647a60e8d2", + "integrity": "sha256:3a8ef060a682ecded4d2b68c951a4f58d22629df4f169534ae9b4e647a60e8d2" + }, + "ghcr.io/deep-space-cartel/devcontainers-features/pip:1": { + "version": "1.0.0", + "resolved": "ghcr.io/deep-space-cartel/devcontainers-features/pip@sha256:9e68548232099e2fa129723ae3c0962b59416c16028c8d7c1a10d963a3ff05ac", + "integrity": "sha256:9e68548232099e2fa129723ae3c0962b59416c16028c8d7c1a10d963a3ff05ac", + "dependsOn": [ + "ghcr.io/deep-space-cartel/devcontainers-features/apt:1" + ] + }, + "ghcr.io/deep-space-cartel/devcontainers-features/starship:1": { + "version": "1.2.0", + "resolved": "ghcr.io/deep-space-cartel/devcontainers-features/starship@sha256:70ae84bb250918d1da871ca6e2bdc7017ff420cc7dd04bafc0ec6ecb8527e4ef", + "integrity": "sha256:70ae84bb250918d1da871ca6e2bdc7017ff420cc7dd04bafc0ec6ecb8527e4ef", + "dependsOn": [ + "ghcr.io/devcontainers/features/common-utils" + ] + }, + "ghcr.io/devcontainers/features/common-utils": { + "version": "2.5.1", + "resolved": "ghcr.io/devcontainers/features/common-utils@sha256:9da676524999513412f2c27604d786ba0bbf3575eb1859166c5a1233f037fc08", + "integrity": "sha256:9da676524999513412f2c27604d786ba0bbf3575eb1859166c5a1233f037fc08" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "version": "2.11.0", + "resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:503f23cd692325b3cbb8c20a0ecfabb3444b0c786b363e0c82572bd7d71dc099", + "integrity": "sha256:503f23cd692325b3cbb8c20a0ecfabb3444b0c786b363e0c82572bd7d71dc099" + }, + "ghcr.io/devcontainers/features/git:1": { + "version": "1.3.2", + "resolved": "ghcr.io/devcontainers/features/git@sha256:63c96e8ac33f5630300d8883e2ec3123278de70d318589af596ea1954846014d", + "integrity": "sha256:63c96e8ac33f5630300d8883e2ec3123278de70d318589af596ea1954846014d" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "1.0.13", + "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:13b301a039ce9e0bb07d45ea0c106c946cfff01c3b9844bbec6b0c7bacba8de3", + "integrity": "sha256:13b301a039ce9e0bb07d45ea0c106c946cfff01c3b9844bbec6b0c7bacba8de3" + } + } +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2fec915..7cc2ad5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,141 @@ // More info: https://containers.dev/implementors/json_reference/ { - "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye", - "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" + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye", + "remoteEnv": { + "WAKATIME_API_KEY": "${localEnv:WAKATIME_API_KEY}", + "PATH": "${containerEnv:PATH}:/opt/pip/bin" + }, + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/deep-space-cartel/devcontainers-features/starship:1": {}, + "ghcr.io/deep-space-cartel/devcontainers-features/apt:1": { + "packages": "bash-completion shellcheck mc python3-pip python3-venv" // shfmt + }, + "ghcr.io/deep-space-cartel/devcontainers-features/pip:1": { + "packages": "pre-commit", + "location": "/opt/pip" + } + }, + "customizations": { + "vscode": { + "settings": { + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "pre-commit: manual", + "type": "shell", + "command": "pre-commit", + "args": [ + "run", + "--hook-stage", + "manual" + ], + "group": { + "kind": "test", + "isDefault": false + } + }, + { + "label": "Dev Containers: Build ubik", + "type": "shell", + "command": ".github/actions/smoke-test/build.sh", + "args": [ + "ubik" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Starship: Install Completions", + "type": "shell", + "command": "sudo", + "args": [ + "bash", + "-c", + "starship completions $(basename $SHELL) > /etc/bash_completion.d/99-starship-completions.sh" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Dev Containers: Publish Templates", + "type": "shell", + "command": "devcontainer", + "args": [ + "templates", + "publish", + "--namespace", + "deep-space-cartel/devcontainers-templates", + "src/" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Dev Containers: Upgrade lockfile", + "type": "shell", + "command": "devcontainer", + "args": [ + "upgrade", + "--workspace-folder", + "." + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Dev Container Feature: Generate Docs", + "type": "shell", + "command": "devcontainer", + "args": [ + "templates", + "generate-docs", + "--github-owner", + "deep-space-cartel", + "--github-repo", + "devcontainers-templates", + "--project-folder", + "src/" + ], + "group": { + "kind": "build", + "isDefault": false + } + } + ] + }, + "editor.fontFamily": "'Hack Nerd Font Mono'", + "terminal.integrated.fontFamily": "'Hack Nerd Font Mono'", + "files.insertFinalNewline": true, + "dotfiles.repository": "deep-space-cartel/dotfiles", + "cSpell.enableFiletypes": [ + "*" + ], + "remote.extensionKind": { + "ms-vscode.PowerShell": [ + "ui" + ], + "1Password.op-vscode": [ + "ui" + ] + } + }, + "extensions": [ + "mads-hartmann.bash-ide-vscode", + "dbaeumer.vscode-eslint" + ] + } + }, + "postCreateCommand": "npm install -g @devcontainers/cli" } diff --git a/.env b/.env new file mode 100644 index 0000000..1792869 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +GITHUB_TOKEN = "op://DeepSpaceCartel/GITHUB_TOKEN/CLASSIC" diff --git a/.github/actions/smoke-test/action.yaml b/.github/actions/smoke-test/action.yaml index 5f98ba8..2d7fc34 100644 --- a/.github/actions/smoke-test/action.yaml +++ b/.github/actions/smoke-test/action.yaml @@ -19,4 +19,4 @@ runs: - name: Test template id: test_template shell: bash - run: ${{ github.action_path }}/test.sh ${{ inputs.template }} \ No newline at end of file + run: ${{ github.action_path }}/test.sh ${{ inputs.template }} diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh index a5b90eb..870ae3b 100755 --- a/.github/actions/smoke-test/build.sh +++ b/.github/actions/smoke-test/build.sh @@ -13,7 +13,7 @@ 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 +if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then OPTIONS=( $(jq -r '.options | keys[]' devcontainer-template.json) ) if [ "${OPTIONS[0]}" != "" ] && [ "${OPTIONS[0]}" != "null" ] ; then diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 778bed4..6377001 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -12,8 +12,7 @@ jobs: id: filter with: filters: | - color: ./**/color/** - hello: ./**/hello/** + ubik: ./**/ubik/** test: needs: [detect-changes] @@ -23,7 +22,7 @@ jobs: matrix: templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Smoke test for '${{ matrix.templates }}' id: smoke_test diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0729348 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: mixed-line-ending + args: ['--fix=lf'] diff --git a/README.md b/README.md index 974ac6d..bba7660 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,6 @@ -# Dev Container Templates: Self Authoring Guide +# Dev Containers Templates -> This repo provides a starting point and example for creating your own custom [Dev Container Templates](https://containers.dev/implementors/templates), hosted for free on GitHub Container Registry. The example in this repository follows the [Dev Container Template distribution specification](https://containers.dev/implementors/templates-distribution/). -> -> To provide feedback on the distribution spec, please leave a comment [on spec issue #71](https://github.com/devcontainers/spec/issues/71). - -## Repo and Template Structure - -This repository contains a _collection_ of two Templates - `hello` and `color`. These Templates serve as simple template implementations which helps containerize the project. Similar to the [`devcontainers/templates`](https://github.com/devcontainers/templates) repo, this repository has a `src` folder. Each Template has its own sub-folder, containing at least a `devcontainer-template.json` and `.devcontainer/devcontainer.json`. - -``` -├── src -│ ├── color -│ │ ├── devcontainer-template.json -│ │ └──| .devcontainer -│ │ └── devcontainer.json -│ ├── hello -│ │ ├── devcontainer-template.json -│ │ └──| .devcontainer -│ │ ├── devcontainer.json -│ │ └── Dockerfile -| ├── ... -│ │ ├── devcontainer-template.json -│ │ └──| .devcontainer -│ │ └── devcontainer.json -├── test -│ ├── color -│ │ └── test.sh -│ ├── hello -│ │ └── test.sh -│ └──test-utils -│ └── test-utils.sh -... -``` - -### Options - -All available options for a Template should be declared in the `devcontainer-template.json`. The syntax for the `options` property can be found in the [devcontainer Template json properties reference](https://containers.dev/implementors/templates#devcontainer-templatejson-properties). - -For example, the `color` Template provides three possible options (`red`, `gold`, `green`), where the default value is set to "red". - -```jsonc -{ - // ... - "options": { - "favorite": { - "type": "string", - "description": "Choose your favorite color." - "proposals": [ - "red", - "gold", - "green" - ], - "default": "red" - } - } -} -``` - -An [implementing tool](https://containers.dev/supporting#tools) will use the `options` property from [the documented Dev Container Template properties](https://containers.dev/implementors/templates#devcontainer-templatejson-properties) for customizing the Template. See [option resolution example](https://containers.dev/implementors/templates#option-resolution-example) for details. - -## Distributing Templates - -**Note**: *Allow GitHub Actions to create and approve pull requests* should be enabled in the repository's `Settings > Actions > General > Workflow permissions` for auto generation of `src/