build: run the container through dotenvx with the encrypted .env.production
- image installs @dotenvx/dotenvx (pinned) and starts via 'dotenvx run -f .env.production --strict -- node server.js' - only DOTENV_PRIVATE_KEY_PRODUCTION is supplied at runtime; without it the container exits(1) (MISSING_PRIVATE_KEY) instead of booting with undecryptable credentials - .env.production copied with --chown=node:node (the source mode is 600) - .dockerignore excludes .env/.env.local/.env.keys so local envs and the private keys never enter the build context
This commit is contained in:
+12
-2
@@ -3,19 +3,29 @@
|
||||
# on the field laptop (the wizard reaches it at http://127.0.0.1:9000 from the
|
||||
# browser, so the container location does not matter).
|
||||
#
|
||||
# The encrypted .env.production is baked in; the private key is supplied at
|
||||
# runtime and never stored in the image:
|
||||
#
|
||||
# docker build -t yreka-tools .
|
||||
# docker run -d -p 4173:4173 --name yreka-tools yreka-tools
|
||||
# docker run -d -p 4173:4173 --name yreka-tools \
|
||||
# --env DOTENV_PRIVATE_KEY_PRODUCTION="$(grep -oP '^DOTENV_PRIVATE_KEY_PRODUCTION=\K.*' .env.keys)" \
|
||||
# yreka-tools
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
|
||||
RUN npm install -g @dotenvx/dotenvx@1.51.4
|
||||
|
||||
COPY tools/package.json tools/package-lock.json ./
|
||||
RUN npm ci --omit=dev && npm cache clean --force
|
||||
|
||||
COPY tools/server.js tools/yrka-auth.js tools/permit.js tools/cropper.js ./
|
||||
COPY tools/public ./public
|
||||
COPY --chown=node:node .env.production ./
|
||||
|
||||
USER node
|
||||
EXPOSE 4173
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s \
|
||||
CMD wget -qO- http://127.0.0.1:4173/ >/dev/null || exit 1
|
||||
CMD ["node", "server.js"]
|
||||
# --strict: fail fast when the private key is missing or decryption fails,
|
||||
# instead of starting with unusable credentials.
|
||||
CMD ["dotenvx", "run", "-f", ".env.production", "--strict", "--", "node", "server.js"]
|
||||
|
||||
Reference in New Issue
Block a user