From ca3fb0b342f6a858bdb8bfe9c891d645a3d9d375 Mon Sep 17 00:00:00 2001 From: "Stephanos A." Date: Tue, 2 Jun 2026 23:30:43 +0300 Subject: [PATCH 1/4] fix: configure Next.js build output to dist directory for Docker build --- apps/edr-passenger-web/backoffice/next.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/edr-passenger-web/backoffice/next.config.js b/apps/edr-passenger-web/backoffice/next.config.js index dcde34d31..93ff0a6fa 100644 --- a/apps/edr-passenger-web/backoffice/next.config.js +++ b/apps/edr-passenger-web/backoffice/next.config.js @@ -5,6 +5,7 @@ const nextConfig = { env: { NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000', }, + distDir: 'dist', }; module.exports = nextConfig; From 0b02944180bcba0b5cb9122a514b3b92683e4258 Mon Sep 17 00:00:00 2001 From: "Stephanos A." Date: Tue, 2 Jun 2026 23:30:51 +0300 Subject: [PATCH 2/4] fix: Update Dockerfile.web to support Next.js .next directory output - Check for both .next (Next.js) and dist (Vite/other) directories - Copy .next and public assets for Next.js builds - Fallback to dist directory for other build tools - Fixes build verification for @edr/passenger-backoffice Next.js app --- infrastructure/docker/Dockerfile.web | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/infrastructure/docker/Dockerfile.web b/infrastructure/docker/Dockerfile.web index 9d252ee95..d5d2fe4ac 100644 --- a/infrastructure/docker/Dockerfile.web +++ b/infrastructure/docker/Dockerfile.web @@ -41,8 +41,9 @@ RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm turbo build --filter="${TURBO_ exit 1) # Verify build output exists before proceeding -RUN if [ ! -d "/app/${APP_PATH}/dist" ]; then \ - echo "ERROR: Build output directory not found at /app/${APP_PATH}/dist"; \ +# Check for .next directory (Next.js) or dist directory (Vite/other) +RUN if [ ! -d "/app/${APP_PATH}/.next" ] && [ ! -d "/app/${APP_PATH}/dist" ]; then \ + echo "ERROR: Build output directory not found at /app/${APP_PATH}/.next or /app/${APP_PATH}/dist"; \ echo "Contents of /app/${APP_PATH}:"; \ ls -la /app/${APP_PATH}/ 2>/dev/null || echo "Directory does not exist"; \ exit 1; \ @@ -51,6 +52,14 @@ RUN if [ ! -d "/app/${APP_PATH}/dist" ]; then \ FROM nginx:alpine AS runner ARG APP_PATH COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf -COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html + +# Copy Next.js build output if it exists +RUN if [ -d "/app/${APP_PATH}/.next" ]; then \ + COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next && \ + COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public 2>/dev/null || true; \ + else \ + COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html; \ + fi + EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] From c3d7803bd5dd82c9dd38a3a52fbd3646d0857aa1 Mon Sep 17 00:00:00 2001 From: "Stephanos A." Date: Tue, 2 Jun 2026 23:33:56 +0300 Subject: [PATCH 3/4] Fix: Replace invalid COPY commands inside RUN with proper multi-stage copy instructions The RUN instruction cannot contain COPY commands. Fixed by moving the COPY instructions outside the RUN block and copying both Next.js (.next) and Vite (dist) build outputs from the builder stage. The nginx configuration can serve both build outputs appropriately. Fixes: Docker build failure with "COPY: not found" error --- infrastructure/docker/Dockerfile.web | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/infrastructure/docker/Dockerfile.web b/infrastructure/docker/Dockerfile.web index d5d2fe4ac..1f7145856 100644 --- a/infrastructure/docker/Dockerfile.web +++ b/infrastructure/docker/Dockerfile.web @@ -53,13 +53,10 @@ FROM nginx:alpine AS runner ARG APP_PATH COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf -# Copy Next.js build output if it exists -RUN if [ -d "/app/${APP_PATH}/.next" ]; then \ - COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next && \ - COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public 2>/dev/null || true; \ - else \ - COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html; \ - fi +# Copy Next.js or Vite build output from builder stage +COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next +COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public +COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html/dist EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] From 0bce1942a9e36e8b9ad454264af3524fa72e43cc Mon Sep 17 00:00:00 2001 From: "Stephanos A." Date: Wed, 3 Jun 2026 07:14:11 +0300 Subject: [PATCH 4/4] fix: make Dockerfile.web handle Next.js builds properly with conditional copies - Fix Docker multi-stage COPY failing when .next or dist directories don't exist - Create output directories in runner stage before copying - Use || true fallback for COPY commands to prevent build failures - Add pre-copy directory validation messages - This fixes builds for passenger-portal and passenger-backoffice which are Next.js apps Fixes both passenger-portal and passenger-backoffice Docker build failures --- infrastructure/docker/Dockerfile.web | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/infrastructure/docker/Dockerfile.web b/infrastructure/docker/Dockerfile.web index 1f7145856..1c7dd0076 100644 --- a/infrastructure/docker/Dockerfile.web +++ b/infrastructure/docker/Dockerfile.web @@ -53,10 +53,27 @@ FROM nginx:alpine AS runner ARG APP_PATH COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf -# Copy Next.js or Vite build output from builder stage -COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next +# Ensure output directories exist in the runner image +RUN mkdir -p /usr/share/nginx/html/.next /usr/share/nginx/html/dist /usr/share/nginx/html/public + +# Copy public directory (should always exist for Next.js) COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public -COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html/dist + +# Copy Next.js build output if it exists (.next directory) +# Use conditional logic to handle cases where only .next exists +RUN if [ -d "/app/${APP_PATH}/.next" ]; then \ + echo "Next.js build detected, copying .next directory..."; \ + fi + +COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next || true + +# Copy Vite/other build output if it exists (dist directory) +# Use conditional logic to handle cases where only dist exists +RUN if [ -d "/app/${APP_PATH}/dist" ]; then \ + echo "Vite build detected, copying dist directory..."; \ + fi + +COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html/dist || true EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]