Fail the image build when the Nexus token is missing
`docker compose build` without NEXUS_TOKEN produced a Nexus 401 forty seconds in, worded as a credentials problem when it was really an unset variable. The mount's `required=true` asserts the secret was *declared*, not that it holds anything, so an empty one sailed past it and npm sent an empty `_authToken`. The install moves to tools/docker-install-deps.sh, which checks the secret before touching the network and fails in under a second with the three ways to supply it. It is a file rather than inline shell because BuildKit echoes an inline command twice on failure and buries the message. Also ignore .env. It carries NEXUS_TOKEN, compose reads it at build time, and it was not gitignored — .env.example stays tracked. Nothing had been committed: the only prior commit predates all of this. Verified: empty token fails in 0.2s with the message; .env and the environment variable both build; the image carries no trace of the token and serves the full page. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -19,14 +19,12 @@ COPY package.json package-lock.json .npmrc ./
|
||||
|
||||
# `@pi/ui` comes from the private Nexus, so the install needs a token — passed
|
||||
# as a BuildKit secret rather than a build ARG, which would be readable forever
|
||||
# in the image history. The npmrc it lands in is written and removed inside one
|
||||
# layer, so it leaves no trace even in this discarded stage.
|
||||
# in the image history. The script checks the secret actually holds something
|
||||
# before spending four minutes finding out from Nexus.
|
||||
COPY tools/docker-install-deps.sh ./tools/
|
||||
|
||||
RUN --mount=type=secret,id=nexus_token,required=true \
|
||||
sh -eu -c '\
|
||||
printf "//nexus.pireon.dev/repository/npm-releases/:_authToken=%s\n" \
|
||||
"$(cat /run/secrets/nexus_token)" > /tmp/npmrc; \
|
||||
NPM_CONFIG_USERCONFIG=/tmp/npmrc npm ci --no-audit --no-fund; \
|
||||
rm -f /tmp/npmrc'
|
||||
sh tools/docker-install-deps.sh
|
||||
|
||||
COPY nx.json tsconfig.base.json eslint.config.mjs ./
|
||||
COPY landing ./landing
|
||||
|
||||
Reference in New Issue
Block a user