From 3c4e10eda77fc507f19c51a530b84ed7deb85f16 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Mon, 20 Apr 2026 07:54:46 +0200 Subject: [PATCH] refactor: optimize Dockerfile by restructuring build steps and improving clarity --- app/Dockerfile | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/Dockerfile b/app/Dockerfile index 61fd09c..d7b3a9b 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,34 +1,50 @@ +# Build stage FROM node:24-trixie-slim AS build WORKDIR /app -COPY backend/package*.json backend/ -COPY frontend/package*.json frontend/ -RUN cd backend && npm ci -RUN cd frontend && npm ci +# Copy sources required for build +COPY backend/*.json backend/ +COPY backend/src backend/src -COPY . . +COPY frontend/*.json frontend/ +COPY frontend/vite.config.ts frontend/vite.config.ts +COPY frontend/index.html frontend/index.html +COPY frontend/src frontend/src +COPY frontend/test frontend/test -RUN cd backend && npm run build -RUN cd frontend && npm run build -RUN cd backend && npm prune --omit=dev +COPY templates templates +COPY templates.json templates.json +# Build backend and frontend +RUN cd backend && npm ci && npm run build && npm prune --omit=dev +RUN cd frontend && npm ci && npm run build + +# Build the container FROM node:24-trixie-slim AS runtime WORKDIR /app -ENV NODE_ENV=production -ENV PORT=3000 +# Copy built artifacts COPY --from=build /app/dist dist COPY --from=build /app/templates templates COPY --from=build /app/templates.json templates.json COPY --from=build /app/backend/node_modules dist/backend/node_modules -WORKDIR /app +# Copy entrypoint and healthcheck scripts COPY entrypoint.sh entrypoint.sh COPY healthcheck.js healthcheck.js + +# Ensure entrypoint script is executable RUN chmod +x entrypoint.sh +# Set environment variables and expose port +ENV NODE_ENV=production +ENV PORT=3000 EXPOSE 3000 + +# Configure health check HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 CMD ["node", "/app/healthcheck.js"] + +# Configure entrypoint ENTRYPOINT ["./entrypoint.sh"]