Skip to content

Commit

Permalink
add new feature boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
audacioustux committed Oct 16, 2023
1 parent 92302fa commit 5d88a25
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 36 deletions.
25 changes: 0 additions & 25 deletions .devcontainer.json

This file was deleted.

22 changes: 22 additions & 0 deletions .devcontainer/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
"customizations": {
"vscode": {
"extensions": [
"mads-hartmann.bash-ide-vscode"
]
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true
},
"ghcr.io/devcontainers/features/node:1": {
"version": "20"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/audacioustux/devcontainers/common-utils-extras:1": {},
"ghcr.io/audacioustux/devcontainers/taskfile:1": {}
},
"updateContentCommand": "npm install -g @devcontainers/cli"
}
9 changes: 0 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- completed
workflow_dispatch:
pull_request:

jobs:
test-autogenerated:
runs-on: ubuntu-latest
Expand All @@ -20,13 +19,10 @@ jobs:
- mcr.microsoft.com/devcontainers/base:ubuntu
steps:
- uses: actions/checkout@v3

- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli

- name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'"
run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} .

test-scenarios:
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
Expand All @@ -51,21 +47,16 @@ jobs:
- vegeta
steps:
- uses: actions/checkout@v3

- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli

- name: "Generating tests for '${{ matrix.features }}' scenarios"
run: devcontainer features test -f ${{ matrix.features }} --skip-autogenerated .

test-global:
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
steps:
- uses: actions/checkout@v3

- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli

- name: "Testing global scenarios"
run: devcontainer features test --global-scenarios-only .
7 changes: 7 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3"

tasks:
default:
cmd: task --list-all
silent: true
new: ./scripts/new.sh {{.CLI_ARGS}}
45 changes: 45 additions & 0 deletions scripts/new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -eax

# ensure 3 arguments were passed
if [ $# -ne 3 ]; then
echo "Usage: $0 <feature_id> <feature_name> <feature_description>"
exit 1
fi

FEATURE_ID=$1
FEATURE_NAME=$2
FEATURE_DESCRIPTION=$3

# ensure feature does not already exist
if [ -d src/$FEATURE_ID ]; then
echo "Feature $FEATURE_ID already exists"
exit 1
fi
# ensure feature id is lowercase
if [ "$FEATURE_ID" != "${FEATURE_ID,,}" ]; then
echo "Feature id must be lowercase"
exit 1
fi

# copy feature template
cp -r templates/feature/src src/$FEATURE_ID
cp -r templates/feature/test test/$FEATURE_ID

# update feature metadata
jq \
--arg FEATURE_ID "$FEATURE_ID" \
--arg FEATURE_NAME "$FEATURE_NAME" \
--arg FEATURE_DESCRIPTION "$FEATURE_DESCRIPTION" \
'.id = $FEATURE_ID | .name = $FEATURE_NAME | .description = $FEATURE_DESCRIPTION' \
src/$FEATURE_ID/devcontainer-feature.json | sponge src/$FEATURE_ID/devcontainer-feature.json

# update feature test metadata
jq \
--arg FEATURE_ID "$FEATURE_ID" \
'.available_for_nonroot_user.features += {($FEATURE_ID): {}}' \
test/$FEATURE_ID/scenarios.json | sponge test/$FEATURE_ID/scenarios.json

# update github workflow to include feature in matrix
yq e '.jobs.test-scenarios.strategy.matrix.features += strenv(FEATURE_ID)' -i .github/workflows/test.yaml
2 changes: 1 addition & 1 deletion src/common-utils-extras/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Common Utilities Extras",
"id": "common-utils-extras",
"version": "1.0.4",
"version": "1.0.5",
"description": "More Common utilities for development containers",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
Expand Down
3 changes: 2 additions & 1 deletion src/common-utils-extras/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ apt-get install -yqq --no-install-recommends \
socat \
parallel \
gum \
cloc
cloc \
moreutils

# create symlinks for bat and fd, as they are called batcat and fdfind in Ubuntu
sudo -iu $_REMOTE_USER <<EOF
Expand Down
9 changes: 9 additions & 0 deletions templates/feature/src/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "",
"id": "",
"version": "1.0.0",
"description": "",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
6 changes: 6 additions & 0 deletions templates/feature/src/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eax

ARCH=amd64
if [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64; fi
16 changes: 16 additions & 0 deletions templates/feature/test/available_for_nonroot_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e

source dev-container-features-test-lib

check "user is vscode" grep vscode <(whoami)

bins=(
)

for bin in "${bins[@]}"; do
check "$bin" command -v "$bin"
done

reportResults
11 changes: 11 additions & 0 deletions templates/feature/test/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"available_for_nonroot_user": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"username": "vscode"
}
}
}
}

0 comments on commit 5d88a25

Please sign in to comment.