From bcd02c763e1dca543727d6fc1aa4eafa5e3479a7 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Mon, 23 Nov 2026 17:26:33 +0530 Subject: [PATCH 1/4] feat: run LocalStack with lstk in both templates Bump localstack-dind and localstack-dood to 1.0.0 and replace the legacy localstack CLI and the awslocal, cdklocal, pulumilocal, samlocal and tflocal options with lstk from localstack-cli:1. DinD: lstk starts LocalStack on every container start, reads .devcontainer/lstk/config.toml, keeps state in a Docker volume and writes a localstack AWS profile. AWS_ENDPOINT_URL is no longer set, since lstk start refuses to run with it. DooD: lstk targets the compose service through LSTK_ENDPOINT_URL. Lambda containers join the shared network via LAMBDA_DOCKER_NETWORK. Fix the option description typo, drop usePro and LOCALSTACK_API_KEY, add end-to-end scenario tests and stop CI from ignoring failures. --- .devcontainer/devcontainer.json | 7 +- .github/actions/cleanup.sh | 28 ++++ .github/actions/scenario-test/action.yaml | 2 +- .github/actions/scenario-test/build.sh | 28 ++-- .github/actions/scenario-test/controller.sh | 11 +- .github/actions/smoke-test/action.yaml | 2 +- .github/actions/smoke-test/build.sh | 36 +++-- .github/actions/smoke-test/test.sh | 9 +- .github/workflows/release.yaml | 2 +- .github/workflows/test-pr.yaml | 43 +++-- README.md | 83 ++++------ .../.devcontainer/devcontainer.json | 54 +++---- .../.devcontainer/lstk/config.toml | 21 +++ .../.devcontainer/lstk/post-create.sh | 10 ++ .../.devcontainer/lstk/post-start.sh | 25 +++ src/localstack-dind/NOTES.md | 58 +++++-- src/localstack-dind/README.md | 97 +++++++---- .../devcontainer-template.json | 103 ++++-------- src/localstack-dood/.devcontainer/.env | 16 +- .../.devcontainer/devcontainer.json | 21 +-- .../.devcontainer/docker-compose.yml | 46 ++++-- .../.devcontainer/lstk/post-start.sh | 17 ++ src/localstack-dood/NOTES.md | 59 +++++-- src/localstack-dood/README.md | 107 ++++++++----- .../devcontainer-template.json | 150 +++++++----------- .../custom_region_with_iam_enforce.sh | 34 ---- .../localstack-dind/debug_mode_on_bookworm.sh | 13 -- test/localstack-dind/iac_tools_on_jammy.sh | 11 ++ test/localstack-dind/iam_region_and_debug.sh | 10 ++ test/localstack-dind/load_pod.sh | 14 ++ test/localstack-dind/no_startup.sh | 10 ++ .../persistence_custom_volume_with_3_3_0.sh | 19 --- .../persistence_pinned_version_on_bookworm.sh | 13 ++ test/localstack-dind/scenarios.json | 58 +++---- test/localstack-dind/test.sh | 16 +- test/localstack-dind/tools_no_startup.sh | 15 -- test/localstack-dind/use_pro_and_pod.sh | 15 -- .../custom_host_iam_and_region.sh | 13 ++ .../custom_region_with_iam_enforce.sh | 34 ---- .../custom_volume_and_host_with_3_3_0.sh | 13 -- .../localstack-dood/debug_mode_on_bookworm.sh | 13 -- .../persistence_pinned_version_on_jammy.sh | 14 ++ test/localstack-dood/scenarios.json | 55 ++----- .../terraform_pod_and_debug_on_bookworm.sh | 17 ++ test/localstack-dood/test.sh | 18 ++- test/localstack-dood/tools.sh | 14 -- test/localstack-dood/use_pro_and_pod.sh | 15 -- test/test-utils/test-utils.sh | 122 +++++++++++++- 48 files changed, 889 insertions(+), 702 deletions(-) create mode 100755 .github/actions/cleanup.sh create mode 100644 src/localstack-dind/.devcontainer/lstk/config.toml create mode 100755 src/localstack-dind/.devcontainer/lstk/post-create.sh create mode 100755 src/localstack-dind/.devcontainer/lstk/post-start.sh create mode 100755 src/localstack-dood/.devcontainer/lstk/post-start.sh delete mode 100644 test/localstack-dind/custom_region_with_iam_enforce.sh delete mode 100644 test/localstack-dind/debug_mode_on_bookworm.sh create mode 100755 test/localstack-dind/iac_tools_on_jammy.sh create mode 100755 test/localstack-dind/iam_region_and_debug.sh create mode 100755 test/localstack-dind/load_pod.sh create mode 100755 test/localstack-dind/no_startup.sh delete mode 100644 test/localstack-dind/persistence_custom_volume_with_3_3_0.sh create mode 100755 test/localstack-dind/persistence_pinned_version_on_bookworm.sh mode change 100644 => 100755 test/localstack-dind/test.sh delete mode 100644 test/localstack-dind/tools_no_startup.sh delete mode 100644 test/localstack-dind/use_pro_and_pod.sh create mode 100755 test/localstack-dood/custom_host_iam_and_region.sh delete mode 100644 test/localstack-dood/custom_region_with_iam_enforce.sh delete mode 100644 test/localstack-dood/custom_volume_and_host_with_3_3_0.sh delete mode 100644 test/localstack-dood/debug_mode_on_bookworm.sh create mode 100755 test/localstack-dood/persistence_pinned_version_on_jammy.sh create mode 100755 test/localstack-dood/terraform_pod_and_debug_on_bookworm.sh mode change 100644 => 100755 test/localstack-dood/test.sh delete mode 100644 test/localstack-dood/tools.sh delete mode 100644 test/localstack-dood/use_pro_and_pod.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 149f440..fda0bdc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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": {} }, @@ -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" } diff --git a/.github/actions/cleanup.sh b/.github/actions/cleanup.sh new file mode 100755 index 0000000..91c74a7 --- /dev/null +++ b/.github/actions/cleanup.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Removes everything a template test run created. +# Usage: cleanup.sh +SRC_DIR="$1" +ID_LABEL="$2" +COMPOSE_PROJECT="$(basename "${SRC_DIR}")_devcontainer" + +echo "🧹 Cleaning up ${SRC_DIR}" +# 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}" diff --git a/.github/actions/scenario-test/action.yaml b/.github/actions/scenario-test/action.yaml index e06f6a1..26978f0 100644 --- a/.github/actions/scenario-test/action.yaml +++ b/.github/actions/scenario-test/action.yaml @@ -9,7 +9,7 @@ runs: steps: - name: Checkout main id: checkout_release - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test scenario templates id: test_template diff --git a/.github/actions/scenario-test/build.sh b/.github/actions/scenario-test/build.sh index 9336f95..1ef5909 100755 --- a/.github/actions/scenario-test/build.sh +++ b/.github/actions/scenario-test/build.sh @@ -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 @@ -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 @@ -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}" @@ -90,6 +96,8 @@ function create_scenario { popd + use_local_feature + echo echo "🏗️ Building Dev Container - ${SCENARIO}" ID_LABEL="test-container=${TEMPLATE_ID}-${SCENARIO}" diff --git a/.github/actions/scenario-test/controller.sh b/.github/actions/scenario-test/controller.sh index 5b8cfbf..0e038fa 100755 --- a/.github/actions/scenario-test/controller.sh +++ b/.github/actions/scenario-test/controller.sh @@ -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 { diff --git a/.github/actions/smoke-test/action.yaml b/.github/actions/smoke-test/action.yaml index 5f98ba8..fa9fbc8 100644 --- a/.github/actions/smoke-test/action.yaml +++ b/.github/actions/smoke-test/action.yaml @@ -9,7 +9,7 @@ runs: steps: - name: Checkout main id: checkout_release - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build template id: build_template diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh index e1a5b1f..aea5b53 100755 --- a/.github/actions/smoke-test/build.sh +++ b/.github/actions/smoke-test/build.sh @@ -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}" @@ -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 @@ -72,6 +78,8 @@ fi popd +use_local_feature + TEST_DIR="test/${TEMPLATE_ID}" if [ -d "${TEST_DIR}" ] ; then echo "(*) Copying test folder" @@ -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}" diff --git a/.github/actions/smoke-test/test.sh b/.github/actions/smoke-test/test.sh index 7c74ca5..3a5eace 100755 --- a/.github/actions/smoke-test/test.sh +++ b/.github/actions/smoke-test/test.sh @@ -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} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 36c2fb3..d663a7f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 5970af5..2b61472 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -6,54 +6,73 @@ on: - LICENSE - .gitkeep - .gitignore + push: + branches: + - main + paths-ignore: + - '*.md' + - LICENSE + - .gitkeep + - .gitignore + workflow_dispatch: 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 }}" 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 }}" diff --git a/README.md b/README.md index bac890e..74ebe52 100644 --- a/README.md +++ b/README.md @@ -11,47 +11,33 @@ A Template can be used in a new or existing project, and a [supporting tool](htt > This repo currently a work in progress which might introduce breaking changes without notification. ## List of Templates -- LocalStack Docker-in-Docker: setup a devcontainer with LocalStack running in an internal Docker service -- LocalStack Docker-outside-of-Docker: setup a devcontainer communicating with a separate LocalStack instance running on the same Docker network +- LocalStack Docker-in-Docker (`localstack-dind`): runs LocalStack inside the dev container's own Docker daemon and manages it with `lstk`. +- LocalStack Docker-outside-of-Docker (`localstack-dood`): runs LocalStack as a Docker Compose service next to the dev container, on the host's Docker daemon. ## Usage -To use either of the Templates use a supported tool and choose one of them, then either add custom values to the options or keep the defaults. -Alternatively, copy the contents of the desired Template's `.devcontainer` folder and customize it as necessary. +Pick one of the Templates in a [supporting tool](https://containers.dev/supporting), such as VS Code or the Dev Container CLI, and keep the defaults or adjust the options. +You can also copy the Template's `.devcontainer` folder into your project and edit it. -Both variation of the Templates adds automatically the [official LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs the CLI and by demand the most popular *Local Tools™*. -Currently this calls for a **Debian-based** DevContainer image. +Both Templates add the [LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs [`lstk`](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), the LocalStack CLI, and the AWS CLI Feature. +`lstk` replaces the legacy `localstack` CLI and the `awslocal`, `tflocal`, `cdklocal` and `samlocal` wrappers. +The Templates use Ubuntu or Debian based images. -### LocalStack - Docker-in-Docker - -This version of the Template starts up LocalStack in an internal Docker service in the DevContainer, hence we set a volume by default for data persistence. -As a result the newly built DevContainers do not necessarily need to re-download images as long this volume exists on the system. -Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data (`LOCALSTACK_VOLUME_DIR`). +Both Templates need a LocalStack [auth token](https://docs.localstack.cloud/aws/getting-started/auth-token/). +Set `LOCALSTACK_AUTH_TOKEN` on the host before you build the container. It is read from the host environment and never written into the Template files. -LocalStack in this variation is controlled via the LocalStack CLI and some env variables that you can adjust or expand in the `devcontainer.json` file's `remoteEnv` block. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). - -#### Use LocalStack Pro +### LocalStack - Docker-in-Docker -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the Template. +LocalStack runs in the dev container's own Docker daemon. `lstk start` runs on every container start. +The `lstk` configuration lives in `.devcontainer/lstk/config.toml`. LocalStack state is kept in a Docker volume and survives rebuilds. +See the [Template README](src/localstack-dind/README.md). ### LocalStack - Docker-outside-of-Docker -This version of the Template starts up LocalStack as a separate container in the same Docker network using the host system's Docker socket. - -To control LocalStack's behaviour adjust the provided `.env` file which will be loaded both into LocalStack and the created DevContainer after rebuild. -For further customisation you can edit the provided `Dockerfile` and/or the `devcontainer.json` file. -Or add additional services by modifying the provided `docker-compose.yml` file. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). - ->[!WARNING] -> In this Template version however the LocalStack CLI provides the `start` and `stop` options do **NOT** control the LocalStack container with them as that would result in name resolution issues in the container. -> -> In case you've made this mistake by accident, try running `docker compose -f /docker-compose.yml up -d localstack` or rebuild the container. - -#### Use LocalStack Pro - -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the `.env` file. +LocalStack runs as the `localstack` service in `.devcontainer/docker-compose.yml`, on the host's Docker daemon. +`lstk` talks to it through `LSTK_ENDPOINT_URL`. Docker Compose, not `lstk`, starts and stops the LocalStack container. +LocalStack's DNS server resolves `localhost.localstack.cloud` inside the dev container, and Lambda containers join the same network. +See the [Template README](src/localstack-dood/README.md). ## Repo and Template Structure @@ -61,20 +47,23 @@ This repository contains a _collection_ of two Templates - `localstack-dind` and ├── src │ ├── localstack-dind │ │ ├── devcontainer-template.json -│ │ ├── inputs.json +│ │ ├── NOTES.md │ │ └──| .devcontainer -│ │ └── devcontainer.json +│ │ ├── devcontainer.json +│ │ └──| lstk +│ │ ├── config.toml +│ │ ├── post-create.sh +│ │ └── post-start.sh │ ├── localstack-dood │ │ ├── devcontainer-template.json +│ │ ├── NOTES.md │ │ └──| .devcontainer │ │ ├── .env │ │ ├── devcontainer.json -│ │ ├── docker-compose.yaml -│ │ └── Dockerfile -| ├── ... -│ │ ├── devcontainer-template.json -│ │ └──| .devcontainer -│ │ └── devcontainer.json +│ │ ├── docker-compose.yml +│ │ ├── Dockerfile +│ │ └──| lstk +│ │ └── post-start.sh ├── test │ ├── localstack-dind | | ├── scenarios.json @@ -93,7 +82,7 @@ This repository contains a _collection_ of two Templates - `localstack-dind` and All available options for a Template should be declared in the `devcontainer-template.json`. The syntax for the `options` property can be found in the [devcontainer Template json properties reference](https://containers.dev/implementors/templates#devcontainer-templatejson-properties). -For example, the `localstack-dind` Template provides four possible options (`jammy`, `focal`, `bookworm`, `bullseye`), where the default value is set to `jammy`. +For example, the `localstack-dind` Template offers four image variants, with `noble` as the default. ```jsonc { @@ -101,14 +90,9 @@ For example, the `localstack-dind` Template provides four possible options (`jam "options": { "imageVariant": { "type": "string", - "description": "Debian version (use bullseye or jammy on local arm64/Apple Silicon):", - "proposals": [ - "jammy", - "focal", - "bullseye", - "bookworm" - ], - "default": "jammy" + "description": "Ubuntu or Debian version of the base image:", + "proposals": ["noble", "jammy", "resolute", "bookworm"], + "default": "noble" } } } @@ -171,10 +155,13 @@ 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 - ``` + export LOCALSTACK_AUTH_TOKEN= ./.github/actions/smoke-test/build.sh ${TEMPLATE-ID} ./.github/actions/smoke-test/test.sh ${TEMPLATE-ID} ``` +The scripts use GNU `sed`. To test against a local checkout of the [Feature](https://github.com/localstack/devcontainer-feature) instead of the published one, set `LOCAL_FEATURE_DIR`, for example `LOCAL_FEATURE_DIR=../devcontainer-feature/src/localstack-cli`. + To override the default values for example for manual testing an `inputs.json` file can be defined in the Template's folder. The file's structure is the following: ```json { diff --git a/src/localstack-dind/.devcontainer/devcontainer.json b/src/localstack-dind/.devcontainer/devcontainer.json index 20013f7..eb8834a 100644 --- a/src/localstack-dind/.devcontainer/devcontainer.json +++ b/src/localstack-dind/.devcontainer/devcontainer.json @@ -3,50 +3,38 @@ "image": "mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant}", "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}", - // LocalStack configuration: https://docs.localstack.cloud/references/configuration/ - "ACTIVATE_PRO": ${templateOption:usePro}, - "DEBUG": ${templateOption:debug}, - "LS_LOG": "${templateOption:logLevel}", - "PERSISTENCE": ${templateOption:persistence}, - "AWS_ENDPOINT_URL": "http://localhost.localstack.cloud:4566", - "AUTO_LOAD_POD": "${templateOption:loadPods}", - "ENFORCE_IAM": ${templateOption:enforceIam}, + // LocalStack auth token: https://docs.localstack.cloud/aws/getting-started/auth-token/ + // Read from the host and never written into the template. You can also run `lstk login` in the container. + "LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}", "AWS_REGION": "${templateOption:defaultRegion}", "AWS_DEFAULT_REGION": "${templateOption:defaultRegion}", - "IMAGE_NAME": "localstack/localstack-pro:${templateOption:version}", - "LOCALSTACK_VOLUME_DIR": "/data" + // `aws` and the AWS SDKs use the `localstack` profile written by `lstk setup aws`. + // Do not set AWS_ENDPOINT_URL here: `lstk start` refuses to run when it is set. + "AWS_PROFILE": "localstack" }, // 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features. "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/localstack/devcontainer-feature/localstack-cli:latest": { - "version": "${templateOption:version}", - "awslocal": ${templateOption:awslocal}, // if true, add in features manually: ghcr.io/devcontainers/features/aws-cli - "cdklocal": ${templateOption:cdklocal}, // if true, add in features manually: ghcr.io/devcontainers-contrib/features/aws-cdk - "pulumilocal": ${templateOption:pulumilocal}, // if true, add in features manually: ghcr.io/devcontainers-contrib/features/pulumi - "samlocal": ${templateOption:samlocal}, // if true, add in features manually: ghcr.io/customink/codespaces-features/sam-cli - "tflocal": ${templateOption:tflocal} // if true, add in features manually: ghcr.io/devcontainers-contrib/features/terraform-asdf - } + "ghcr.io/devcontainers/features/docker-in-docker:4": {}, + // `lstk aws` and the `localstack` profile need the AWS CLI. + "ghcr.io/devcontainers/features/aws-cli:1": {}, + // Installs lstk. For `lstk terraform`, `lstk cdk` or `lstk sam`, also add + // ghcr.io/devcontainers/features/terraform:1, ghcr.io/devcontainers-extra/features/aws-cdk:2 + // or ghcr.io/customink/codespaces-features/sam-cli:1. + "ghcr.io/localstack/devcontainer-feature/localstack-cli:1": {} }, - // 👇 Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "type localstack; ${templateOption:startup} && localstack start -d || true", + // lstk reads .devcontainer/lstk/config.toml through ~/.config/lstk/config.toml. + "postCreateCommand": "bash .devcontainer/lstk/post-create.sh", + // Starts LocalStack on every container start, as the inner Docker daemon restarts with the container. + "postStartCommand": "bash .devcontainer/lstk/post-start.sh ${templateOption:startup}", + "mounts": [ { - // to persist build data and images - "source": "dind-var-lib-docker", - "target": "/var/lib/docker", - "type": "volume" - }, - { - "source": "${templateOption:volumePath}", + // LocalStack state (/var/lib/localstack), kept across container rebuilds. + "source": "localstack-data-${devcontainerId}", "target": "/data", - "type": "bind", - "consistency": "cached" + "type": "volume" } ] } diff --git a/src/localstack-dind/.devcontainer/lstk/config.toml b/src/localstack-dind/.devcontainer/lstk/config.toml new file mode 100644 index 0000000..105f7d3 --- /dev/null +++ b/src/localstack-dind/.devcontainer/lstk/config.toml @@ -0,0 +1,21 @@ +# lstk configuration for this dev container. +# ~/.config/lstk/config.toml links to this file, so every lstk command in the container uses it. +# Edit it and run `lstk restart` to apply changes. +# Reference: https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/configuration/ + +[[containers]] +type = "aws" +# LocalStack image tag, e.g. "latest", "stable" or "2026.10". +tag = "${templateOption:version}" +port = "4566" +# /data is a Docker volume mounted by devcontainer.json. +volumes = ["/data:/var/lib/localstack"] +env = ["devcontainer"] + +# LocalStack configuration: https://docs.localstack.cloud/aws/customization/configuration-options/ +[env.devcontainer] +DEBUG = "${templateOption:debug}" +LS_LOG = "${templateOption:logLevel}" +PERSISTENCE = "${templateOption:persistence}" +ENFORCE_IAM = "${templateOption:enforceIam}" +AUTO_LOAD_POD = "${templateOption:loadPods}" diff --git a/src/localstack-dind/.devcontainer/lstk/post-create.sh b/src/localstack-dind/.devcontainer/lstk/post-create.sh new file mode 100755 index 0000000..938b171 --- /dev/null +++ b/src/localstack-dind/.devcontainer/lstk/post-create.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Runs once after the dev container is created. +set -euo pipefail + +config_dir="${HOME}/.config/lstk" +mkdir -p "${config_dir}" +ln -sfn "$(cd "$(dirname "$0")" && pwd)/config.toml" "${config_dir}/config.toml" + +# Writes the `localstack` profile used by `aws` and the AWS SDKs (AWS_PROFILE=localstack). +lstk --non-interactive setup aws --force diff --git a/src/localstack-dind/.devcontainer/lstk/post-start.sh b/src/localstack-dind/.devcontainer/lstk/post-start.sh new file mode 100755 index 0000000..fef511f --- /dev/null +++ b/src/localstack-dind/.devcontainer/lstk/post-start.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Runs on every dev container start. Usage: post-start.sh +set -uo pipefail + +if [ "${1:-true}" != "true" ]; then + echo "LocalStack auto-start is off. Run 'lstk start' to start it." + exit 0 +fi + +echo "Waiting for the Docker daemon..." +if ! timeout 60 bash -c 'until docker info > /dev/null 2>&1; do sleep 1; done'; then + echo "The Docker daemon did not come up within 60s. Run 'lstk start' once it is ready." >&2 + exit 1 +fi + +# The first start pulls the LocalStack image, so allow more than the 60s default. +LSTK_STARTUP_TIMEOUT="${LSTK_STARTUP_TIMEOUT:-5m}" lstk --non-interactive start +status=$? + +if [ "${status}" -ne 0 ] && [ -z "${LOCALSTACK_AUTH_TOKEN:-}" ]; then + echo "LocalStack did not start and LOCALSTACK_AUTH_TOKEN is not set." + echo "Set it on the host and rebuild the container, or run 'lstk login' and then 'lstk start'." + exit 0 +fi +exit "${status}" diff --git a/src/localstack-dind/NOTES.md b/src/localstack-dind/NOTES.md index ef1287e..1b2fab0 100644 --- a/src/localstack-dind/NOTES.md +++ b/src/localstack-dind/NOTES.md @@ -1,13 +1,53 @@ -This version of the Template starts up LocalStack in an internal Docker service in the DevContainer, hence we set a volume by default for data persistence. -As a result the newly built DevContainers do not necessarily need to re-download images as long this volume exists on the system. -Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data (`LOCALSTACK_VOLUME_DIR`). +This Template runs LocalStack inside the dev container's own Docker daemon, using the [docker-in-docker](https://github.com/devcontainers/features/tree/main/src/docker-in-docker) Feature. +[`lstk`](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), the LocalStack CLI, starts and manages it. +The Template adds the [LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature) for `lstk` and the AWS CLI Feature. -The Template adds automatically the [official LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs the CLI and by demand the most popular *Local Tools™*. -Currently this calls for a **Debian-based** DevContainer image. +## Auth token -LocalStack in this variation is controlled via the LocalStack CLI and some env variables that you can adjust or expand in the `devcontainer.json` file's `remoteEnv` block. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). +Set `LOCALSTACK_AUTH_TOKEN` on the host before you build the container. +The Template reads it through `${localEnv:LOCALSTACK_AUTH_TOKEN}` and never writes it into your files. +If it is not set, the container still builds. Run `lstk login` in a terminal and then `lstk start`. +See the [auth token documentation](https://docs.localstack.cloud/aws/getting-started/auth-token/). -## Use LocalStack Pro +## How it works -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the Template. \ No newline at end of file +| File | Purpose | +| --- | --- | +| `.devcontainer/devcontainer.json` | Base image, Features, environment and lifecycle commands. | +| `.devcontainer/lstk/config.toml` | `lstk` configuration: image tag, port, mounts and LocalStack variables. `~/.config/lstk/config.toml` links to it. | +| `.devcontainer/lstk/post-create.sh` | Links the config and writes the `localstack` AWS profile with `lstk setup aws`. | +| `.devcontainer/lstk/post-start.sh` | Waits for Docker and runs `lstk start` on every container start (when `startup` is on). | + +LocalStack state lives in `/var/lib/localstack` inside the emulator, backed by the `localstack-data-` Docker volume mounted at `/data`. +It survives container rebuilds. Docker images are kept in the volume the docker-in-docker Feature creates. + +To change LocalStack settings, edit `.devcontainer/lstk/config.toml` and run `lstk restart`. +For the available variables see the [configuration reference](https://docs.localstack.cloud/aws/customization/configuration-options/). + +## Using LocalStack + +```bash +lstk status # emulator status and deployed resources +lstk aws s3 mb s3://demo # AWS CLI against LocalStack (replaces awslocal) +aws s3 ls # plain aws uses the localstack profile (AWS_PROFILE=localstack) +lstk logs --follow +lstk stop +``` + +`AWS_PROFILE=localstack` also points the AWS SDKs at LocalStack. +The Template does not set `AWS_ENDPOINT_URL`, because `lstk start` refuses to run when it is set. + +For Terraform, AWS CDK or AWS SAM, add the tool's Feature and use `lstk terraform`, `lstk cdk` or `lstk sam`: + +| Command | Feature | +| --- | --- | +| `lstk terraform`, `lstk tf` | `ghcr.io/devcontainers/features/terraform:1` | +| `lstk cdk` | `ghcr.io/devcontainers/features/node:1` and `ghcr.io/devcontainers-extra/features/aws-cdk:2` | +| `lstk sam` | `ghcr.io/customink/codespaces-features/sam-cli:1` | + +## Migrating from 0.x + +Version 1.0.0 replaces the legacy `localstack` CLI with `lstk`. +The `awslocal`, `cdklocal`, `pulumilocal`, `samlocal`, `tflocal`, `usePro` and `volumePath` options are gone. +LocalStack now always runs the `localstack/localstack-pro` image, which needs an auth token. +See the [lstk migration guide](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/migration/). diff --git a/src/localstack-dind/README.md b/src/localstack-dind/README.md index 9a476c0..fc78382 100644 --- a/src/localstack-dind/README.md +++ b/src/localstack-dind/README.md @@ -1,42 +1,75 @@ - # LocalStack Docker-in-Docker (localstack-dind) -A template to manage LocalStack in DinD via CLI +Runs LocalStack inside the dev container's own Docker daemon and manages it with lstk. ## Options | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| imageVariant | Debian version (use bullseye or jammy on local arm64/Apple Silicon): | string | jammy | -| awslocal | Install LocalStack wrapper for AWS CLI: | boolean | false | -| cdklocal | Install LocalStack wrapper for CDK: | boolean | false | -| pulumilocal | Install LocalStack wrapper for Pulumi: | boolean | false | -| samlocal | Install LocalStack wrapper for AWS SAM CLI: | boolean | false | -| tflocal | Install LocalStack wrapper for Terraform: | boolean | false | -| logLevel | Set LocalStack log level: | string | info | -| debug | - | boolean | false | -| persistence | - | boolean | false | -| usePro | - | boolean | false | -| version | - | string | latest | -| loadPods | - | string | | -| volumePath | - | string | ./.volume | -| enforceIam | - | boolean | false | -| defaultRegion | - | string | us-east-1 | -| startup | Start up LocalStack: | boolean | true | - -This version of the Template starts up LocalStack in an internal Docker service in the DevContainer, hence we set a volume by default for data persistence. -As a result the newly built DevContainers do not necessarily need to re-download images as long this volume exists on the system. -Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data (`LOCALSTACK_VOLUME_DIR`). - -The Template adds automatically the [official LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs the CLI and by demand the most popular *Local Tools™*. -Currently this calls for a **Debian-based** DevContainer image. - -LocalStack in this variation is controlled via the LocalStack CLI and some env variables that you can adjust or expand in the `devcontainer.json` file's `remoteEnv` block. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). - -## Use LocalStack Pro - -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the Template. +| imageVariant | Ubuntu or Debian version of the base image: | string | noble | +| version | LocalStack image tag (localstack/localstack-pro): | string | latest | +| logLevel | LocalStack log level (LS_LOG): | string | info | +| debug | Enable LocalStack debug mode (DEBUG): | boolean | false | +| persistence | Persist LocalStack state across restarts (PERSISTENCE): | boolean | false | +| enforceIam | Enforce IAM policies (ENFORCE_IAM): | boolean | false | +| loadPods | Cloud Pods to load at start-up, comma-separated (AUTO_LOAD_POD): | string | | +| defaultRegion | Default AWS region for the AWS CLI and SDKs: | string | us-east-1 | +| startup | Start LocalStack with lstk when the container starts: | boolean | true | + +This Template runs LocalStack inside the dev container's own Docker daemon, using the [docker-in-docker](https://github.com/devcontainers/features/tree/main/src/docker-in-docker) Feature. +[`lstk`](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), the LocalStack CLI, starts and manages it. +The Template adds the [LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature) for `lstk` and the AWS CLI Feature. + +## Auth token + +Set `LOCALSTACK_AUTH_TOKEN` on the host before you build the container. +The Template reads it through `${localEnv:LOCALSTACK_AUTH_TOKEN}` and never writes it into your files. +If it is not set, the container still builds. Run `lstk login` in a terminal and then `lstk start`. +See the [auth token documentation](https://docs.localstack.cloud/aws/getting-started/auth-token/). + +## How it works + +| File | Purpose | +| --- | --- | +| `.devcontainer/devcontainer.json` | Base image, Features, environment and lifecycle commands. | +| `.devcontainer/lstk/config.toml` | `lstk` configuration: image tag, port, mounts and LocalStack variables. `~/.config/lstk/config.toml` links to it. | +| `.devcontainer/lstk/post-create.sh` | Links the config and writes the `localstack` AWS profile with `lstk setup aws`. | +| `.devcontainer/lstk/post-start.sh` | Waits for Docker and runs `lstk start` on every container start (when `startup` is on). | + +LocalStack state lives in `/var/lib/localstack` inside the emulator, backed by the `localstack-data-` Docker volume mounted at `/data`. +It survives container rebuilds. Docker images are kept in the volume the docker-in-docker Feature creates. + +To change LocalStack settings, edit `.devcontainer/lstk/config.toml` and run `lstk restart`. +For the available variables see the [configuration reference](https://docs.localstack.cloud/aws/customization/configuration-options/). + +## Using LocalStack + +```bash +lstk status # emulator status and deployed resources +lstk aws s3 mb s3://demo # AWS CLI against LocalStack (replaces awslocal) +aws s3 ls # plain aws uses the localstack profile (AWS_PROFILE=localstack) +lstk logs --follow +lstk stop +``` + +`AWS_PROFILE=localstack` also points the AWS SDKs at LocalStack. +The Template does not set `AWS_ENDPOINT_URL`, because `lstk start` refuses to run when it is set. + +For Terraform, AWS CDK or AWS SAM, add the tool's Feature and use `lstk terraform`, `lstk cdk` or `lstk sam`: + +| Command | Feature | +| --- | --- | +| `lstk terraform`, `lstk tf` | `ghcr.io/devcontainers/features/terraform:1` | +| `lstk cdk` | `ghcr.io/devcontainers/features/node:1` and `ghcr.io/devcontainers-extra/features/aws-cdk:2` | +| `lstk sam` | `ghcr.io/customink/codespaces-features/sam-cli:1` | + +## Migrating from 0.x + +Version 1.0.0 replaces the legacy `localstack` CLI with `lstk`. +The `awslocal`, `cdklocal`, `pulumilocal`, `samlocal`, `tflocal`, `usePro` and `volumePath` options are gone. +LocalStack now always runs the `localstack/localstack-pro` image, which needs an auth token. +See the [lstk migration guide](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/migration/). + --- diff --git a/src/localstack-dind/devcontainer-template.json b/src/localstack-dind/devcontainer-template.json index 7915a54..849e9a5 100644 --- a/src/localstack-dind/devcontainer-template.json +++ b/src/localstack-dind/devcontainer-template.json @@ -1,50 +1,35 @@ { "id": "localstack-dind", - "version": "0.1.1", + "version": "1.0.0", "name": "LocalStack Docker-in-Docker", - "description": "A template to manage LocalStack in DinD via CLI", + "description": "Runs LocalStack inside the dev container's own Docker daemon and manages it with lstk.", "documentationURL": "https://github.com/localstack/devcontainer-template/tree/main/src/localstack-dind", "licenseURL": "https://github.com/localstack/devcontainer-template/blob/main/LICENSE", "options": { "imageVariant": { "type": "string", - "description": "Debian version (use bullseye or jammy on local arm64/Apple Silicon):", + "description": "Ubuntu or Debian version of the base image:", "proposals": [ + "noble", "jammy", - "focal", - "bullseye", + "resolute", "bookworm" ], - "default": "jammy" + "default": "noble" }, - "awslocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for AWS CLI:", - "default": "false" - }, - "cdklocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for CDK:", - "default": "false" - }, - "pulumilocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for Pulumi:", - "default": "false" - }, - "samlocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for AWS SAM CLI:", - "default": "false" - }, - "tflocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for Terraform:", - "default": "false" + "version": { + "type": "string", + "description": "LocalStack image tag (localstack/localstack-pro):", + "proposals": [ + "latest", + "stable", + "2026.10" + ], + "default": "latest" }, "logLevel": { "type": "string", - "description": "Set LocalStack log level:", + "description": "LocalStack log level (LS_LOG):", "enum": [ "trace", "trace-internal", @@ -58,53 +43,27 @@ }, "debug": { "type": "boolean", - "descripiton": "Enable LocalStack debugging:", - "default": "false" + "description": "Enable LocalStack debug mode (DEBUG):", + "default": false }, "persistence": { "type": "boolean", - "descripiton": "Enable persistence in LocalStack:", - "default": "false" + "description": "Persist LocalStack state across restarts (PERSISTENCE):", + "default": false }, - "usePro": { + "enforceIam": { "type": "boolean", - "descripiton": "Enable LocalStack Pro:", - "default": "false" - }, - "version": { - "type": "string", - "descripiton": "Use LocalStack version:", - "proposals": [ - "latest", - "3.6.0", - "3.5.0", - "3.4.0", - "3.3.0", - "3.2.0", - "3.1.0", - "3.0.2", - "3.0.1" - ], - "default": "latest" + "description": "Enforce IAM policies (ENFORCE_IAM):", + "default": false }, "loadPods": { "type": "string", - "descripiton": "Load Cloud Pods at start-up (comma-separated list):", - "default": " " - }, - "volumePath": { - "type": "string", - "descripiton": "LocalStack volume location on the host (currently only local (bind) mounts recommended):", - "default": "./.volume" - }, - "enforceIam": { - "type": "boolean", - "descripiton": "Enforce IAM:", - "default": "false" + "description": "Cloud Pods to load at start-up, comma-separated (AUTO_LOAD_POD):", + "default": "" }, "defaultRegion": { "type": "string", - "descripiton": "Default AWS region:", + "description": "Default AWS region for the AWS CLI and SDKs:", "proposals": [ "us-east-1", "us-east-2", @@ -140,11 +99,17 @@ }, "startup": { "type": "boolean", - "description": "Start up LocalStack:", - "default": "true" + "description": "Start LocalStack with lstk when the container starts:", + "default": true } }, "platforms": [ "Any" + ], + "keywords": [ + "localstack", + "lstk", + "aws", + "docker-in-docker" ] } diff --git a/src/localstack-dood/.devcontainer/.env b/src/localstack-dood/.devcontainer/.env index 7cc063e..90ac711 100644 --- a/src/localstack-dood/.devcontainer/.env +++ b/src/localstack-dood/.devcontainer/.env @@ -1,15 +1,9 @@ -# Activate LocalStack Pro: https://docs.localstack.cloud/getting-started/auth-token/ -LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:-} # required for Pro, not processed via template due to security reasons -LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY:-} -# LocalStack configuration: https://docs.localstack.cloud/references/configuration/ -ACTIVATE_PRO=${templateOption:usePro} +# LocalStack configuration, loaded into the localstack service. +# Reference: https://docs.localstack.cloud/aws/customization/configuration-options/ +# Rebuild the dev container to apply changes. DEBUG=${templateOption:debug} LS_LOG=${templateOption:logLevel} PERSISTENCE=${templateOption:persistence} -AWS_ENDPOINT_URL=http://${templateOption:host} -LOCALSTACK_HOST=${templateOption:host} -AUTO_LOAD_POD=${templateOption:loadPods} ENFORCE_IAM=${templateOption:enforceIam} -AWS_REGION=${templateOption:defaultRegion} -AWS_DEFAULT_REGION=${templateOption:defaultRegion} -IMAGE_NAME=localstack/localstack-pro:${templateOption:version} \ No newline at end of file +AUTO_LOAD_POD=${templateOption:loadPods} +LOCALSTACK_HOST=${templateOption:host} diff --git a/src/localstack-dood/.devcontainer/devcontainer.json b/src/localstack-dood/.devcontainer/devcontainer.json index e0b6bca..0dc1d78 100644 --- a/src/localstack-dood/.devcontainer/devcontainer.json +++ b/src/localstack-dood/.devcontainer/devcontainer.json @@ -7,13 +7,16 @@ // 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features. "features": { "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, - "ghcr.io/localstack/devcontainer-feature/localstack-cli:latest": { - "version": "${templateOption:version}", - "awslocal": ${templateOption:awslocal}, // if true, add in features manually: ghcr.io/devcontainers/features/aws-cli - "cdklocal": ${templateOption:cdklocal}, // if true, add in features manually: ghcr.io/devcontainers-contrib/features/aws-cdk - "pulumilocal": ${templateOption:pulumilocal}, // if true, add in features manually: ghcr.io/devcontainers-contrib/features/pulumi - "samlocal": ${templateOption:samlocal}, // if true, add in features manually: ghcr.io/customink/codespaces-features/sam-cli - "tflocal": ${templateOption:tflocal} // if true, add in features manually: ghcr.io/devcontainers-contrib/features/terraform-asdf - } - } + // `lstk aws` and the `localstack` profile need the AWS CLI. + "ghcr.io/devcontainers/features/aws-cli:1": {}, + // Installs lstk. For `lstk terraform`, `lstk cdk` or `lstk sam`, also add + // ghcr.io/devcontainers/features/terraform:1, ghcr.io/devcontainers-extra/features/aws-cdk:2 + // or ghcr.io/customink/codespaces-features/sam-cli:1. + "ghcr.io/localstack/devcontainer-feature/localstack-cli:1": {} + }, + + // Writes the `localstack` AWS profile. + "postCreateCommand": "lstk --non-interactive setup aws --force", + // Waits for the localstack service and prints its status. + "postStartCommand": "bash .devcontainer/lstk/post-start.sh" } diff --git a/src/localstack-dood/.devcontainer/docker-compose.yml b/src/localstack-dood/.devcontainer/docker-compose.yml index cb4d8c5..c78c4f5 100644 --- a/src/localstack-dood/.devcontainer/docker-compose.yml +++ b/src/localstack-dood/.devcontainer/docker-compose.yml @@ -1,25 +1,27 @@ -version: "3.8" - services: localstack: - container_name: "localstack-main" - image: localstack/localstack-pro:${templateOption:version} # required for Pro + container_name: localstack-main + image: localstack/localstack-pro:${templateOption:version} ports: - "127.0.0.1:4566:4566" # LocalStack Gateway - - "127.0.0.1:4510-4559:4510-4559" # external services port range - - "127.0.0.1:443:443" # LocalStack HTTPS Gateway (Pro) + - "127.0.0.1:4510-4559:4510-4559" # External services port range + - "127.0.0.1:443:443" # LocalStack HTTPS Gateway env_file: - .env + environment: + # Read from the host environment, never written into the template. + LOCALSTACK_AUTH_TOKEN: ${LOCALSTACK_AUTH_TOKEN:-} + # Containers that LocalStack starts, such as Lambda functions, join the shared network. + LAMBDA_DOCKER_NETWORK: ${templateOption:networkName} volumes: - "/var/run/docker.sock:/var/run/docker.sock" - "${templateOption:volumePath}:/var/lib/localstack" networks: - ${templateOption:networkName}: - # Set the container IP address in the ${templateOption:networkCidr} subnet + ls: ipv4_address: ${templateOption:ipAddress} - + app: - build: + build: context: . dockerfile: Dockerfile volumes: @@ -27,17 +29,27 @@ services: # Overrides default command so things don't shut down after the process ends. command: sleep infinity init: true - env_file: - - .env + environment: + # Used by lstk for Cloud Pods and other platform commands. + LOCALSTACK_AUTH_TOKEN: ${LOCALSTACK_AUTH_TOKEN:-} + # lstk talks to the localstack service instead of starting its own container. + LSTK_ENDPOINT_URL: http://${templateOption:host} + LOCALSTACK_HOST: ${templateOption:host} + # `aws` and the AWS SDKs use the `localstack` profile written by `lstk setup aws`. + AWS_PROFILE: localstack + AWS_REGION: ${templateOption:defaultRegion} + AWS_DEFAULT_REGION: ${templateOption:defaultRegion} dns: - # Set the DNS server to be the LocalStack container + # LocalStack's DNS server resolves localhost.localstack.cloud to the localstack service. - ${templateOption:ipAddress} + depends_on: + - localstack networks: - - ${templateOption:networkName} + - ls networks: - ${templateOption:networkName}: + ls: + name: ${templateOption:networkName} ipam: config: - # Specify the subnet range for IP address allocation - - subnet: ${templateOption:networkCidr} \ No newline at end of file + - subnet: ${templateOption:networkCidr} diff --git a/src/localstack-dood/.devcontainer/lstk/post-start.sh b/src/localstack-dood/.devcontainer/lstk/post-start.sh new file mode 100755 index 0000000..7ddd982 --- /dev/null +++ b/src/localstack-dood/.devcontainer/lstk/post-start.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Runs on every dev container start. LocalStack itself runs as the localstack +# service in docker-compose.yml; lstk reaches it through LSTK_ENDPOINT_URL. +set -uo pipefail + +echo "Waiting for LocalStack at ${LSTK_ENDPOINT_URL}..." +if timeout 120 bash -c 'until curl -fs "${LSTK_ENDPOINT_URL}/_localstack/health" > /dev/null; do sleep 2; done'; then + lstk --non-interactive status + exit 0 +fi + +echo "LocalStack is not reachable at ${LSTK_ENDPOINT_URL}." +if [ -z "${LOCALSTACK_AUTH_TOKEN:-}" ]; then + echo "The localstack service needs LOCALSTACK_AUTH_TOKEN. Set it on the host and rebuild the container." +fi +echo "Check the service logs with: docker logs localstack-main" +exit 0 diff --git a/src/localstack-dood/NOTES.md b/src/localstack-dood/NOTES.md index a9da843..d231e91 100644 --- a/src/localstack-dood/NOTES.md +++ b/src/localstack-dood/NOTES.md @@ -1,18 +1,51 @@ -This version of the Template starts up LocalStack as a separate container in the same Docker network using the host system's Docker socket. +This Template runs LocalStack as a separate `localstack` service in Docker Compose, next to the dev container, using the host's Docker daemon. +Both containers share a Docker network, and LocalStack's DNS server resolves `localhost.localstack.cloud` to the LocalStack container. +The Template adds the [LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature) for [`lstk`](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), the AWS CLI Feature and the docker-outside-of-docker Feature. -To control LocalStack's behaviour adjust the provided `.env` file which will be loaded both into LocalStack and the created DevContainer after rebuild. -For further customisation you can edit the provided `Dockerfile` and/or the `devcontainer.json` file. -Or add additional services by modifying the provided `docker-compose.yml` file. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). +## Auth token -The Template adds automatically the [official LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs the CLI and by demand the most popular *Local Tools™*. -Currently this calls for a **Debian-based** DevContainer image. +Set `LOCALSTACK_AUTH_TOKEN` on the host before you build the container. +Docker Compose passes it to the `localstack` service and the dev container. It is never written into your files. +See the [auth token documentation](https://docs.localstack.cloud/aws/getting-started/auth-token/). ->[!WARNING] -> In this Template version however the LocalStack CLI provides the `start` and `stop` options do not control the LocalStack container with them as that would result in name resolution issues with the container. -> -> In case you've made this mistake by accident, try running `docker compose -f /docker-compose.yml up -d localstack` or rebuild the container. +## How it works -#### Use LocalStack Pro +| File | Purpose | +| --- | --- | +| `.devcontainer/docker-compose.yml` | The `localstack` and `app` services and their shared network. | +| `.devcontainer/.env` | LocalStack variables for the `localstack` service. | +| `.devcontainer/Dockerfile` | Base image of the dev container. | +| `.devcontainer/devcontainer.json` | Features and lifecycle commands. | +| `.devcontainer/lstk/post-start.sh` | Waits for LocalStack and prints `lstk status`. | -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the `.env` file. \ No newline at end of file +Docker Compose owns the LocalStack container, not `lstk`. +`LSTK_ENDPOINT_URL` points `lstk` at the `localstack` service, so `lstk status`, `lstk aws`, `lstk terraform`, `lstk cdk`, `lstk sam` and the snapshot commands work as usual. +`lstk start`, `lstk stop`, `lstk restart` and `lstk logs` refuse to run against an external endpoint. +Use `docker restart localstack-main` and `docker logs localstack-main` instead, or rebuild the container. + +Lambda functions and other containers that LocalStack starts join the same network through `LAMBDA_DOCKER_NETWORK`. +LocalStack state is stored in the `volumePath` folder, relative to `.devcontainer/`. +For more LocalStack variables, add them to `.env` and see the [configuration reference](https://docs.localstack.cloud/aws/customization/configuration-options/). + +## Using LocalStack + +```bash +lstk status # emulator status and deployed resources +lstk aws s3 mb s3://demo # AWS CLI against LocalStack (replaces awslocal) +aws s3 ls # plain aws uses the localstack profile (AWS_PROFILE=localstack) +``` + +For Terraform, AWS CDK or AWS SAM, add the tool's Feature and use `lstk terraform`, `lstk cdk` or `lstk sam`: + +| Command | Feature | +| --- | --- | +| `lstk terraform`, `lstk tf` | `ghcr.io/devcontainers/features/terraform:1` | +| `lstk cdk` | `ghcr.io/devcontainers/features/node:1` and `ghcr.io/devcontainers-extra/features/aws-cdk:2` | +| `lstk sam` | `ghcr.io/customink/codespaces-features/sam-cli:1` | + +## Migrating from 0.x + +Version 1.0.0 replaces the legacy `localstack` CLI with `lstk`. +The `awslocal`, `cdklocal`, `pulumilocal`, `samlocal`, `tflocal` and `usePro` options are gone. +LocalStack now always runs the `localstack/localstack-pro` image, which needs an auth token. +See the [lstk migration guide](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/migration/). diff --git a/src/localstack-dood/README.md b/src/localstack-dood/README.md index ad23591..201c661 100644 --- a/src/localstack-dood/README.md +++ b/src/localstack-dood/README.md @@ -1,50 +1,77 @@ - # LocalStack Docker-outside-of-Docker (localstack-dood) -A template to manage LocalStack in DooD +Runs LocalStack as a Docker Compose service next to the dev container. lstk talks to it over the shared network. ## Options | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| imageVariant | Debian version (use bullseye or jammy on local arm64/Apple Silicon): | string | jammy | -| awslocal | Install LocalStack wrapper for AWS CLI: | boolean | false | -| cdklocal | Install LocalStack wrapper for CDK: | boolean | false | -| pulumilocal | Install LocalStack wrapper for Pulumi: | boolean | false | -| samlocal | Install LocalStack wrapper for AWS SAM CLI: | boolean | false | -| tflocal | Install LocalStack wrapper for Terraform: | boolean | false | -| logLevel | Set LocalStack log level: | string | info | -| networkName | - | string | ls | -| networkCidr | - | string | 10.0.2.0/24 | -| ipAddress | - | string | 10.0.2.20 | -| host | - | string | localhost.localstack.cloud:4566 | -| debug | - | boolean | false | -| persistence | - | boolean | false | -| usePro | - | boolean | false | -| version | - | string | latest | -| loadPods | - | string | | -| volumePath | - | string | ./.volume | -| enforceIam | - | boolean | false | -| defaultRegion | - | string | us-east-1 | - -This version of the Template starts up LocalStack as a separate container in the same Docker network using the host system's Docker socket. - -To control LocalStack's behaviour adjust the provided `.env` file which will be loaded both into LocalStack and the created DevContainer after rebuild. -For further customisation you can edit the provided `Dockerfile` and/or the `devcontainer.json` file. -Or add additional services by modifying the provided `docker-compose.yml` file. -For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/). - -The Template adds automatically the [official LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature), which installs the CLI and by demand the most popular *Local Tools™*. -Currently this calls for a **Debian-based** DevContainer image. - ->[!WARNING] -> In this Template version however the LocalStack CLI provides the `start` and `stop` options do not control the LocalStack container with them as that would result in name resolution issues with the container. -> -> In case you've made this mistake by accident, try running `docker compose -f /docker-compose.yml up -d localstack` or rebuild the container. - -#### Use LocalStack Pro - -Set `usePro: true` and set on your host system the `LOCALSTACK_AUTH_TOKEN` or the `LOCALSTACK_API_KEY` environment variable, this will be automatically picked up by the `.env` file. +| imageVariant | Ubuntu or Debian version of the base image: | string | noble | +| version | LocalStack image tag (localstack/localstack-pro): | string | latest | +| logLevel | LocalStack log level (LS_LOG): | string | info | +| debug | Enable LocalStack debug mode (DEBUG): | boolean | false | +| persistence | Persist LocalStack state across restarts (PERSISTENCE): | boolean | false | +| enforceIam | Enforce IAM policies (ENFORCE_IAM): | boolean | false | +| loadPods | Cloud Pods to load at start-up, comma-separated (AUTO_LOAD_POD): | string | | +| defaultRegion | Default AWS region for the AWS CLI and SDKs: | string | us-east-1 | +| networkName | Docker network shared by LocalStack, the dev container and Lambda containers: | string | ls | +| networkCidr | LocalStack network CIDR: | string | 10.0.2.0/24 | +| ipAddress | LocalStack IP address (inside the network CIDR): | string | 10.0.2.20 | +| host | LocalStack hostname and port (LOCALSTACK_HOST): | string | localhost.localstack.cloud:4566 | +| volumePath | Host folder for LocalStack state, relative to .devcontainer/: | string | ./.volume | + +This Template runs LocalStack as a separate `localstack` service in Docker Compose, next to the dev container, using the host's Docker daemon. +Both containers share a Docker network, and LocalStack's DNS server resolves `localhost.localstack.cloud` to the LocalStack container. +The Template adds the [LocalStack DevContainer Feature](https://github.com/localstack/devcontainer-feature) for [`lstk`](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/), the AWS CLI Feature and the docker-outside-of-docker Feature. + +## Auth token + +Set `LOCALSTACK_AUTH_TOKEN` on the host before you build the container. +Docker Compose passes it to the `localstack` service and the dev container. It is never written into your files. +See the [auth token documentation](https://docs.localstack.cloud/aws/getting-started/auth-token/). + +## How it works + +| File | Purpose | +| --- | --- | +| `.devcontainer/docker-compose.yml` | The `localstack` and `app` services and their shared network. | +| `.devcontainer/.env` | LocalStack variables for the `localstack` service. | +| `.devcontainer/Dockerfile` | Base image of the dev container. | +| `.devcontainer/devcontainer.json` | Features and lifecycle commands. | +| `.devcontainer/lstk/post-start.sh` | Waits for LocalStack and prints `lstk status`. | + +Docker Compose owns the LocalStack container, not `lstk`. +`LSTK_ENDPOINT_URL` points `lstk` at the `localstack` service, so `lstk status`, `lstk aws`, `lstk terraform`, `lstk cdk`, `lstk sam` and the snapshot commands work as usual. +`lstk start`, `lstk stop`, `lstk restart` and `lstk logs` refuse to run against an external endpoint. +Use `docker restart localstack-main` and `docker logs localstack-main` instead, or rebuild the container. + +Lambda functions and other containers that LocalStack starts join the same network through `LAMBDA_DOCKER_NETWORK`. +LocalStack state is stored in the `volumePath` folder, relative to `.devcontainer/`. +For more LocalStack variables, add them to `.env` and see the [configuration reference](https://docs.localstack.cloud/aws/customization/configuration-options/). + +## Using LocalStack + +```bash +lstk status # emulator status and deployed resources +lstk aws s3 mb s3://demo # AWS CLI against LocalStack (replaces awslocal) +aws s3 ls # plain aws uses the localstack profile (AWS_PROFILE=localstack) +``` + +For Terraform, AWS CDK or AWS SAM, add the tool's Feature and use `lstk terraform`, `lstk cdk` or `lstk sam`: + +| Command | Feature | +| --- | --- | +| `lstk terraform`, `lstk tf` | `ghcr.io/devcontainers/features/terraform:1` | +| `lstk cdk` | `ghcr.io/devcontainers/features/node:1` and `ghcr.io/devcontainers-extra/features/aws-cdk:2` | +| `lstk sam` | `ghcr.io/customink/codespaces-features/sam-cli:1` | + +## Migrating from 0.x + +Version 1.0.0 replaces the legacy `localstack` CLI with `lstk`. +The `awslocal`, `cdklocal`, `pulumilocal`, `samlocal`, `tflocal` and `usePro` options are gone. +LocalStack now always runs the `localstack/localstack-pro` image, which needs an auth token. +See the [lstk migration guide](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/migration/). + --- diff --git a/src/localstack-dood/devcontainer-template.json b/src/localstack-dood/devcontainer-template.json index 4037beb..707e655 100644 --- a/src/localstack-dood/devcontainer-template.json +++ b/src/localstack-dood/devcontainer-template.json @@ -1,50 +1,35 @@ { "id": "localstack-dood", - "version": "0.1.2", + "version": "1.0.0", "name": "LocalStack Docker-outside-of-Docker", - "description": "A template to manage LocalStack in DooD", + "description": "Runs LocalStack as a Docker Compose service next to the dev container. lstk talks to it over the shared network.", "documentationURL": "https://github.com/localstack/devcontainer-template/tree/main/src/localstack-dood", "licenseURL": "https://github.com/localstack/devcontainer-template/blob/main/LICENSE", "options": { "imageVariant": { "type": "string", - "description": "Debian version (use bullseye or jammy on local arm64/Apple Silicon):", + "description": "Ubuntu or Debian version of the base image:", "proposals": [ + "noble", "jammy", - "focal", - "bullseye", + "resolute", "bookworm" ], - "default": "jammy" + "default": "noble" }, - "awslocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for AWS CLI:", - "default": "false" - }, - "cdklocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for CDK:", - "default": "false" - }, - "pulumilocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for Pulumi:", - "default": "false" - }, - "samlocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for AWS SAM CLI:", - "default": "false" - }, - "tflocal": { - "type": "boolean", - "description": "Install LocalStack wrapper for Terraform:", - "default": "false" + "version": { + "type": "string", + "description": "LocalStack image tag (localstack/localstack-pro):", + "proposals": [ + "latest", + "stable", + "2026.10" + ], + "default": "latest" }, "logLevel": { "type": "string", - "description": "Set LocalStack log level:", + "description": "LocalStack log level (LS_LOG):", "enum": [ "trace", "trace-internal", @@ -56,78 +41,29 @@ ], "default": "info" }, - "networkName": { - "type": "string", - "descripiton": "LocalStack network name:", - "default": "ls" - }, - "networkCidr": { - "type": "string", - "descripiton": "LocalStack network CIDR:", - "default": "10.0.2.0/24" - }, - "ipAddress": { - "type": "string", - "descripiton": "LocalStack IP:", - "default": "10.0.2.20" - }, - "host": { - "type": "string", - "descripiton": "LocalStack hostname:", - "proposals": [ - "localhost.localstack.cloud:4566" - ], - "default": "localhost.localstack.cloud:4566" - }, "debug": { "type": "boolean", - "descripiton": "Enable LocalStack debugging:", - "default": "false" + "description": "Enable LocalStack debug mode (DEBUG):", + "default": false }, "persistence": { "type": "boolean", - "descripiton": "Enable persistence in LocalStack:", - "default": "false" + "description": "Persist LocalStack state across restarts (PERSISTENCE):", + "default": false }, - "usePro": { + "enforceIam": { "type": "boolean", - "descripiton": "Enable LocalStack Pro:", - "default": "false" - }, - "version": { - "type": "string", - "descripiton": "Use LocalStack version:", - "proposals": [ - "latest", - "3.6.0", - "3.5.0", - "3.4.0", - "3.3.0", - "3.2.0", - "3.1.0", - "3.0.2", - "3.0.1" - ], - "default": "latest" + "description": "Enforce IAM policies (ENFORCE_IAM):", + "default": false }, "loadPods": { "type": "string", - "descripiton": "Load Cloud Pods at start-up (comma-separated list):", - "default": " " - }, - "volumePath": { - "type": "string", - "descripiton": "LocalStack volume location on the host (currently only local (bind) mounts recommended):", - "default": "./.volume" - }, - "enforceIam": { - "type": "boolean", - "descripiton": "Enforce IAM:", - "default": "false" + "description": "Cloud Pods to load at start-up, comma-separated (AUTO_LOAD_POD):", + "default": "" }, "defaultRegion": { "type": "string", - "descripiton": "Default AWS region:", + "description": "Default AWS region for the AWS CLI and SDKs:", "proposals": [ "us-east-1", "us-east-2", @@ -160,9 +96,43 @@ "sa-east-1" ], "default": "us-east-1" + }, + "networkName": { + "type": "string", + "description": "Docker network shared by LocalStack, the dev container and Lambda containers:", + "default": "ls" + }, + "networkCidr": { + "type": "string", + "description": "LocalStack network CIDR:", + "default": "10.0.2.0/24" + }, + "ipAddress": { + "type": "string", + "description": "LocalStack IP address (inside the network CIDR):", + "default": "10.0.2.20" + }, + "host": { + "type": "string", + "description": "LocalStack hostname and port (LOCALSTACK_HOST):", + "proposals": [ + "localhost.localstack.cloud:4566" + ], + "default": "localhost.localstack.cloud:4566" + }, + "volumePath": { + "type": "string", + "description": "Host folder for LocalStack state, relative to .devcontainer/:", + "default": "./.volume" } }, "platforms": [ "Any" + ], + "keywords": [ + "localstack", + "lstk", + "aws", + "docker-compose" ] } diff --git a/test/localstack-dind/custom_region_with_iam_enforce.sh b/test/localstack-dind/custom_region_with_iam_enforce.sh deleted file mode 100644 index 7f1c31a..0000000 --- a/test/localstack-dind/custom_region_with_iam_enforce.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -localstack wait -t 30 - -# Scenario specific tests -check "localstack version" localstack --version -check "default region" awslocal sqs create-queue --queue-name test-queue | grep eu-central-1 - -awslocal iam create-user --user-name test -awslocal iam put-user-policy --user-name test --policy-name restrict-queue-list --policy-document "$(cat < /dev/null -localstack wait -t 30 -check "debug enabled" "curl -s http://localhost:4566/_localstack/diagnose; echo" -check "debug enabled" "curl -s http://localhost:4566/_localstack/diagnose | jq -r '.config.LS_LOG' | grep trace" - -# Report result -reportResults diff --git a/test/localstack-dind/iac_tools_on_jammy.sh b/test/localstack-dind/iac_tools_on_jammy.sh new file mode 100755 index 0000000..d186f36 --- /dev/null +++ b/test/localstack-dind/iac_tools_on_jammy.sh @@ -0,0 +1,11 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +check "distro" "grep VERSION_CODENAME=jammy /etc/os-release" +check "emulator is running" "lstk --non-interactive status" +check "lstk terraform (replaces tflocal)" "terraformRoundTrip dind-tf-bucket" +check "lstk cdk (replaces cdklocal)" "cdkRoundTrip DindCdkStack" +check "lstk sam (replaces samlocal)" "samRoundTrip dind-sam-stack" + +reportResults diff --git a/test/localstack-dind/iam_region_and_debug.sh b/test/localstack-dind/iam_region_and_debug.sh new file mode 100755 index 0000000..9663649 --- /dev/null +++ b/test/localstack-dind/iam_region_and_debug.sh @@ -0,0 +1,10 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +check "emulator is running" "lstk --non-interactive status" +check "default region" "aws sqs create-queue --queue-name region-queue | grep eu-central-1" +check "IAM is enforced" "iamDenyRoundTrip devcontainer-test" +check "log level is trace" "curl -s ${LOCALSTACK_URL}/_localstack/diagnose | jq -r '.config.LS_LOG' | grep -x trace" + +reportResults diff --git a/test/localstack-dind/load_pod.sh b/test/localstack-dind/load_pod.sh new file mode 100755 index 0000000..5ceb4c9 --- /dev/null +++ b/test/localstack-dind/load_pod.sh @@ -0,0 +1,14 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +POD=devcontainer-template-ci-dind + +check "distro" "grep VERSION_CODENAME=resolute /etc/os-release" +check "AUTO_LOAD_POD passed to the emulator" "docker inspect localstack-aws --format '{{join .Config.Env \" \"}}' | grep -w AUTO_LOAD_POD=${POD}" +check "seed and save pod" "aws s3 mb s3://pod-bucket && lstk --non-interactive snapshot save pod:${POD}" +check "lstk restart" "lstk --non-interactive restart" +check "pod auto-loaded on start" "timeout 60 bash -c 'until aws s3 ls | grep -q pod-bucket; do sleep 2; done'" +lstk --non-interactive snapshot remove pod:${POD} --force + +reportResults diff --git a/test/localstack-dind/no_startup.sh b/test/localstack-dind/no_startup.sh new file mode 100755 index 0000000..2edf856 --- /dev/null +++ b/test/localstack-dind/no_startup.sh @@ -0,0 +1,10 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +check "lstk installed" lstk --version +check "docker is up" "docker info > /dev/null" +check "emulator not started" "! docker ps --format '{{.Names}}' | grep -q localstack" +check "localstack AWS profile written" "aws configure get endpoint_url --profile localstack | grep localhost.localstack.cloud:4566" + +reportResults diff --git a/test/localstack-dind/persistence_custom_volume_with_3_3_0.sh b/test/localstack-dind/persistence_custom_volume_with_3_3_0.sh deleted file mode 100644 index 4e3b896..0000000 --- a/test/localstack-dind/persistence_custom_volume_with_3_3_0.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -localstack wait -t 30 - -# Scenario specific tests -check "localstack-cli version" 'localstack --version | grep 3.3.0' -check "localstack image version" 'localstack status | grep "Docker image" | grep 3.3.0' -check "persist localstack data" "localstack config show | grep -w PERSISTENCE | grep -io True" - -awslocal s3 mb s3://devcontainer-persisted-data -localstack stop && localstack start -d -localstack wait -t 30 - -check "data persisted" "awslocal s3api list-buckets | jq -e '.Buckets | any(.Name == \"devcontainer-persisted-data\")' " - -# Report result -reportResults diff --git a/test/localstack-dind/persistence_pinned_version_on_bookworm.sh b/test/localstack-dind/persistence_pinned_version_on_bookworm.sh new file mode 100755 index 0000000..2718e17 --- /dev/null +++ b/test/localstack-dind/persistence_pinned_version_on_bookworm.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +check "distro" "grep VERSION_CODENAME=bookworm /etc/os-release" +check "pinned image tag" "docker inspect localstack-aws-2026.10 --format '{{.Config.Image}}' | grep -x 'localstack/localstack-pro:2026.10'" +check "PERSISTENCE passed to the emulator" "docker inspect localstack-aws-2026.10 --format '{{join .Config.Env \" \"}}' | grep -w PERSISTENCE=true" +check "volume path is /data" "lstk volume path | grep -x /data" +check "create bucket" "aws s3 mb s3://persisted-bucket" +check "lstk restart" "lstk --non-interactive restart" +check "bucket survives restart" "aws s3 ls | grep persisted-bucket" + +reportResults diff --git a/test/localstack-dind/scenarios.json b/test/localstack-dind/scenarios.json index 727bb01..b585502 100644 --- a/test/localstack-dind/scenarios.json +++ b/test/localstack-dind/scenarios.json @@ -1,47 +1,29 @@ { - "tools_no_startup": { - "features": { - "ghcr.io/devcontainers/features/node:1": {} - }, + "iac_tools_on_jammy": { "imageVariant": "jammy", - "awslocal": true, - "cdklocal": true, - "pulumilocal": true, - "samlocal": true, - "tflocal": true, - "startup": false + "features": { + "ghcr.io/devcontainers/features/terraform:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/devcontainers-extra/features/aws-cdk:2": {}, + "ghcr.io/customink/codespaces-features/sam-cli:1": {} + } }, - "debug_mode_on_bookworm": { + "persistence_pinned_version_on_bookworm": { "imageVariant": "bookworm", + "version": "2026.10", + "persistence": true + }, + "iam_region_and_debug": { + "defaultRegion": "eu-central-1", + "enforceIam": true, "debug": true, "logLevel": "trace" }, - "use_pro_and_pod": { - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} - }, - "usePro": true, - "awslocal": true, - "loadPods": "devcontainer-use_pro_and_pod", - "version": "3.5.0" + "load_pod": { + "imageVariant": "resolute", + "loadPods": "devcontainer-template-ci-dind" }, - "persistence_custom_volume_with_3_3_0": { - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} - }, - "usePro": true, - "awslocal": true, - "version": "3.3.0", - "persistence": true, - "volumePath": "./volume" - }, - "custom_region_with_iam_enforce": { - "awslocal": true, - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} - }, - "defaultRegion": "eu-central-1", - "enforceIam": true, - "usePro": true + "no_startup": { + "startup": false } -} \ No newline at end of file +} diff --git a/test/localstack-dind/test.sh b/test/localstack-dind/test.sh old mode 100644 new mode 100755 index 969aa4d..e1b7351 --- a/test/localstack-dind/test.sh +++ b/test/localstack-dind/test.sh @@ -2,10 +2,16 @@ cd $(dirname "$0") source test-utils.sh -# Template specific tests -check "distro" lsb_release -c | grep "jammy" -check "localstack status" localstack status -check "localstack stops" localstack stop +check "distro" "grep VERSION_CODENAME=noble /etc/os-release" +check "lstk installed" lstk --version +check "no legacy CLI or wrappers" "! command -v localstack && ! command -v awslocal && ! command -v tflocal && ! command -v cdklocal && ! command -v samlocal" +check "lstk uses the template config" "readlink ~/.config/lstk/config.toml | grep -E '\.devcontainer/lstk/config\.toml$'" +check "emulator is running" "lstk --non-interactive status" +check "image tag" "docker inspect localstack-aws --format '{{.Config.Image}}' | grep -x 'localstack/localstack-pro:latest'" +check "state on the /data volume" "docker inspect localstack-aws --format '{{range .Mounts}}{{.Source}}:{{.Destination}} {{end}}' | grep -w '/data:/var/lib/localstack'" +check "lstk aws (replaces awslocal)" "lstk aws s3 mb s3://lstk-smoke && lstk aws s3 ls | grep lstk-smoke" +check "aws CLI uses the localstack profile" "aws s3 ls | grep lstk-smoke" +check "lambda runs in the inner docker" "lambdaRoundTrip dind-smoke" +check "lstk stop" "lstk --non-interactive stop && ! docker ps --format '{{.Names}}' | grep -x localstack-aws" -# Report result reportResults diff --git a/test/localstack-dind/tools_no_startup.sh b/test/localstack-dind/tools_no_startup.sh deleted file mode 100644 index d75d766..0000000 --- a/test/localstack-dind/tools_no_startup.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Scenario specific tests -check "distro" lsb_release -c | grep "jammy" -check "awslocal" type awslocal -check "cdklocal" type cdklocal -check "pulumilocal" type pulumilocal -check "samlocal" type samlocal -check "tflocal" type tflocal -check "localstack stopped" localstack status; localstack status | grep stopped > /dev/null - -# Report result -reportResults diff --git a/test/localstack-dind/use_pro_and_pod.sh b/test/localstack-dind/use_pro_and_pod.sh deleted file mode 100644 index 5e31c12..0000000 --- a/test/localstack-dind/use_pro_and_pod.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Scenario specific tests -check "localstack-cli version" 'localstack --version | grep 3.5.0' -check "localstack image version" 'localstack status | grep "Docker image" | grep 3.5.0' -check "localstack is pro" "docker inspect localstack-main | jq -e '.[0].Config.Env | index(\"ACTIVATE_PRO=1\") != null'" - -localstack wait -t 30 -SCENARIO=$(basename -s .sh $0) -check "pod loaded resources" "awslocal s3api list-buckets | jq -e '.Buckets | any(.Name == \"devcontainer-test\")'" - -# Report result -reportResults diff --git a/test/localstack-dood/custom_host_iam_and_region.sh b/test/localstack-dood/custom_host_iam_and_region.sh new file mode 100755 index 0000000..773c59f --- /dev/null +++ b/test/localstack-dood/custom_host_iam_and_region.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +waitForLocalStack + +check "custom host" "curl -fs http://my-host.localstack.cloud:4566/_localstack/health" +check "lstk status over the custom host" "lstk --non-interactive status" +check "profile uses the custom host" "aws configure get endpoint_url --profile localstack | grep my-host.localstack.cloud:4566" +check "default region" "aws sqs create-queue --queue-name region-queue | grep eu-central-1" +check "IAM is enforced" "iamDenyRoundTrip devcontainer-test" + +reportResults diff --git a/test/localstack-dood/custom_region_with_iam_enforce.sh b/test/localstack-dood/custom_region_with_iam_enforce.sh deleted file mode 100644 index a6bfc70..0000000 --- a/test/localstack-dood/custom_region_with_iam_enforce.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -localstack wait -t 30 - -# Scenario specific tests -check "localstack status" localstack status -check "default region" awslocal sqs create-queue --queue-name test-queue | grep eu-central-1 - -awslocal iam create-user --user-name test -awslocal iam put-user-policy --user-name test --policy-name restrict-queue-list --policy-document "$(cat < /dev/null -localstack wait -t 30 -check "debug enabled" "curl -s http://localhost.localstack.cloud:4566/_localstack/diagnose; echo" -check "log level is trace" "curl -s http://localhost.localstack.cloud:4566/_localstack/diagnose | jq -r '.config.LS_LOG'" - -# Report result -reportResults diff --git a/test/localstack-dood/persistence_pinned_version_on_jammy.sh b/test/localstack-dood/persistence_pinned_version_on_jammy.sh new file mode 100755 index 0000000..9716fc1 --- /dev/null +++ b/test/localstack-dood/persistence_pinned_version_on_jammy.sh @@ -0,0 +1,14 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +waitForLocalStack + +check "distro" "grep VERSION_CODENAME=jammy /etc/os-release" +check "pinned image tag" "docker inspect localstack-main --format '{{.Config.Image}}' | grep -x 'localstack/localstack-pro:2026.10'" +check "create bucket" "aws s3 mb s3://persisted-bucket" +check "restart the localstack service" "docker restart localstack-main && waitForLocalStack" +check "bucket survives restart" "aws s3 ls | grep persisted-bucket" +check "state written to the volume folder" "test -n \"\$(ls -A ../.devcontainer/volume)\"" + +reportResults diff --git a/test/localstack-dood/scenarios.json b/test/localstack-dood/scenarios.json index aad9150..94b067d 100644 --- a/test/localstack-dood/scenarios.json +++ b/test/localstack-dood/scenarios.json @@ -1,47 +1,22 @@ { - "tools": { - "features": { - "ghcr.io/devcontainers/features/node:1": {} - }, + "custom_host_iam_and_region": { + "host": "my-host.localstack.cloud:4566", + "defaultRegion": "eu-central-1", + "enforceIam": true + }, + "persistence_pinned_version_on_jammy": { "imageVariant": "jammy", - "awslocal": true, - "cdklocal": true, - "pulumilocal": true, - "samlocal": true, - "tflocal": true, - "startup": false + "version": "2026.10", + "persistence": true, + "volumePath": "./volume" }, - "debug_mode_on_bookworm": { + "terraform_pod_and_debug_on_bookworm": { "imageVariant": "bookworm", - "debug": true, - "logLevel": "trace" - }, - "use_pro_and_pod": { - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} - }, - "usePro": true, - "awslocal": true, - "loadPods": "devcontainer-use_pro_and_pod", - "version": "3.5.0" - }, - "custom_volume_and_host_with_3_3_0": { - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} - }, - "usePro": true, - "awslocal": true, - "version": "3.3.0", - "volumePath": "./volume", - "host": "my-host.localstack.cloud:4566" - }, - "custom_region_with_iam_enforce": { - "awslocal": true, "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {} + "ghcr.io/devcontainers/features/terraform:1": {} }, - "defaultRegion": "eu-central-1", - "enforceIam": true, - "usePro": true + "loadPods": "devcontainer-template-ci-dood", + "debug": true, + "logLevel": "trace" } -} \ No newline at end of file +} diff --git a/test/localstack-dood/terraform_pod_and_debug_on_bookworm.sh b/test/localstack-dood/terraform_pod_and_debug_on_bookworm.sh new file mode 100755 index 0000000..cab4948 --- /dev/null +++ b/test/localstack-dood/terraform_pod_and_debug_on_bookworm.sh @@ -0,0 +1,17 @@ +#!/bin/bash +cd $(dirname "$0") +source test-utils.sh + +POD=devcontainer-template-ci-dood + +waitForLocalStack + +check "distro" "grep VERSION_CODENAME=bookworm /etc/os-release" +check "log level is trace" "curl -s ${LOCALSTACK_URL}/_localstack/diagnose | jq -r '.config.LS_LOG' | grep -x trace" +check "lstk terraform over the endpoint (replaces tflocal)" "terraformRoundTrip dood-tf-bucket" +check "seed and save pod" "aws s3 mb s3://pod-bucket && lstk --non-interactive snapshot save pod:${POD}" +check "restart the localstack service" "docker restart localstack-main && waitForLocalStack" +check "pod auto-loaded on start" "timeout 60 bash -c 'until aws s3 ls | grep -q pod-bucket; do sleep 2; done'" +lstk --non-interactive snapshot remove pod:${POD} --force + +reportResults diff --git a/test/localstack-dood/test.sh b/test/localstack-dood/test.sh old mode 100644 new mode 100755 index 969aa4d..4e9fcaf --- a/test/localstack-dood/test.sh +++ b/test/localstack-dood/test.sh @@ -2,10 +2,18 @@ cd $(dirname "$0") source test-utils.sh -# Template specific tests -check "distro" lsb_release -c | grep "jammy" -check "localstack status" localstack status -check "localstack stops" localstack stop +waitForLocalStack + +check "distro" "grep VERSION_CODENAME=noble /etc/os-release" +check "lstk installed" lstk --version +check "no legacy CLI or wrappers" "! command -v localstack && ! command -v awslocal && ! command -v tflocal && ! command -v cdklocal && ! command -v samlocal" +check "lstk targets the compose service" "test \"\${LSTK_ENDPOINT_URL}\" = http://localhost.localstack.cloud:4566" +check "lstk status over the endpoint" "lstk --non-interactive status" +check "lstk start is refused" "! lstk --non-interactive start" +check "image tag" "docker inspect localstack-main --format '{{.Config.Image}}' | grep -x 'localstack/localstack-pro:latest'" +check "localstack.cloud resolves to the service" "getent ahostsv4 localhost.localstack.cloud | grep -w 10.0.2.20" +check "lstk aws (replaces awslocal)" "lstk aws s3 mb s3://lstk-smoke && lstk aws s3 ls | grep lstk-smoke" +check "aws CLI uses the localstack profile" "aws s3 ls | grep lstk-smoke" +check "lambda reaches LocalStack over the shared network" "lambdaRoundTrip dood-smoke" -# Report result reportResults diff --git a/test/localstack-dood/tools.sh b/test/localstack-dood/tools.sh deleted file mode 100644 index 77505a4..0000000 --- a/test/localstack-dood/tools.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Scenario specific tests -check "distro" lsb_release -c | grep "jammy" -check "awslocal" type awslocal -check "cdklocal" type cdklocal -check "pulumilocal" type pulumilocal -check "samlocal" type samlocal -check "tflocal" type tflocal - -# Report result -reportResults diff --git a/test/localstack-dood/use_pro_and_pod.sh b/test/localstack-dood/use_pro_and_pod.sh deleted file mode 100644 index f99eafd..0000000 --- a/test/localstack-dood/use_pro_and_pod.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Scenario specific tests -check "localstack-cli version" 'localstack --version | grep 3.5.0' -check "localstack image version" 'localstack status | grep "Docker image" | grep 3.5.0' -check "localstack is pro" "docker inspect localstack-main | jq -e '.[0].Config.Env | index(\"ACTIVATE_PRO=true\") != null'" - -localstack wait -t 30 -SCENARIO=$(basename -s .sh $0) -check "pod loaded resources" "awslocal s3api list-buckets | jq -e '.Buckets | any(.Name == \"devcontainer-test\")'" - -# Report result -reportResults diff --git a/test/test-utils/test-utils.sh b/test/test-utils/test-utils.sh index 381e5d5..6cdd839 100644 --- a/test/test-utils/test-utils.sh +++ b/test/test-utils/test-utils.sh @@ -26,8 +26,128 @@ reportResults() { if [ ${#FAILED[@]} -ne 0 ]; then echoStderr -e "\n💥 Failed tests: ${FAILED[@]}" exit 1 - else + else echo -e "\n💯 All passed!" exit 0 fi } + +# --- LocalStack helpers shared by both templates --- + +LOCALSTACK_URL="${LSTK_ENDPOINT_URL:-http://localhost.localstack.cloud:4566}" + +waitForLocalStack() { + timeout "${1:-180}" bash -c "until curl -fs ${LOCALSTACK_URL}/_localstack/health > /dev/null; do sleep 2; done" +} + +# Creates a Python Lambda function, invokes it and checks the response. +# Exercises the Docker wiring LocalStack needs to run function containers. +lambdaRoundTrip() { + local name="$1" dir + dir=$(mktemp -d) + cat > "${dir}/index.py" <<'PY' +def handler(event, context): + return {"message": "hello from " + event.get("name", "lambda")} +PY + (cd "${dir}" && zip -q function.zip index.py) || return 1 + aws lambda create-function --function-name "${name}" --runtime python3.12 --handler index.handler \ + --role arn:aws:iam::000000000000:role/lambda-role --zip-file "fileb://${dir}/function.zip" > /dev/null || return 1 + aws lambda wait function-active-v2 --function-name "${name}" || return 1 + aws lambda invoke --function-name "${name}" --cli-binary-format raw-in-base64-out \ + --payload '{"name": "devcontainer"}' "${dir}/out.json" > /dev/null || return 1 + cat "${dir}/out.json"; echo + grep -q "hello from devcontainer" "${dir}/out.json" +} + +# Deploys an S3 bucket with `lstk terraform` (replaces tflocal). +terraformRoundTrip() { + local bucket="$1" dir + dir=$(mktemp -d) + cat > "${dir}/main.tf" < /dev/null && + lstk terraform apply -auto-approve -input=false && + aws s3api head-bucket --bucket "${bucket}" && + lstk tf destroy -auto-approve -input=false > /dev/null + ) +} + +# Deploys an SQS queue with `lstk cdk` (replaces cdklocal). +cdkRoundTrip() { + local stack="$1" dir + dir=$(mktemp -d) + cat > "${dir}/app.js" <<'EOF' +const cdk = require("aws-cdk-lib"); +const sqs = require("aws-cdk-lib/aws-sqs"); +const app = new cdk.App(); +const stack = new cdk.Stack(app, process.env.STACK_NAME); +new sqs.Queue(stack, "Queue", { queueName: process.env.STACK_NAME + "-queue" }); +EOF + echo '{"app": "node app.js"}' > "${dir}/cdk.json" + ( + cd "${dir}" && + npm init -y > /dev/null && + npm install --no-audit --no-fund aws-cdk-lib constructs > /dev/null && + export STACK_NAME="${stack}" && + lstk cdk bootstrap && + lstk cdk deploy --require-approval never && + aws sqs get-queue-url --queue-name "${stack}-queue" + ) +} + +# Deploys a Lambda function with `lstk sam` (replaces samlocal). +samRoundTrip() { + local stack="$1" dir + dir=$(mktemp -d) + mkdir -p "${dir}/src" + cat > "${dir}/src/index.py" <<'PY' +def handler(event, context): + return {"message": "hello from sam"} +PY + cat > "${dir}/template.yaml" <<'EOF' +AWSTemplateFormatVersion: "2010-09-09" +Transform: AWS::Serverless-2016-10-31 +Resources: + HelloFunction: + Type: AWS::Serverless::Function + Properties: + Runtime: python3.12 + Handler: index.handler + CodeUri: src/ +Outputs: + FunctionName: + Value: !Ref HelloFunction +EOF + ( + cd "${dir}" && + lstk sam deploy --stack-name "${stack}" --resolve-s3 --capabilities CAPABILITY_IAM \ + --no-confirm-changeset --no-fail-on-empty-changeset && + fn=$(aws cloudformation describe-stacks --stack-name "${stack}" \ + --query "Stacks[0].Outputs[?OutputKey=='FunctionName'].OutputValue" --output text) && + aws lambda wait function-active-v2 --function-name "${fn}" && + aws lambda invoke --function-name "${fn}" out.json > /dev/null && + grep -q "hello from sam" out.json + ) +} + +# Checks that a principal limited by an IAM deny policy is refused. +iamDenyRoundTrip() { + local user="$1" creds + aws iam create-user --user-name "${user}" > /dev/null || return 1 + aws iam put-user-policy --user-name "${user}" --policy-name deny-list-queues --policy-document '{ + "Version": "2012-10-17", + "Statement": [{"Effect": "Deny", "Action": "sqs:ListQueues", "Resource": "*"}] + }' || return 1 + creds=$(aws iam create-access-key --user-name "${user}") || return 1 + local out + out=$(AWS_ACCESS_KEY_ID=$(jq -r .AccessKey.AccessKeyId <<< "${creds}") \ + AWS_SECRET_ACCESS_KEY=$(jq -r .AccessKey.SecretAccessKey <<< "${creds}") \ + aws sqs list-queues 2>&1) + echo "${out}" + grep -q -E 'AccessDenied|not authorized' <<< "${out}" +} From dca03fb349e34daed64085ae78325b8469e92067 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Mon, 23 Nov 2026 18:02:03 +0530 Subject: [PATCH 2/4] ci: allow testing against an unreleased Feature Add a feature-ref input to the test workflow and both test actions. When set, CI checks out localstack/devcontainer-feature at that ref and builds the Templates with it through LOCAL_FEATURE_DIR. --- .github/actions/scenario-test/action.yaml | 14 ++++++++++++++ .github/actions/smoke-test/action.yaml | 16 +++++++++++++++- .github/workflows/test-pr.yaml | 7 +++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.github/actions/scenario-test/action.yaml b/.github/actions/scenario-test/action.yaml index 26978f0..d23e0e7 100644 --- a/.github/actions/scenario-test/action.yaml +++ b/.github/actions/scenario-test/action.yaml @@ -3,6 +3,10 @@ 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 @@ -11,7 +15,17 @@ runs: id: checkout_release 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 }} diff --git a/.github/actions/smoke-test/action.yaml b/.github/actions/smoke-test/action.yaml index fa9fbc8..c06ba07 100644 --- a/.github/actions/smoke-test/action.yaml +++ b/.github/actions/smoke-test/action.yaml @@ -3,6 +3,10 @@ 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 @@ -11,12 +15,22 @@ runs: id: checkout_release 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 }} \ No newline at end of file + run: ${{ github.action_path }}/test.sh ${{ inputs.template }} diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 2b61472..5b940cc 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -15,6 +15,11 @@ on: - .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: @@ -58,6 +63,7 @@ jobs: uses: ./.github/actions/smoke-test with: template: "${{ matrix.templates }}" + feature-ref: ${{ inputs.feature-ref }} scenario-test: needs: [detect-changes] @@ -76,3 +82,4 @@ jobs: uses: ./.github/actions/scenario-test with: template: "${{ matrix.templates }}" + feature-ref: ${{ inputs.feature-ref }} From e22cb13076d1452e0eb3ded5fd565453688e0922 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Mon, 23 Nov 2026 18:02:10 +0530 Subject: [PATCH 3/4] ci: TEMP test against devcontainer-feature#9 branch (revert before merge) --- .github/workflows/test-pr.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 5b940cc..bdae883 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -63,7 +63,7 @@ jobs: uses: ./.github/actions/smoke-test with: template: "${{ matrix.templates }}" - feature-ref: ${{ inputs.feature-ref }} + feature-ref: ${{ inputs.feature-ref || 'migrate-to-lstk' }} scenario-test: needs: [detect-changes] @@ -82,4 +82,4 @@ jobs: uses: ./.github/actions/scenario-test with: template: "${{ matrix.templates }}" - feature-ref: ${{ inputs.feature-ref }} + feature-ref: ${{ inputs.feature-ref || 'migrate-to-lstk' }} From 6d935dff4a566f984f2bb0fabadca98f379c44d0 Mon Sep 17 00:00:00 2001 From: Bart Date: Mon, 23 Nov 2026 16:27:58 +0100 Subject: [PATCH 4/4] ci: print LocalStack container logs before cleanup Startup failures of the DooD LocalStack service, such as a rejected auth token, only surfaced as an unreachable endpoint. Co-Authored-By: Claude Opus 5.5 --- .github/actions/cleanup.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/actions/cleanup.sh b/.github/actions/cleanup.sh index 91c74a7..030c36d 100755 --- a/.github/actions/cleanup.sh +++ b/.github/actions/cleanup.sh @@ -6,6 +6,13 @@ 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