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
7 changes: 3 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// More info: https://containers.dev/implementors/json_reference/
{
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bookworm",
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
Expand All @@ -13,9 +13,8 @@
}
},
"remoteEnv": {
// Activate LocalStack Pro: https://docs.localstack.cloud/getting-started/auth-token/
"LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}", // required for Pro, not processed via template due to security reasons
"LOCALSTACK_API_KEY": "${localEnv:LOCALSTACK_API_KEY}"
// Needed by the template tests: https://docs.localstack.cloud/aws/getting-started/auth-token/
"LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}"
},
"postCreateCommand": "npm install -g @devcontainers/cli"
}
35 changes: 35 additions & 0 deletions .github/actions/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Removes everything a template test run created.
# Usage: cleanup.sh <workspace folder> <id label>
SRC_DIR="$1"
ID_LABEL="$2"
COMPOSE_PROJECT="$(basename "${SRC_DIR}")_devcontainer"

echo "🧹 Cleaning up ${SRC_DIR}"
# DooD: LocalStack runs as a compose service next to the dev container. Print its logs before removing it,
# so startup failures (e.g. a rejected auth token) are visible in CI.
if docker container inspect localstack-main &> /dev/null ; then
echo "::group::LocalStack container logs (localstack-main)"
docker logs --tail 200 localstack-main 2>&1
echo "::endgroup::"
fi
# Stop the compose services first, so LocalStack removes the Lambda containers it started.
PROJECT_CONTAINERS=$(docker container ls -q -f "label=com.docker.compose.project=${COMPOSE_PROJECT}")
if [ -n "${PROJECT_CONTAINERS}" ] ; then
docker stop -t 30 ${PROJECT_CONTAINERS} > /dev/null
fi
for filter in "label=${ID_LABEL}" "label=com.docker.compose.project=${COMPOSE_PROJECT}"; do
CONTAINERS=$(docker container ls -aq -f "${filter}")
if [ -n "${CONTAINERS}" ] ; then
docker rm -f ${CONTAINERS} > /dev/null && echo "🧹 Removed containers matching ${filter}"
fi
done
for NETWORK in $(docker network ls -q -f "label=com.docker.compose.project=${COMPOSE_PROJECT}"); do
# Containers LocalStack started on the network, e.g. Lambda functions.
ATTACHED=$(docker container ls -aq -f "network=${NETWORK}")
if [ -n "${ATTACHED}" ] ; then
docker rm -f ${ATTACHED} > /dev/null && echo "🧹 Removed containers attached to network ${NETWORK}"
fi
docker network rm "${NETWORK}" > /dev/null && echo "🧹 Removed network ${NETWORK}"
done
sudo rm -rf "${SRC_DIR}" && echo "🧹 Removed ${SRC_DIR}"
16 changes: 15 additions & 1 deletion .github/actions/scenario-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ inputs:
template:
description: 'Template to test'
required: true
feature-ref:
description: 'Optional git ref of localstack/devcontainer-feature to test against instead of the published Feature'
required: false
default: ''

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

- name: Checkout unreleased Feature
if: ${{ inputs.feature-ref != '' }}
uses: actions/checkout@v4
with:
repository: localstack/devcontainer-feature
ref: ${{ inputs.feature-ref }}
path: .feature

- name: Test scenario templates
id: test_template
shell: bash
env:
LOCAL_FEATURE_DIR: ${{ inputs.feature-ref != '' && '.feature/src/localstack-cli' || '' }}
run: ${{ github.action_path }}/controller.sh ${{ inputs.template }}
28 changes: 18 additions & 10 deletions .github/actions/scenario-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
TEMPLATE_ID="$1"
SCENARIO="$2"
SRC_DIR="/tmp/${TEMPLATE_ID}-${SCENARIO}"
LOCAL_FEATURE_DIR="${LOCAL_FEATURE_DIR:+$(cd "${LOCAL_FEATURE_DIR}" && pwd)}"

set -e

Expand Down Expand Up @@ -48,22 +49,16 @@ function gen_config {
fi

if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
if [ "$(jq -r --arg o "${OPTION}" '.options[$o] | has("default")' devcontainer-template.json)" != "true" ] ; then
echo "Template '${TEMPLATE_ID}-${SCENARIO}' is missing a default value for option '${OPTION}'"
exit 1
fi
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)
fi

# For empty default values use " "
if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
echo "Template '${TEMPLATE_ID}-${SCENARIO}' 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"

if [ "${OPTION}" == "volumePath" ] ; then
mkdir -p ${SRC_DIR}/${OPTION_VALUE}
fi

unset OPTION_VALUE
done
Expand All @@ -72,6 +67,17 @@ function gen_config {
fi
}

# Optional: test against a local checkout of the LocalStack Feature instead of
# the published one, e.g. LOCAL_FEATURE_DIR=../devcontainer-feature/src/localstack-cli
function use_local_feature {
if [ -z "${LOCAL_FEATURE_DIR:-}" ] ; then
return
fi
echo "(!) Using local LocalStack Feature from '${LOCAL_FEATURE_DIR}'"
cp -R "${LOCAL_FEATURE_DIR}" "${SRC_DIR}/.devcontainer/localstack-cli"
sed -i -e 's#"ghcr.io/localstack/devcontainer-feature/localstack-cli:[^"]*"#"./localstack-cli"#' "${SRC_DIR}/.devcontainer/devcontainer.json"
}

function create_scenario {
cp -R "src/${TEMPLATE_ID}" "${SRC_DIR}"

Expand All @@ -90,6 +96,8 @@ function create_scenario {

popd

use_local_feature

echo
echo "🏗️ Building Dev Container - ${SCENARIO}"
ID_LABEL="test-container=${TEMPLATE_ID}-${SCENARIO}"
Expand Down
11 changes: 1 addition & 10 deletions .github/actions/scenario-test/controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ function reportAllScenarioResults {
}

function cleanup {
# Clean up
echo "🧹 Cleaning up..."
local ID_LABEL=${2}
CONTAINER_ID=$(docker container ls -f "label=${ID_LABEL}" -q)
if [ "${CONTAINER_ID:-x}" != "x" ]; then
docker rm -f "${CONTAINER_ID}" > /dev/null && echo "🧹 Removing container ${CONTAINER_ID}"
echo "🧹 Removing container localstack-main (if exists)" && docker rm -f "localstack-main" &> /dev/null
fi
echo "🧹 Removing container network ${ID_LABEL/*=/}_devcontainer_ls (if exists)" && docker network rm -f "${ID_LABEL/*=/}_devcontainer_ls" > /dev/null
sudo rm -rf "${1}" && echo "🧹 Removing scenario files ${SCENARIO}"
"$(dirname "$0")/../cleanup.sh" "${1}" "${2}"
}

function no_scenarios {
Expand Down
18 changes: 16 additions & 2 deletions .github/actions/smoke-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ inputs:
template:
description: 'Template to test'
required: true
feature-ref:
description: 'Optional git ref of localstack/devcontainer-feature to test against instead of the published Feature'
required: false
default: ''

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

- name: Checkout unreleased Feature
if: ${{ inputs.feature-ref != '' }}
uses: actions/checkout@v4
with:
repository: localstack/devcontainer-feature
ref: ${{ inputs.feature-ref }}
path: .feature

- name: Build template
id: build_template
shell: bash
env:
LOCAL_FEATURE_DIR: ${{ inputs.feature-ref != '' && '.feature/src/localstack-cli' || '' }}
run: ${{ github.action_path }}/build.sh ${{ inputs.template }}

- name: Test template
id: test_template
shell: bash
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
run: ${{ github.action_path }}/test.sh ${{ inputs.template }}
36 changes: 23 additions & 13 deletions .github/actions/smoke-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ function merge {
rm .devcontainer/devcontainer.json.bak
}

# Optional: test against a local checkout of the LocalStack Feature instead of
# the published one, e.g. LOCAL_FEATURE_DIR=../devcontainer-feature/src/localstack-cli
function use_local_feature {
if [ -z "${LOCAL_FEATURE_DIR:-}" ] ; then
return
fi
echo "(!) Using local LocalStack Feature from '${LOCAL_FEATURE_DIR}'"
cp -R "${LOCAL_FEATURE_DIR}" "${SRC_DIR}/.devcontainer/localstack-cli"
sed -i -e 's#"ghcr.io/localstack/devcontainer-feature/localstack-cli:[^"]*"#"./localstack-cli"#' "${SRC_DIR}/.devcontainer/devcontainer.json"
}

SRC_DIR="/tmp/${TEMPLATE_ID}"
cp -R "src/${TEMPLATE_ID}" "${SRC_DIR}"
LOCAL_FEATURE_DIR="${LOCAL_FEATURE_DIR:+$(cd "${LOCAL_FEATURE_DIR}" && pwd)}"

pushd "${SRC_DIR}"

Expand All @@ -44,22 +56,16 @@ if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then
fi

if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)
fi

# For empty default values use " "
if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then
echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'"
exit 1
if [ "$(jq -r --arg o "${OPTION}" '.options[$o] | has("default")' devcontainer-template.json)" != "true" ] ; then
echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'"
exit 1
fi
OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json)
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"

if [ "${OPTION}" == "volumePath" ] ; then
mkdir -p ${SRC_DIR}/${OPTION_VALUE}
fi

unset OPTION_VALUE
done
Expand All @@ -72,6 +78,8 @@ fi

popd

use_local_feature

TEST_DIR="test/${TEMPLATE_ID}"
if [ -d "${TEST_DIR}" ] ; then
echo "(*) Copying test folder"
Expand All @@ -82,8 +90,10 @@ if [ -d "${TEST_DIR}" ] ; then
fi

export DOCKER_BUILDKIT=1
echo "(*) Installing @devcontainer/cli"
npm install -g @devcontainers/cli
if ! type devcontainer &> /dev/null ; then
echo "(*) Installing @devcontainer/cli"
npm install -g @devcontainers/cli
fi

echo "Building Dev Container"
ID_LABEL="test-container=${TEMPLATE_ID}"
Expand Down
9 changes: 4 additions & 5 deletions .github/actions/smoke-test/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/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)
sudo rm -rf "${SRC_DIR}"
STATUS=$?

"$(dirname "$0")/../cleanup.sh" "${SRC_DIR}" "${ID_LABEL}"
exit ${STATUS}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: "Publish Templates"
uses: devcontainers/action@v1
Expand Down
50 changes: 38 additions & 12 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,80 @@ on:
- LICENSE
- .gitkeep
- .gitignore
push:
branches:
- main
paths-ignore:
- '*.md'
- LICENSE
- .gitkeep
- .gitignore
workflow_dispatch:
inputs:
feature-ref:
description: 'Test against this git ref of localstack/devcontainer-feature instead of the published Feature'
required: false
default: ''

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
templates: ${{ steps.filter.outputs.changes }}
# Pull requests test the templates they touch. Pushes to main and manual runs test all of them.
templates: ${{ github.event_name == 'pull_request' && steps.filter.outputs.changes || '["localstack-dind","localstack-dood"]' }}
steps:
- uses: dorny/paths-filter@v2
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: filter
if: ${{ github.event_name == 'pull_request' }}
with:
filters: |
localstack-dind: ./**/localstack-dind/**
localstack-dood: ./**/localstack-dood/**
localstack-dind:
- 'src/localstack-dind/**'
- 'test/localstack-dind/**'
- 'test/test-utils/**'
- '.github/**'
localstack-dood:
- 'src/localstack-dood/**'
- 'test/localstack-dood/**'
- 'test/test-utils/**'
- '.github/**'

smoke-test:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.templates != '[]' }}
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Smoke test for '${{ matrix.templates }}'
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
id: smoke_test
uses: ./.github/actions/smoke-test
with:
template: "${{ matrix.templates }}"
feature-ref: ${{ inputs.feature-ref || 'migrate-to-lstk' }}

scenario-test:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.templates != '[]' }}
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Scenario test(s) for '${{ matrix.templates }}'
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
id: scenario_test
uses: ./.github/actions/scenario-test
with:
template: "${{ matrix.templates }}"
feature-ref: ${{ inputs.feature-ref || 'migrate-to-lstk' }}
Loading
Loading