Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/smoke-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Smoke test'
description: Run a smoke test on built templates
inputs:
template:
description: 'Template id under templates/src to test'
required: true

runs:
using: composite
steps:
- name: Checkout main
id: checkout_release
uses: actions/checkout@v6

- name: Build template
id: build_template
shell: bash
run: ${{ github.action_path }}/build.sh ${{ inputs.template }}

- name: Test template
id: test_template
shell: bash
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
55 changes: 55 additions & 0 deletions .github/actions/smoke-test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
TEMPLATE_ID="$1"

set -e

shopt -s dotglob

SRC_DIR="/tmp/${TEMPLATE_ID}"
cp -R "templates/src/${TEMPLATE_ID}" "${SRC_DIR}"

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
OPTIONS=( $(jq -r '.options | keys[]' devcontainer-template.json) )

if [ "${OPTIONS[0]}" != "" ] && [ "${OPTIONS[0]}" != "null" ] ; then
echo "(!) Configuring template options for '${TEMPLATE_ID}'"
for OPTION in "${OPTIONS[@]}"
do
OPTION_KEY="\${templateOption:$OPTION}"
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)

if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'"
exit 1
fi

echo "(!) Replacing '${OPTION_KEY}' with '${OPTION_VALUE}'"
OPTION_VALUE_ESCAPED=$(sed -e 's/[]\/$*.^[]/\\&/g' <<<"${OPTION_VALUE}")
find ./ -type f -print0 | xargs -0 sed -i "s/${OPTION_KEY}/${OPTION_VALUE_ESCAPED}/g"
done
fi
fi

popd

TEST_DIR="test/${TEMPLATE_ID}"
if [ -d "${TEST_DIR}" ] ; then
echo "(*) Copying test folder"
DEST_DIR="${SRC_DIR}/test-project"
mkdir -p ${DEST_DIR}
cp -Rp ${TEST_DIR}/* ${DEST_DIR}
cp -Rp test/test-utils/* ${DEST_DIR}
fi

export DOCKER_BUILDKIT=1
echo "(*) Installing @devcontainer/cli"
npm install -g @devcontainers/cli

echo "Building Dev Container"
ID_LABEL="test-container=${TEMPLATE_ID}"
devcontainer up --id-label ${ID_LABEL} --workspace-folder "${SRC_DIR}"
13 changes: 13 additions & 0 deletions .github/actions/smoke-test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
TEMPLATE_ID="$1"
set -e

SRC_DIR="/tmp/${TEMPLATE_ID}"
echo "Running Smoke Test"

ID_LABEL="test-container=${TEMPLATE_ID}"
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'

# Clean up
docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q)
rm -rf "${SRC_DIR}"
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Release Dev Container Templates"
on:
workflow_dispatch:

jobs:
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6

- name: "Publish Templates"
uses: devcontainers/action@v1
with:
publish-templates: "true"
base-path-to-templates: "./templates/src"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73 changes: 73 additions & 0 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "CI - Test Templates"
on:
pull_request:

jobs:
smoke-test:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v6

- name: Smoke test for "gz"
id: smoke_test
uses: ./.github/actions/smoke-test
with:
template: "gz"

gen-docs:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.CI_BOT_TOKEN }}

- name: "Publish Templates"
uses: devcontainers/action@v1
with:
publish-templates: "false"
base-path-to-templates: "./templates/src"
generate-docs: "true"

- uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Update generated docs

complete:
needs:
- gen-docs
- smoke-test
if: always()
runs-on: ubuntu-latest
steps:
- name: Verify required jobs succeeded
env:
SMOKE_TEST_RESULT: ${{ needs.smoke-test.result }}
GEN_DOCS_RESULT: ${{ needs.gen-docs.result }}
run: |
set -euo pipefail

echo "smoke_test: ${SMOKE_TEST_RESULT}"
echo "gen_docs: ${GEN_DOCS_RESULT}"

if [[ "${SMOKE_TEST_RESULT}" != "success" ]]; then
echo "Required job 'smoke_test' did not succeed."
exit 1
fi

# gen_docs is skipped for fork PRs by design; treat that as acceptable.
if [[ "${GEN_DOCS_RESULT}" != "success" && "${GEN_DOCS_RESULT}" != "skipped" ]]; then
echo "Required job 'gen_docs' failed or was cancelled."
exit 1
fi

echo "All required jobs completed successfully."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tmp/
45 changes: 45 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Local Smoke Test GZ: Build",
"type": "process",
"command": ".github/actions/smoke-test/build.sh",
"args": [
"gz"
],
"options": {
"cwd": "${workspaceFolder}",
"env": {
"TEMPLATE_ARGS": "{\"distro\":\"jetty\",\"imageVariant\":\"base\"}"
}
},
"problemMatcher": []
},
{
"label": "Local Smoke Test GZ: Assert",
"dependsOrder": "sequence",
"dependsOn": [
"Local Smoke Test GZ: Build"
],
"type": "process",
"command": ".github/actions/smoke-test/test.sh",
"args": [
"gz"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
},
{
"label": "Local Smoke Test GZ",
"dependsOrder": "sequence",
"dependsOn": [
"Local Smoke Test GZ: Build",
"Local Smoke Test GZ: Assert"
],
"problemMatcher": []
}
]
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# ros2-devcontainer-templates
ROS2 devcontainer templates
# devcontainers

Devcontainer templates repository focused on robotics and simulation.

## Included template

- `templates/src/gz`

## Workflows

- `.github/workflows/test-pr.yaml`: smoke tests template changes on pull requests
- `.github/workflows/release.yaml`: publishes templates to GHCR on manual dispatch from `main`
26 changes: 26 additions & 0 deletions templates/src/gz/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Gazebo",
"image": "althack/gz:${templateOption:distro}-${templateOption:imageVariant}",
"remoteUser": "ros",
"updateRemoteUserUID": true,
"containerEnv": {
"GZ_VERSION": "${templateOption:distro}"
},
"runArgs": [
"--network=host",
"--ipc=host",
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp:unconfined",
"--security-opt=apparmor:unconfined"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-python.python",
"twxs.cmake",
"redhat.vscode-yaml"
]
}
}
}
17 changes: 17 additions & 0 deletions templates/src/gz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Gazebo (gz)

Gazebo development environment.

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| distro | Gazebo distribution to use. | string | jetty |
| imageVariant | Container image variant to use for this Gazebo distro. | string | base |



---

_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/althack/devcontainers/blob/main/templates/src/gz/devcontainer-template.json). Add additional notes to a `NOTES.md`._
43 changes: 43 additions & 0 deletions templates/src/gz/devcontainer-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "gz",
"version": "0.1.0",
"name": "Gazebo",
"description": "Gazebo development environment.",
"documentationURL": "https://github.com/athackst/devcontainer-templates/tree/main/templates/src/gz",
"licenseURL": "https://github.com/athackst/devcontainer-templates/blob/main/LICENSE",
"publisher": "althack",
"keywords": [
"gazebo",
"gz",
"robotics",
"ubuntu",
"docker"
],
"platforms": [
"Gazebo",
"Ubuntu",
"C++",
"Python"
],
"options": {
"distro": {
"type": "string",
"description": "Gazebo distribution to use.",
"proposals": [
"jetty",
"ionic",
"harmonic"
],
"default": "jetty"
},
"imageVariant": {
"type": "string",
"description": "Container image variant to use for this Gazebo distro.",
"proposals": [
"base",
"dev"
],
"default": "base"
}
}
}
Loading