mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 04:20:55 +00:00
- 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
80 lines
2.8 KiB
Docker
80 lines
2.8 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
ARG TURBO_FILTER=@edr/freight-portal
|
|
ARG APP_PATH=apps/edr-freight-web/portal
|
|
ARG VITE_API_URL=http://localhost:3001/api
|
|
|
|
FROM node:24.15.0-alpine AS base
|
|
RUN apk add --no-cache libc6-compat
|
|
RUN corepack enable
|
|
WORKDIR /app
|
|
|
|
FROM base AS pruner
|
|
ARG TURBO_FILTER
|
|
COPY . .
|
|
RUN pnpm dlx turbo prune "${TURBO_FILTER}" --docker
|
|
|
|
FROM base AS installer
|
|
COPY --from=pruner /app/out/json/ .
|
|
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
|
RUN --mount=type=secret,id=npmrc,target=./.npmrc,required=false \
|
|
--mount=type=cache,id=pnpm,target=/pnpm/store \
|
|
pnpm install --frozen-lockfile
|
|
|
|
FROM base AS builder
|
|
ARG TURBO_FILTER
|
|
ARG APP_PATH
|
|
ARG VITE_API_URL
|
|
ENV VITE_API_URL=${VITE_API_URL}
|
|
COPY --from=installer /app/ .
|
|
COPY --from=pruner /app/out/full/ .
|
|
|
|
# Configure npm/pnpm with extended timeouts and retries for network requests
|
|
RUN npm config set fetch-timeout 120000 && \
|
|
npm config set fetch-retry-mintimeout 20000 && \
|
|
npm config set fetch-retry-maxtimeout 120000 && \
|
|
npm config set fetch-retries 5
|
|
|
|
RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm turbo build --filter="${TURBO_FILTER}..." || \
|
|
(echo "Build failed for ${TURBO_FILTER}" && \
|
|
ls -la /app/${APP_PATH}/ 2>/dev/null || echo "App path does not exist" && \
|
|
exit 1)
|
|
|
|
# Verify build output exists before proceeding
|
|
# 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; \
|
|
fi
|
|
|
|
FROM nginx:alpine AS runner
|
|
ARG APP_PATH
|
|
COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# 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 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;"]
|