Files
computer-playbook/scripts/tests/deploy/local/exec/run.sh
T
kevinveenbirkenbachandClaude Opus 4.7 5b8cb71884 feat(scripts+make): add make run wrapper for nested docker run inside the host container
Inner-loop iteration on a deployed stack often needs a one-off sidecar
container against the same docker daemon the stack lives on — typical
cases are rerunning a Playwright project with a patched .env, retrying
an arbitrary CLI image against an app container, or smoke-checking a
release image without going through Ansible. Without a wrapper the
caller has to spell out `docker exec <host-container> docker run --rm
<flags...> <image> <cmd>` by hand, which is verbose enough that agents
tend to fall back to redeploying instead of validating in-place.

Add `make run IMAGE=<ref> [CMD=...] [RUN_FLAGS=...]` plus the underlying
`scripts/tests/deploy/local/exec/run.sh`. The script reuses
`scripts/meta/env/all.sh` to resolve the host container name (same SPOT
as `make exec`), forwards RUN_FLAGS verbatim, and only wraps CMD in
`sh -lc` so default-entrypoint images and shell one-liners both work.

Wire both iteration loops to mention the wrapper next to `make exec`:
the Role Loop's Inspect block gets a bullet pointing at it, and the
Playwright Spec Loop gains a short "Debugging in the nested docker
daemon" section that also reminds the agent to mirror any successful
hand-patch back into the role's playwright.env.j2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 15:37:12 +02:00

82 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Wrapper to run a one-off `docker run` INSIDE the infinito host container
# (which already provides nested Docker-in-Docker). Used for inner-loop
# debugging where you need to spin up a sidecar image (e.g. the Playwright
# runner) against the same docker daemon the deployed stack lives on,
# without re-running an Ansible playbook.
#
# Required env:
# IMAGE Image reference passed to `docker run` (e.g. alpine,
# mcr.microsoft.com/playwright:v1.59.1-noble)
#
# Optional env:
# CMD Command to execute inside the sidecar container.
# When omitted, the image's default entrypoint runs.
# RUN_FLAGS Extra flags forwarded verbatim to `docker run`
# (e.g. "--env-file /tmp/x.env -v /tmp/y:/y -w /e2e").
# INFINITO_DISTRO arch|debian|ubuntu|fedora|centos — selects which
# infinito host container we exec into.
# INFINITO_CONTAINER Optional explicit override of the host container name.
#
# Examples:
# IMAGE=alpine make run
# IMAGE=alpine CMD='env | grep PATH' make run
# IMAGE=mcr.microsoft.com/playwright:v1.59.1-noble \
# RUN_FLAGS='--env-file /tmp/test-e2e-playwright/web-app-friendica/.env \
# -v /tmp/test-e2e-playwright/web-app-friendica:/e2e -w /e2e' \
# CMD='npx playwright test --grep dashboard' \
# make run
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../../../" && pwd)"
usage() {
cat <<EOF
Usage:
IMAGE=<ref> [CMD='<shell>'] [RUN_FLAGS='<flags>'] ${0}
Examples:
IMAGE=alpine ${0}
IMAGE=alpine CMD='env' ${0}
IMAGE=mcr.microsoft.com/playwright:v1.59.1-noble \\
RUN_FLAGS='--env-file /tmp/.env -v /tmp/proj:/e2e -w /e2e' \\
CMD='npx playwright test' \\
${0}
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
: "${IMAGE:?IMAGE must be set (e.g. IMAGE=alpine)}"
cd "${REPO_ROOT}"
# shellcheck source=scripts/meta/env/all.sh
source "scripts/meta/env/all.sh"
: "${INFINITO_CONTAINER:?INFINITO_CONTAINER not set after sourcing scripts/meta/env/all.sh}"
# Build the nested `docker run` argv. Splitting RUN_FLAGS on whitespace is
# intentional — same UX as RUN_FLAGS in any other Make wrapper. Callers that
# need single args containing spaces should pass them via the image entry-
# point (-e VAR='spaced value' arrives intact because docker parses -e).
docker_run_argv=(docker run --rm)
if [[ -n "${RUN_FLAGS:-}" ]]; then
# shellcheck disable=SC2206
docker_run_argv+=(${RUN_FLAGS})
fi
docker_run_argv+=("${IMAGE}")
if [[ -n "${CMD:-}" ]]; then
docker_run_argv+=(sh -lc "${CMD}")
fi
exec_flags=(-i)
if [[ -t 0 && -t 1 ]]; then
exec_flags=(-it)
fi
exec docker exec "${exec_flags[@]}" "${INFINITO_CONTAINER}" "${docker_run_argv[@]}"