From 0bce1942a9e36e8b9ad454264af3524fa72e43cc Mon Sep 17 00:00:00 2001 From: "Stephanos A." Date: Wed, 3 Jun 2026 07:14:11 +0300 Subject: [PATCH] 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;"]