From fdc0ca997fb2a534459e1338669cb90f0edcba17 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Sun, 8 Jun 2025 17:02:29 +0000 Subject: [PATCH 1/3] Cleaned up template examples and added nix-dood dev container --- .github/actions/smoke-test/build.sh | 2 +- Makefile | 7 ++++ 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/nix-dood/.devcontainer/Dockerfile | 6 ++++ src/nix-dood/.devcontainer/devcontainer.json | 23 +++++++++++++ src/nix-dood/devcontainer-template.json | 23 +++++++++++++ test/hello/test.sh | 10 ------ test/{color => nix-dood}/test.sh | 2 +- test/test-utils/test-utils.sh | 4 +-- 15 files changed, 63 insertions(+), 157 deletions(-) create mode 100644 Makefile 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/nix-dood/.devcontainer/Dockerfile create mode 100644 src/nix-dood/.devcontainer/devcontainer.json create mode 100644 src/nix-dood/devcontainer-template.json delete mode 100644 test/hello/test.sh rename test/{color => nix-dood}/test.sh (68%) diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh index 60a5fff..72dfa1a 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/Makefile b/Makefile new file mode 100644 index 0000000..a8daee1 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +CONTAINERID ?= $(shell bash -c 'read -p "Dev Container ID: " dci; echo $$dci') + +build: + ./.github/actions/smoke-test/build.sh $(CONTAINERID) + +run-tests: + ./.github/actions/smoke-test/test.sh $(CONTAINERID) diff --git a/src/color/.devcontainer/devcontainer.json b/src/color/.devcontainer/devcontainer.json deleted file mode 100644 index 0c20573..0000000 --- a/src/color/.devcontainer/devcontainer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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" -} diff --git a/src/color/README.md b/src/color/README.md deleted file mode 100644 index a329dff..0000000 --- a/src/color/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# 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`._ diff --git a/src/color/devcontainer-template.json b/src/color/devcontainer-template.json deleted file mode 100644 index a64d31c..0000000 --- a/src/color/devcontainer-template.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "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" - ] -} diff --git a/src/hello/.devcontainer/Dockerfile b/src/hello/.devcontainer/Dockerfile deleted file mode 100644 index 9c45c4c..0000000 --- a/src/hello/.devcontainer/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant} - -RUN mkdir -p /usr/local/etc \ - && echo "${templateOption:greeting}" > /usr/local/etc/greeting.txt \ No newline at end of file diff --git a/src/hello/.devcontainer/devcontainer.json b/src/hello/.devcontainer/devcontainer.json deleted file mode 100644 index fc33f83..0000000 --- a/src/hello/.devcontainer/devcontainer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Hello, World", - "build": { - "dockerfile": "Dockerfile" - }, - - // ๐Ÿ‘‡ 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": [], - - // ๐Ÿ‘‡ Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "cat /usr/local/etc/greeting.txt" - - // ๐Ÿ‘‡ Configure tool-specific properties. - // "customizations": {}, - - // ๐Ÿ‘‡ Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/src/hello/README.md b/src/hello/README.md deleted file mode 100644 index 2cdac8f..0000000 --- a/src/hello/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Hello, World (hello) - -A hello world Template - -## Options - -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| imageVariant | Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): | string | jammy | -| greeting | Select a pre-made greeting, or enter your own | string | hey | - - - ---- - -_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/devcontainers/template-starter/blob/main/src/hello/devcontainer-template.json). Add additional notes to a `NOTES.md`._ diff --git a/src/hello/devcontainer-template.json b/src/hello/devcontainer-template.json deleted file mode 100644 index 342c75e..0000000 --- a/src/hello/devcontainer-template.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "id": "hello", - "version": "1.0.0", - "name": "Hello, World", - "description": "A hello world Template", - "documentationURL": "https://github.com/devcontainers/template-starter/tree/main/src/hello", - "licenseURL": "https://github.com/devcontainers/template-starter/blob/main/LICENSE", - "options": { - "imageVariant": { - "type": "string", - "description": "Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon):", - "proposals": [ - "jammy", - "focal", - "bionic" - ], - "default": "jammy" - }, - "greeting": { - "type": "string", - "description": "Select a pre-made greeting, or enter your own", - "proposals": [ - "hey", - "hello", - "hi", - "howdy" - ], - "default": "hey" - } - }, - "platforms": [ - "Any" - ] -} diff --git a/src/nix-dood/.devcontainer/Dockerfile b/src/nix-dood/.devcontainer/Dockerfile new file mode 100644 index 0000000..67c7eb8 --- /dev/null +++ b/src/nix-dood/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/xtruder/nix-devcontainer:v1 + +RUN echo "${templateOption:greeting}" > ~/greeting.txt + +# cache /nix +VOLUME /nix \ No newline at end of file diff --git a/src/nix-dood/.devcontainer/devcontainer.json b/src/nix-dood/.devcontainer/devcontainer.json new file mode 100644 index 0000000..bf93d0a --- /dev/null +++ b/src/nix-dood/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +{ + "name": "feenx-nix-dood", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + + "userEnvProbe": "loginShell", + "postCreateCommand": "cat ~/greeting.txt", + + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker", + "arrterian.nix-env-selector" + ] + } + }, + + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + } +} \ No newline at end of file diff --git a/src/nix-dood/devcontainer-template.json b/src/nix-dood/devcontainer-template.json new file mode 100644 index 0000000..2c894f7 --- /dev/null +++ b/src/nix-dood/devcontainer-template.json @@ -0,0 +1,23 @@ +{ + "id": "nix-dood", + "version": "1.0.0", + "name": "Nix with Docker outside of Docker", + "description": "A Template to use nix flakes and the devcontainer's docker host access.", + "documentationURL": "https://github.com/feenx-lab/feenx-devcontainers/tree/main/src/nix-dood", + "licenseURL": "https://github.com/feenx-lab/feenx-devcontainers/blob/main/LICENSE", + "options": { + "greeting": { + "type": "string", + "description": "Select a pre-made greeting, or enter your own", + "proposals": [ + "Welcome to your declarative, Nix-powered, dev environment setup.", + "Dev environment ready.", + "Autobots assemble!" + ], + "default": "Welcome to your declarative, Nix-powered, dev environment setup." + } + }, + "platforms": [ + "Any" + ] +} diff --git a/test/hello/test.sh b/test/hello/test.sh deleted file mode 100644 index 0428c34..0000000 --- a/test/hello/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Template specific tests -check "distro" lsb_release -c -check "greeting" [ $(cat /usr/local/etc/greeting.txt | grep hey) ] - -# Report result -reportResults diff --git a/test/color/test.sh b/test/nix-dood/test.sh similarity index 68% rename from test/color/test.sh rename to test/nix-dood/test.sh index b75ba5b..6f06a79 100644 --- a/test/color/test.sh +++ b/test/nix-dood/test.sh @@ -4,7 +4,7 @@ source test-utils.sh # Template specific tests check "distro" lsb_release -c -check "color" [ $(cat /tmp/color.txt | grep red) ] +check "greeting" [ $(cat /home/code/greeting.txt | grep dev) ] # Report result reportResults diff --git a/test/test-utils/test-utils.sh b/test/test-utils/test-utils.sh index 5e4b4ae..f3b94d9 100644 --- a/test/test-utils/test-utils.sh +++ b/test/test-utils/test-utils.sh @@ -11,7 +11,7 @@ check() { LABEL=$1 shift echo -e "\n๐Ÿงช Testing $LABEL" - if "$@"; then + if [ -n "$*" ]; then echo "โœ… Passed!" return 0 else @@ -25,7 +25,7 @@ reportResults() { if [ ${#FAILED[@]} -ne 0 ]; then echoStderr -e "\n๐Ÿ’ฅ Failed tests: ${FAILED[@]}" exit 1 - else + else echo -e "\n๐Ÿ’ฏ All passed!" exit 0 fi From 35f9ca501d12d02ff0ed090d93001d2f4fb601f0 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Sun, 8 Jun 2025 17:31:34 +0000 Subject: [PATCH 2/3] Fixed CI build to check for nix-dood and not the examples anymore and added a PR request template --- .github/pull_request_template.md | 7 +++++++ .github/workflows/test-pr.yaml | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..e667bc2 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ +## Describe your changes + +Briefly describe the feature being introduced. + +## Checklist before requesting a review +- [ ] I have performed a self-review of my code +- [ ] If it is a core feature, I have added thorough tests. \ No newline at end of file diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 778bed4..70417ed 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/** + color: ./**/nix-dood/** test: needs: [detect-changes] From 747f701bb4834a53b988587374e72338f0832907 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Sun, 8 Jun 2025 17:33:39 +0000 Subject: [PATCH 3/3] Fixed the naming of the filter for detect-changes job to match nix-dood --- .github/workflows/test-pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 70417ed..cfa9f2f 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -12,7 +12,7 @@ jobs: id: filter with: filters: | - color: ./**/nix-dood/** + nix-dood: ./**/nix-dood/** test: needs: [detect-changes]