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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ A Template can be used in a new or existing project, and a [supporting tool](htt
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.

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 install [lstk](https://github.com/localstack/lstk), the LocalStack CLI. Besides managing LocalStack, lstk proxies `aws`, `terraform`, `cdk`, `sam` and `az` commands to LocalStack (e.g. `lstk aws s3 ls`). The wrapped tools themselves need to be added separately, e.g. via the `ghcr.io/devcontainers/features/aws-cli` Feature.

### 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`).
Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data.

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.
LocalStack in this variation is started with `lstk start` after the DevContainer is created and is controlled with lstk (`lstk status`, `lstk stop`, `lstk logs`, ...).
The image version and the LocalStack configuration live in `.devcontainer/lstk.toml`, which is linked as the lstk config (`~/.config/lstk/config.toml`); add further LocalStack variables to its `[env.devcontainer]` section.
For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/).

#### Use LocalStack Pro
#### Auth Token

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.
An Auth Token is required to start LocalStack. Set the `LOCALSTACK_AUTH_TOKEN` environment variable on your host system, it will be automatically picked up by the Template.
You can find your Auth Token in the [LocalStack Web Application](https://app.localstack.cloud/workspace/auth-token).

### LocalStack - Docker-outside-of-Docker

Expand All @@ -45,13 +46,14 @@ 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 this Template version LocalStack is managed by Docker Compose, lstk only talks to it via `AWS_ENDPOINT_URL` (set in `.env`). Lifecycle commands such as `lstk start` and `lstk stop` are therefore not available.
>
> In case you've made this mistake by accident, try running `docker compose -f <DEV_CONTAINER_CONFIG_LOCATION>/docker-compose.yml up -d localstack` or rebuild the container.
> In case the LocalStack container is not running, try running `docker compose -f <DEV_CONTAINER_CONFIG_LOCATION>/docker-compose.yml up -d localstack` or rebuild the container.

#### Use LocalStack Pro
#### Auth Token

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.
An Auth Token is required to start LocalStack. Set the `LOCALSTACK_AUTH_TOKEN` environment variable on your host system, it will be automatically picked up by the Template via the `.env` file.
You can find your Auth Token in the [LocalStack Web Application](https://app.localstack.cloud/workspace/auth-token).

## Repo and Template Structure

Expand All @@ -63,14 +65,17 @@ This repository contains a _collection_ of two Templates - `localstack-dind` and
│ │ ├── devcontainer-template.json
│ │ ├── inputs.json
│ │ └──| .devcontainer
│ │ └── devcontainer.json
│ │ ├── devcontainer.json
│ │ ├── install-lstk.sh
│ │ └── lstk.toml
│ ├── localstack-dood
│ │ ├── devcontainer-template.json
│ │ └──| .devcontainer
│ │ ├── .env
│ │ ├── devcontainer.json
│ │ ├── docker-compose.yaml
│ │ └── Dockerfile
│ │ ├── Dockerfile
│ │ └── install-lstk.sh
| ├── ...
│ │ ├── devcontainer-template.json
│ │ └──| .devcontainer
Expand Down
41 changes: 14 additions & 27 deletions src/localstack-dind/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,33 @@
"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 (required to start LocalStack): https://docs.localstack.cloud/aws/getting-started/auth-token/
"LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}", // required, not processed via template due to security reasons
"AWS_REGION": "${templateOption:defaultRegion}",
"AWS_DEFAULT_REGION": "${templateOption:defaultRegion}",
"IMAGE_NAME": "localstack/localstack-pro:${templateOption:version}",
"LOCALSTACK_VOLUME_DIR": "/data"
"AWS_DEFAULT_REGION": "${templateOption:defaultRegion}"
// LocalStack itself is configured in .devcontainer/lstk.toml
},

// 👇 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:2": {}
},

// 👇 Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "type localstack; ${templateOption:startup} && localstack start -d || true",
// 👇 Install lstk, the LocalStack CLI: https://github.com/localstack/lstk
// lstk also proxies aws, terraform, cdk, sam and az commands to LocalStack. The wrapped tools are not installed,
// if needed add features manually, e.g. ghcr.io/devcontainers/features/aws-cli, ghcr.io/devcontainers/features/terraform
"onCreateCommand": "bash .devcontainer/install-lstk.sh .devcontainer/lstk.toml",

// 👇 Start LocalStack once the Docker daemon (started in the background by the docker-in-docker feature) is ready
"postCreateCommand": "if ${templateOption:startup}; then timeout 120 sh -c 'until docker info > /dev/null 2>&1; do sleep 1; done' && lstk --non-interactive start --timeout 3m; fi",
"mounts": [
{
// to persist build data and images
"source": "dind-var-lib-docker",
"target": "/var/lib/docker",
"type": "volume"
},
{
},
{
"source": "${templateOption:volumePath}",
"target": "/data",
"type": "bind",
Expand Down
42 changes: 42 additions & 0 deletions src/localstack-dind/.devcontainer/install-lstk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Installs lstk, the LocalStack CLI: https://github.com/localstack/lstk
# Usage: install-lstk.sh [config.toml]
# config.toml optional lstk config, linked to ~/.config/lstk/config.toml so every lstk command uses it
# Set LSTK_VERSION (e.g. 1.5.0) to pin a release, defaults to the latest one.
set -euo pipefail

CONFIG_FILE="${1:-}"
VERSION="${LSTK_VERSION:-latest}"
if [ "$VERSION" = "latest" ]; then
VERSION=$(curl -fsSLI -o /dev/null -w '%{url_effective}' https://github.com/localstack/lstk/releases/latest)
VERSION="${VERSION##*/}"
fi
VERSION="${VERSION#v}"

case "$(uname -m)" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac

TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT

curl -fsSL "https://github.com/localstack/lstk/releases/download/v${VERSION}/lstk_${VERSION}_linux_${ARCH}.tar.gz" \
| tar -xz -C "$TMP_DIR"

SUDO=""
[ "$(id -u)" -ne 0 ] && SUDO="sudo"
# Keep the whole archive together: lstk finds its bundled extensions next to the
# symlink-resolved binary.
$SUDO rm -rf /usr/local/lib/lstk
$SUDO mkdir -p /usr/local/lib/lstk
$SUDO cp -R "$TMP_DIR"/. /usr/local/lib/lstk/
$SUDO ln -sf /usr/local/lib/lstk/lstk /usr/local/bin/lstk

if [ -n "$CONFIG_FILE" ]; then
mkdir -p "$HOME/.config/lstk"
ln -sf "$(realpath "$CONFIG_FILE")" "$HOME/.config/lstk/config.toml"
fi

lstk --version
18 changes: 18 additions & 0 deletions src/localstack-dind/.devcontainer/lstk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# lstk configuration, linked to ~/.config/lstk/config.toml on container creation.
# Reference: https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/configuration/
[[containers]]
type = "aws"
tag = "${templateOption:version}"
port = "4566"
container_name = "localstack-main"
# Bind mounted from the host (see "mounts" in devcontainer.json)
volume = "/data"
env = ["devcontainer"]

# LocalStack configuration passed to the container: https://docs.localstack.cloud/references/configuration/
[env.devcontainer]
DEBUG = "${templateOption:debug}"
LS_LOG = "${templateOption:logLevel}"
PERSISTENCE = "${templateOption:persistence}"
ENFORCE_IAM = "${templateOption:enforceIam}"
AUTO_LOAD_POD = "${templateOption:loadPods}"
13 changes: 7 additions & 6 deletions src/localstack-dind/NOTES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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`).
Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data.

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.
The Template installs [lstk](https://github.com/localstack/lstk), the LocalStack CLI. Besides managing LocalStack, lstk proxies `aws`, `terraform`, `cdk`, `sam` and `az` commands to LocalStack (e.g. `lstk aws s3 ls`). The wrapped tools themselves need to be added separately, e.g. via the `ghcr.io/devcontainers/features/aws-cli` Feature.

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.
LocalStack in this variation is started with `lstk start` after the DevContainer is created and is controlled with lstk (`lstk status`, `lstk stop`, `lstk logs`, ...).
The image version and the LocalStack configuration live in `.devcontainer/lstk.toml`, which is linked as the lstk config (`~/.config/lstk/config.toml`); add further LocalStack variables to its `[env.devcontainer]` section.
For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/).

## Use LocalStack Pro
## Auth Token

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.
An Auth Token is required to start LocalStack. Set the `LOCALSTACK_AUTH_TOKEN` environment variable on your host system, it will be automatically picked up by the Template.
You can find your Auth Token in the [LocalStack Web Application](https://app.localstack.cloud/workspace/auth-token).
33 changes: 14 additions & 19 deletions src/localstack-dind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@ A template to manage LocalStack in DinD via CLI
| 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 |
| debug | Enable LocalStack debugging: | boolean | false |
| persistence | Enable persistence in LocalStack: | boolean | false |
| version | LocalStack image version: | string | latest |
| loadPods | Load Cloud Pods at start-up (comma-separated list): | string | |
| volumePath | LocalStack volume location on the host (currently only local (bind) mounts recommended): | string | ./.volume |
| enforceIam | Enforce IAM: | boolean | false |
| defaultRegion | Default AWS region: | 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`).
Additionally the DevContainer bind mounts a folder from the host system as `/data`, which will be used to store LocalStack data.

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.
The Template installs [lstk](https://github.com/localstack/lstk), the LocalStack CLI. Besides managing LocalStack, lstk proxies `aws`, `terraform`, `cdk`, `sam` and `az` commands to LocalStack (e.g. `lstk aws s3 ls`). The wrapped tools themselves need to be added separately, e.g. via the `ghcr.io/devcontainers/features/aws-cli` Feature.

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.
LocalStack in this variation is started with `lstk start` after the DevContainer is created and is controlled with lstk (`lstk status`, `lstk stop`, `lstk logs`, ...).
The image version and the LocalStack configuration live in `.devcontainer/lstk.toml`, which is linked as the lstk config (`~/.config/lstk/config.toml`); add further LocalStack variables to its `[env.devcontainer]` section.
For further LocalStack configuration options please consult our [official documentation](https://docs.localstack.cloud/references/configuration/).

## Use LocalStack Pro
## Auth Token

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.
An Auth Token is required to start LocalStack. Set the `LOCALSTACK_AUTH_TOKEN` environment variable on your host system, it will be automatically picked up by the Template.
You can find your Auth Token in the [LocalStack Web Application](https://app.localstack.cloud/workspace/auth-token).

---

Expand Down
Loading
Loading