Files
edr-platform/infrastructure/docker/Dockerfile.web
ghost2023 4b3e8ad32c feat(landing): add front door routing to passenger and freight
edrsc.com had no entry point — a visitor could not tell which of the two
apps they wanted. This adds @edr/landing: one static page whose job is to
make that choice obvious, with the two doors above the fold and the rest
kept to supporting context.

Fills in apps/edr-landing/, which until now held an orphaned next-env.d.ts
from an abandoned Next 15 start and was built by nothing.

- Next.js 14 static export. Versions mirror the passenger portal exactly,
  so they resolve to what the lockfile already had and add 6 packages.
  Depends on no workspace package — @edr/ui-common's Tailwind 4 tokens do
  not fit this Tailwind 3 setup.
- Destinations come from NEXT_PUBLIC_PASSENGER_URL / NEXT_PUBLIC_FREIGHT_URL
  as origins, with the entry path appended in src/lib/apps.ts. Freight links
  to /portal rather than /, which is that app's own marketing landing.
- Design lifted from EDRFreightLandingPage so the two public surfaces read
  as one railway. Figures (752 km, ~16 h) are the ones freight already
  asserts publicly.
- Fonts load as a stylesheet, not next/font: next/font fetches from
  fonts.googleapis.com during `next build` and failed the build outright on
  a machine without network. Verified deterministic over repeated builds.
- CountUp renders its final value server-side and the reveal animation's
  hidden state is scoped behind html.js, so the page is complete with
  JavaScript off instead of blank.

turbo.json: a static export's artifact is out/, which the build task did not
list — a cache hit would have restored a build with the artifact missing.
Also gitignored.

Dockerfile.web: passes the two NEXT_PUBLIC_* build args through (a static
export inlines them at build time, so runtime env does nothing), and exempts
this app from the VITE_* required-check that guards the freight Vite apps and
would otherwise fail its build.

Claude-Session: https://claude.ai/code/session_011ZMMHwK4Ham1Dt19FVZQj3
2026-09-04 20:32:53 +03:00

114 lines
4.0 KiB
Docker

# syntax=docker/dockerfile:1
ARG TURBO_FILTER=@edr/freight-portal
ARG APP_PATH=apps/edr-freight-web/portal
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
ARG VITE_BASE_API_URL
ARG VITE_USER_MANAGEMENT_BASE
ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_PASSENGER_URL
ARG NEXT_PUBLIC_FREIGHT_URL
ARG VITE_GOOGLE_MAPS_API_KEY
ARG VITE_POSTHOG_KEY
ARG VITE_POSTHOG_HOST
ARG VITE_ENV
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_BASE_API_URL=${VITE_BASE_API_URL}
ENV VITE_USER_MANAGEMENT_BASE=${VITE_USER_MANAGEMENT_BASE}
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# @edr/landing is a static export; these are inlined at build time.
ENV NEXT_PUBLIC_PASSENGER_URL=${NEXT_PUBLIC_PASSENGER_URL}
ENV NEXT_PUBLIC_FREIGHT_URL=${NEXT_PUBLIC_FREIGHT_URL}
ENV VITE_GOOGLE_MAPS_API_KEY=${VITE_GOOGLE_MAPS_API_KEY}
ENV VITE_POSTHOG_KEY=${VITE_POSTHOG_KEY}
ENV VITE_POSTHOG_HOST=${VITE_POSTHOG_HOST}
# dev|staging only — gates the Fayda/OTP bypass. Unset in prod.
ENV VITE_ENV=${VITE_ENV}
# Guards the freight Vite apps. @edr/landing is a Next static export that
# reads none of these, so requiring them would block its build outright.
RUN if [ "${TURBO_FILTER}" != "@edr/landing" ] && \
{ [ -z "$VITE_API_URL" ] || [ -z "$VITE_BASE_API_URL" ] || [ -z "$VITE_USER_MANAGEMENT_BASE" ]; }; then \
echo "ERROR: VITE_API_URL, VITE_BASE_API_URL, and VITE_USER_MANAGEMENT_BASE must all be set" && \
exit 1; \
fi
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
RUN if [ ! -d "/app/${APP_PATH}/dist" ] && [ ! -d "/app/${APP_PATH}/out" ]; then \
echo "ERROR: Build output directory not found at /app/${APP_PATH}/dist or /app/${APP_PATH}/out"; \
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 nginx configuration
COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf
# Remove default nginx files
RUN rm -rf /usr/share/nginx/html/*
# Copy build output - check for Next.js 'out' or Vite 'dist' directory
# Use shell to handle conditional copy
RUN --mount=type=bind,from=builder,source=/app,target=/build \
if [ -d "/build/${APP_PATH}/out" ]; then \
cp -r /build/${APP_PATH}/out/* /usr/share/nginx/html/; \
echo "Copied from Next.js 'out' directory"; \
elif [ -d "/build/${APP_PATH}/dist" ]; then \
cp -r /build/${APP_PATH}/dist/* /usr/share/nginx/html/; \
echo "Copied from Vite 'dist' directory"; \
else \
echo "Error: No build output found in 'out' or 'dist' directory"; \
exit 1; \
fi
# Copy public directory if it exists (for static assets)
RUN --mount=type=bind,from=builder,source=/app,target=/build \
if [ -d "/build/${APP_PATH}/public" ]; then \
mkdir -p /usr/share/nginx/html/public && \
cp -r /build/${APP_PATH}/public/* /usr/share/nginx/html/public/ && \
echo "Copied public directory"; \
else \
echo "No public directory found, skipping"; \
fi
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]