Skip to content

Commit

Permalink
Create initial template;
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderilyin committed Aug 22, 2024
1 parent 0f6eedf commit 84c4fa6
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 110 deletions.
31 changes: 30 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
// More info: https://containers.dev/implementors/json_reference/
{
"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/docker-in-docker:2": {}
"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": {
"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"
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/smoke-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ runs:
- name: Test template
id: test_template
shell: bash
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
2 changes: 1 addition & 1 deletion .github/actions/smoke-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
id: filter
with:
filters: |
color: ./**/color/**
hello: ./**/hello/**
unobtainium: ./**/unobtainium/**
test:
needs: [detect-changes]
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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']
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Dev Container Templates: Self Authoring Guide

> 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/).
> 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`.
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
Expand Down Expand Up @@ -69,7 +69,7 @@ Templates are individually versioned by the `version` attribute in a Template's

### Publishing

> NOTE: The Distribution spec can be [found here](https://containers.dev/implementors/templates-distribution/).
> NOTE: The Distribution spec can be [found here](https://containers.dev/implementors/templates-distribution/).
>
> While any registry [implementing the OCI Distribution spec](https://github.com/opencontainers/distribution-spec) can be used, this template will leverage GHCR (GitHub Container Registry) as the backing registry.
Expand All @@ -88,9 +88,9 @@ The provided GitHub Action will also publish a third "metadata" package with jus

### Marking Template Public

For your Template to be used, it currently needs to be available publicly. By default, OCI Artifacts in GHCR are marked as `private`.
For your Template to be used, it currently needs to be available publicly. By default, OCI Artifacts in GHCR are marked as `private`.

To make them public, navigate to the Template's "package settings" page in GHCR, and set the visibility to 'public`.
To make them public, navigate to the Template's "package settings" page in GHCR, and set the visibility to 'public`.

```
https://github.com/users/<owner>/packages/container/<repo>%2F<templateName>/settings
Expand All @@ -113,8 +113,8 @@ This repo contains a GitHub Action [workflow](.github/workflows/test-pr.yaml) fo
For running the tests locally, you would need to execute the following commands -

```
./.github/actions/smoke-test/build.sh ${TEMPLATE-ID}
./.github/actions/smoke-test/test.sh ${TEMPLATE-ID}
./.github/actions/smoke-test/build.sh ${TEMPLATE-ID}
./.github/actions/smoke-test/test.sh ${TEMPLATE-ID}
```

### Updating Documentation
Expand Down
18 changes: 0 additions & 18 deletions src/color/.devcontainer/devcontainer.json

This file was deleted.

4 changes: 0 additions & 4 deletions src/hello/.devcontainer/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions src/hello/.devcontainer/devcontainer.json

This file was deleted.

17 changes: 0 additions & 17 deletions src/hello/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions src/hello/devcontainer-template.json

This file was deleted.

74 changes: 74 additions & 0 deletions src/unobtainium/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "Unobtainium",
"image": "mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant}",
"remoteEnv": {
"WAKATIME_API_KEY": "${localEnv:WAKATIME_API_KEY}",
"PATH": "${containerEnv:PATH}:/opt/pip/bin"
},
"remoteUser": "vscode",
"features": {
"git": "latest",
"github-cli": "latest",
"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 mkdocs mkdocs-material",
"location": "/opt/pip"
}
},
"customizations": {
"vscode": {
"settings": {
"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": [
"1Password.op-vscode",
"Codeium.codeium",
"DavidAnson.vscode-markdownlint",
"GitHub.vscode-codeql",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"mads-hartmann.bash-ide-vscode",
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker",
"WakaTime.vscode-wakatime",
"yzhang.markdown-all-in-one"
],
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "pre-commit: manual",
"type": "shell",
"command": "pre-commit",
"args": [
"run",
"--hook-stage",
"manual"
],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
}
}
}
1 change: 0 additions & 1 deletion src/color/README.md → src/unobtainium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ A Template to remind you of your favorite color
| 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 |



Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/test-utils/test-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ check() {
LABEL=$1
shift
echo -e "\n🧪 Testing $LABEL"
if "$@"; then
if "$@"; then
echo "✅ Passed!"
return 0
else
Expand All @@ -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
Expand Down

0 comments on commit 84c4fa6

Please sign in to comment.