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;"]