From 1f82345a2f8e9055404a1f0f9370b81327941d0a Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 30 Oct 2026 21:38:49 +0100 Subject: [PATCH] Keep .env and local build artifacts out of the Docker image Without a .dockerignore, COPY . . baked the .env file (including the webhook secret) into the image and overwrote the container's node_modules with the host's. Pass public build-time values as build args and provide the rest at runtime through env_file. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 13 +++++++++++++ Dockerfile | 9 ++++++++- docker-compose.yml | 10 +++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..451e761 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Installed and built inside the image +node_modules +.next + +# Secrets are passed in by docker compose, never baked into the image +.env* + +.git +.github +Dockerfile +docker-compose.yml +*.md +npm-debug.log* diff --git a/Dockerfile b/Dockerfile index 5c48030..8d967c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,15 @@ RUN npm install COPY . . +# NEXT_PUBLIC_* values are inlined at build time, and pages are prerendered +# with data from Sanity during the build +ARG NEXT_PUBLIC_SANITY_PROJECT_ID +ARG NEXT_PUBLIC_SANITY_DATASET +ARG NEXT_PUBLIC_UMAMI_SRC +ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID + RUN npm run build EXPOSE 9000 -CMD ["npm", "run", "start"] \ No newline at end of file +CMD ["npm", "run", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index 0759b66..ea6fe06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,15 @@ services: uiogaming.no: container_name: uiogaming.no - build: . + build: + context: . + # Values are read from .env + args: + NEXT_PUBLIC_SANITY_PROJECT_ID: ${NEXT_PUBLIC_SANITY_PROJECT_ID} + NEXT_PUBLIC_SANITY_DATASET: ${NEXT_PUBLIC_SANITY_DATASET} + NEXT_PUBLIC_UMAMI_SRC: ${NEXT_PUBLIC_UMAMI_SRC} + NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${NEXT_PUBLIC_UMAMI_WEBSITE_ID} + env_file: .env ports: - 9000:9000 environment: