diff --git a/scripts/artifact-publish-bun-runtime.test.mjs b/scripts/artifact-publish-bun-runtime.test.mjs index 6fb24760..196e9dd1 100644 --- a/scripts/artifact-publish-bun-runtime.test.mjs +++ b/scripts/artifact-publish-bun-runtime.test.mjs @@ -12,3 +12,13 @@ test("bun-command artifact Dockerfile installs native Bun binary without npm pos assert.match(source, /hwlab-artifact-runtime-check-failed:\$1/u); assert.match(source, /fail bun-version/u); }); + +test("env-reuse Dockerfile carries git and stable Bun path for mirror checkout", async () => { + const source = await readFile("scripts/artifact-publish.mjs", "utf8"); + assert.ok(source.includes("apt-get install -y --no-install-recommends ca-certificates git")); + assert.ok(source.includes('ln -sf \\"/opt/hwlab-env/$bun_bin\\" /usr/local/bin/bun')); + assert.ok(source.includes("test -x /usr/local/bin/bun")); + assert.ok(source.includes("/usr/local/bin/bun --version >/tmp/hwlab-env-bun-version.txt")); + assert.ok(source.includes("ENV PATH=/usr/local/bin:$PATH")); + assert.ok(source.includes('CMD [\\"/usr/local/bin/bun\\", \\"/usr/local/bin/hwlab-env-reuse-launcher.ts\\"]')); +}); diff --git a/scripts/artifact-publish.mjs b/scripts/artifact-publish.mjs index 6b108687..65288bb1 100644 --- a/scripts/artifact-publish.mjs +++ b/scripts/artifact-publish.mjs @@ -1300,20 +1300,23 @@ function dockerfile(baseImage, port, labels = []) { } function envReuseDockerfile(baseImage, labels = []) { - const dependencyScript = "set -eu; if [ -f package-lock.json ]; then npm ci --omit=dev --include=optional --ignore-scripts; else npm install --omit=dev --include=optional --ignore-scripts; fi; if ! command -v bun >/dev/null 2>&1; then bun_pkg=\"\"; case \"$(uname -m)\" in x86_64|amd64) bun_pkg=\"@oven/bun-linux-x64@1.3.13\" ;; aarch64|arm64) bun_pkg=\"@oven/bun-linux-aarch64@1.3.13\" ;; *) echo \"unsupported bun architecture: $(uname -m)\" >&2; false ;; esac; npm install --no-save --omit=dev --include=optional --ignore-scripts \"$bun_pkg\"; test -x \"node_modules/${bun_pkg%@*}/bin/bun\"; ln -sf \"/opt/hwlab-env/node_modules/${bun_pkg%@*}/bin/bun\" /usr/local/bin/bun; fi"; - const readinessScript = "set -eu; command -v node >/dev/null; command -v npm >/dev/null; command -v git >/dev/null; command -v sh >/dev/null; command -v bun >/dev/null; test -d /opt/hwlab-env/node_modules"; + const osPackageScript = "set -eu; apt-get update; apt-get install -y --no-install-recommends ca-certificates git; rm -rf /var/lib/apt/lists/*"; + const dependencyScript = "set -eu; if [ -f package-lock.json ]; then npm ci --omit=dev --include=optional --ignore-scripts; else npm install --omit=dev --include=optional --ignore-scripts; fi; if command -v bun >/dev/null 2>&1; then bun_path=\"$(command -v bun)\"; if [ \"$bun_path\" != \"/usr/local/bin/bun\" ]; then ln -sf \"$bun_path\" /usr/local/bin/bun; fi; fi; if [ ! -x /usr/local/bin/bun ]; then bun_pkg=\"\"; case \"$(uname -m)\" in x86_64|amd64) bun_pkg=\"@oven/bun-linux-x64@1.3.13\" ;; aarch64|arm64) bun_pkg=\"@oven/bun-linux-aarch64@1.3.13\" ;; *) echo \"unsupported bun architecture: $(uname -m)\" >&2; false ;; esac; npm install --no-save --omit=dev --include=optional --ignore-scripts \"$bun_pkg\"; bun_bin=\"node_modules/${bun_pkg%@*}/bin/bun\"; test -x \"$bun_bin\"; ln -sf \"/opt/hwlab-env/$bun_bin\" /usr/local/bin/bun; fi"; + const readinessScript = "set -eu; command -v node >/dev/null; command -v npm >/dev/null; command -v git >/dev/null; command -v sh >/dev/null; test -d /opt/hwlab-env/node_modules; test -x /usr/local/bin/bun; /usr/local/bin/bun --version >/tmp/hwlab-env-bun-version.txt"; return [ `FROM ${baseImage}`, "WORKDIR /opt/hwlab-env", ...labels.map(([name, value]) => `LABEL ${name}=${dockerfileQuote(value)}`), "COPY package.json ./package.json", "COPY package-lock.json* ./", + `RUN ${osPackageScript}`, `RUN ${dependencyScript}`, "COPY deploy/runtime/launcher/hwlab-env-reuse-launcher.ts /usr/local/bin/hwlab-env-reuse-launcher.ts", `RUN ${readinessScript}`, "ENV HWLAB_RUNTIME_MODE=env-reuse-git-mirror-checkout", "ENV HWLAB_RUNTIME_NODE_MODULES=/opt/hwlab-env/node_modules", - "CMD [\"bun\", \"/usr/local/bin/hwlab-env-reuse-launcher.ts\"]", + "ENV PATH=/usr/local/bin:$PATH", + "CMD [\"/usr/local/bin/bun\", \"/usr/local/bin/hwlab-env-reuse-launcher.ts\"]", "" ].join("\n"); }