From 0253cfc676641918f551c428cef68248f891a183 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Fri, 24 Apr 2026 21:11:08 +0200 Subject: [PATCH] Copy edge E2E runner config in CI --- .github/workflows/tests.yml | 15 ++++++-- scripts/edge-gateway-e2e.mjs | 5 +++ scripts/test-gateway.mjs | 66 +++++++++++++++++++++++------------ scripts/test-gateway.test.mjs | 6 ++++ 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4220a7dc..bdfd285d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -222,16 +222,25 @@ jobs: run: | set -euo pipefail compose_project="${COMPOSE_PROJECT_NAME:-$(basename "$PWD")}" - docker run --rm \ + runner="edge-e2e-runner-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + docker rm -f "$runner" >/dev/null 2>&1 || true + trap 'docker rm -f "$runner" >/dev/null 2>&1 || true' EXIT + docker create \ + --name "$runner" \ --network "${compose_project}_default" \ -e COMPOSE_FILE="$COMPOSE_FILE" \ -e EDGE_GATEWAY_E2E_BASE_URL="http://caddy" \ -e EDGE_GATEWAY_E2E_COMPOSE_PROJECT="$compose_project" \ + -e EDGE_GATEWAY_E2E_COPY_CONFIG="true" \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v "$PWD:$PWD" \ - -w "$PWD" \ + -w /workspace \ node:22-alpine \ sh -lc "apk add --no-cache docker-cli docker-cli-compose >/dev/null && node scripts/edge-gateway-e2e.mjs" + docker cp . "$runner:/workspace" + docker start "$runner" >/dev/null + docker logs -f "$runner" + exit_code="$(docker wait "$runner")" + exit "$exit_code" - name: Tear down local stack if: always() diff --git a/scripts/edge-gateway-e2e.mjs b/scripts/edge-gateway-e2e.mjs index f656cdd5..2a923200 100644 --- a/scripts/edge-gateway-e2e.mjs +++ b/scripts/edge-gateway-e2e.mjs @@ -510,6 +510,10 @@ function closeSocket(socket) { socket.close(); } +function shouldCopyGatewayConfig() { + return /^(1|true|yes)$/i.test(String(process.env.EDGE_GATEWAY_E2E_COPY_CONFIG || "").trim()); +} + function collectMessages(rows) { return Array.isArray(rows) ? rows @@ -602,6 +606,7 @@ async function main() { "--heartbeat-seconds", "3", "--skip-compose-up", + ...(shouldCopyGatewayConfig() ? ["--copy-config"] : []), ], { cwd: rootDir, stdio: "inherit", diff --git a/scripts/test-gateway.mjs b/scripts/test-gateway.mjs index 55a8cd67..313e35d6 100644 --- a/scripts/test-gateway.mjs +++ b/scripts/test-gateway.mjs @@ -56,6 +56,7 @@ Options: --tail Log lines for the logs action. Default: 200 --skip-compose-up Do not start the local Docker Compose stack before start. --skip-build Do not rebuild the test gateway image before start. + --copy-config Copy generated config into the container instead of bind mounting it. `); } @@ -150,6 +151,7 @@ export function parseArgs(argv = process.argv.slice(2)) { tail: "200", skipComposeUp: false, skipBuild: false, + copyConfig: false, }; for (let index = 0; index < rest.length; index += 1) { @@ -204,6 +206,9 @@ export function parseArgs(argv = process.argv.slice(2)) { case "--skip-build": options.skipBuild = true; break; + case "--copy-config": + options.copyConfig = true; + break; case "--help": case "-h": options.help = true; @@ -361,35 +366,51 @@ async function startContainer({ containerName, hostname, configDir, + copyConfig, }) { const networkName = resolveComposeNetworkName(rootDir); const mountedConfigDir = toDockerMountPath(configDir); + const containerConfigPath = copyConfig + ? `/tmp/${DEFAULT_CONFIG_FILE_NAME}` + : `/config/${DEFAULT_CONFIG_FILE_NAME}`; + const createArgs = [ + copyConfig ? "create" : "run", + ...(copyConfig ? [] : ["-d"]), + "--name", + containerName, + "--hostname", + hostname, + "--restart", + "unless-stopped", + "--network", + networkName, + ...(copyConfig ? [] : ["-v", `${mountedConfigDir}:/config`]), + imageTag, + "--config", + containerConfigPath, + ]; await removeContainer(containerName); - await runCommand( - "docker", - [ - "run", - "-d", - "--name", - containerName, - "--hostname", - hostname, - "--restart", - "unless-stopped", - "--network", - networkName, - "-v", - `${mountedConfigDir}:/config`, - imageTag, - "--config", - `/config/${DEFAULT_CONFIG_FILE_NAME}`, - ], - { + await runCommand("docker", createArgs, { + cwd: rootDir, + stdio: "inherit", + }); + + if (copyConfig) { + await runCommand("docker", [ + "cp", + path.join(configDir, DEFAULT_CONFIG_FILE_NAME), + `${containerName}:${containerConfigPath}`, + ], { cwd: rootDir, stdio: "inherit", - } - ); + }); + + await runCommand("docker", ["start", containerName], { + cwd: rootDir, + stdio: "inherit", + }); + } } async function printStatus({ imageTag, configDir, containerName }) { @@ -469,6 +490,7 @@ async function main() { containerName: options.containerName, hostname: options.hostname, configDir, + copyConfig: options.copyConfig, }); process.stdout.write(`Test gateway container started. diff --git a/scripts/test-gateway.test.mjs b/scripts/test-gateway.test.mjs index fe59583b..1441a8f6 100644 --- a/scripts/test-gateway.test.mjs +++ b/scripts/test-gateway.test.mjs @@ -52,6 +52,12 @@ test("parseArgs accepts help without an explicit action", () => { assert.equal(options.help, true); }); +test("parseArgs accepts copy config mode", () => { + const options = parseArgs(["start", "--copy-config"]); + + assert.equal(options.copyConfig, true); +}); + test("buildGatewayConfig applies defaults for a dockerized gateway", () => { const config = buildGatewayConfig({});