From 57f775ac7043722fa777fe93c4ec11c9b9fb2adb Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Sat, 20 Dec 2025 14:42:34 +0100 Subject: [PATCH 1/3] ci: improve docker build --- .dockerignore | 23 ++++++++++++++++++ .github/workflows/docker.yml | 4 ++- Dockerfile | 47 +++++++++++++++++++++++++++++++----- 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..5b9c8f930 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +# Do NOT ignore .git - needed in the image for version metadata +# .git +node_modules +**/node_modules +npm-debug.log +yarn-error.log +dist +.DS_Store +.gitignore +.vscode +.env +.env.local +logs +*.log +coverage +tests +docs +.idea +.cache +# Ignore local config backups +server/src/configs/koji_backups/** +# Keep package and source files but ignore nested node_modules +packages/*/node_modules diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e4eef64a0..1143535cc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,7 +9,9 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4.1.1 + - uses: actions/checkout@v4 + with: + fetch-depth: 1 - name: Set .gitsha run: 'echo ${{ github.sha }} > .gitsha' - name: Set .gitref diff --git a/Dockerfile b/Dockerfile index 3efc6246f..11a103e12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,51 @@ # - mount areas.json to /home/node/server/src/configs/areas.json # - Also mount every other configuration file necessary into the according directory. -FROM node:22-alpine +FROM node:22-alpine AS builder ENV NPM_CONFIG_PREFIX=/home/node/.npm-global ENV PATH=$PATH:/home/node/.npm-global/bin WORKDIR /home/node -COPY package.json . -COPY yarn.lock . -RUN apk add git -RUN npm install -g yarn + +# Install minimal build deps +RUN apk add --no-cache git python3 make g++ + +# Install yarn (node:22 includes corepack but ensure yarn v1 available) +RUN npm install -g yarn@1.22.19 + +# Copy package manifests first for better layer caching +COPY package.json yarn.lock ./ +COPY packages ./packages +COPY server ./server +COPY public ./public +COPY ReactMap.js ./ReactMap.js + +# Copy remaining source needed for build (excluding node_modules via .dockerignore) COPY . . -RUN yarn install + +# Install all deps and build +RUN yarn install --frozen-lockfile RUN yarn build + +# Reinstall only production dependencies to a clean node_modules folder +RUN rm -rf node_modules && yarn install --production --frozen-lockfile --ignore-scripts + + +# Final runtime image +FROM node:22-alpine AS runtime +ENV NODE_ENV=production +ENV NPM_CONFIG_PREFIX=/home/node/.npm-global +ENV PATH=$PATH:/home/node/.npm-global/bin +WORKDIR /home/node + +# Install yarn in runtime if you need it (keeps compatibility). +RUN npm install -g yarn@1.22.19 + +# Copy production node_modules and built assets from builder +COPY --from=builder /home/node/node_modules ./node_modules +COPY --from=builder /home/node/package.json ./package.json +COPY --from=builder /home/node/server ./server +COPY --from=builder /home/node/public ./public +COPY --from=builder /home/node/dist ./dist +COPY --from=builder /home/node/ReactMap.js ./ReactMap.js From 27340f7cfaa669f7836b7568d9c2b2955b4d3953 Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Sat, 20 Dec 2025 15:14:38 +0100 Subject: [PATCH 2/3] ci: improve docker build --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 11a103e12..998bee2fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,3 +53,5 @@ COPY --from=builder /home/node/server ./server COPY --from=builder /home/node/public ./public COPY --from=builder /home/node/dist ./dist COPY --from=builder /home/node/ReactMap.js ./ReactMap.js +COPY --from=builder /home/node/packages ./packages +COPY --from=builder /home/node/config ./config From b5aece78c3427b90fce3b99a4e1ebbdc0b35663e Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 30 Dec 2025 18:28:07 -0800 Subject: [PATCH 3/3] fix: stuff --- Dockerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 998bee2fe..6c8e8b3f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,12 +28,20 @@ COPY ReactMap.js ./ReactMap.js # Copy remaining source needed for build (excluding node_modules via .dockerignore) COPY . . +# Capture git metadata for update checks in Docker builds. +RUN if [ -d .git ]; then \ + git rev-parse HEAD > .gitsha; \ + ref="$(git symbolic-ref -q HEAD || true)"; \ + if [ -z "$ref" ]; then ref="refs/heads/main"; fi; \ + printf '%s\n' "$ref" > .gitref; \ + fi + # Install all deps and build RUN yarn install --frozen-lockfile RUN yarn build # Reinstall only production dependencies to a clean node_modules folder -RUN rm -rf node_modules && yarn install --production --frozen-lockfile --ignore-scripts +RUN rm -rf node_modules && HUSKY=0 yarn install --production --frozen-lockfile # Final runtime image @@ -55,3 +63,5 @@ COPY --from=builder /home/node/dist ./dist COPY --from=builder /home/node/ReactMap.js ./ReactMap.js COPY --from=builder /home/node/packages ./packages COPY --from=builder /home/node/config ./config +COPY --from=builder /home/node/.gitsha ./.gitsha +COPY --from=builder /home/node/.gitref ./.gitref