11# Base image
2- FROM node:16-alpine
3-
4- # Create a directory for the app
2+ FROM node:24-alpine AS base
53WORKDIR /app
64
5+ # pnpm setup
6+ ENV CI=true
7+ RUN corepack enable pnpm && \
8+ pnpm config set store-dir /pnpm/store && \
9+ pnpm config set package-import-method clone-or-copy
10+
11+ # Build stage
12+ FROM base AS fetch-deps
13+ COPY pnpm-lock.yaml pnpm-workspace.yaml ./
14+ RUN pnpm fetch --prod
15+
16+ FROM fetch-deps AS prod-deps
17+ COPY . .
18+ RUN pnpm install -r --offline --prod --filter server...
19+
20+ FROM fetch-deps AS build-base
21+ RUN pnpm fetch
22+
23+ # Build both frontend and server separately for caching
24+ FROM build-base AS build-server
25+ COPY . .
26+ RUN pnpm install -r --offline --filter server...
27+ # Build with CI=false to avoid treat warnings as errors
28+ RUN CI=false pnpm run -r --filter server... build
29+
30+ FROM build-base AS build-frontend
31+ COPY . .
32+ # TODO: filter only frontend dependencies. until we add a shared package, we need all dependencies
33+ RUN pnpm install -r --offline
34+
735# Read build-time environment variables
836ARG REACT_APP_SERVER_URL
937ENV REACT_APP_SERVER_URL=${REACT_APP_SERVER_URL}
@@ -13,25 +41,23 @@ ARG REACT_APP_PUBLIC_VAPID_KEY
1341ENV REACT_APP_PUBLIC_VAPID_KEY=${REACT_APP_PUBLIC_VAPID_KEY}
1442ARG REACT_APP_ENCRYPTION_KEY
1543ENV REACT_APP_ENCRYPTION_KEY=${REACT_APP_ENCRYPTION_KEY}
44+ ARG REACT_APP_GOOGLE_MAPS_API_KEY
45+ ENV REACT_APP_GOOGLE_MAPS_API_KEY=${REACT_APP_GOOGLE_MAPS_API_KEY}
46+ ARG REACT_APP_GOOGLE_MAPS_MAP_ID
47+ ENV REACT_APP_GOOGLE_MAPS_MAP_ID=${REACT_APP_GOOGLE_MAPS_MAP_ID}
1648
17- # Copy package.jsons first to install
18- COPY package.json package-lock.json /app/
19- COPY frontend/package.json frontend/package-lock.json /app/frontend/
20- COPY server/package.json server/package-lock.json /app/server/
21- RUN npm install
49+ # Build with CI=false to avoid treat warnings as errors
50+ RUN CI=false pnpm run -r --filter frontend... build
2251
52+ FROM base AS prod
2353# Copy the frontend and server directories to the app directory
24- COPY frontend /app/frontend
25- COPY server /app/server
26- COPY . .
54+ COPY --from=prod-deps /app/node_modules /app/node_modules
55+ COPY --from=prod-deps /app/server/node_modules /app/server/node_modules
2756
28- # Install dependencies for the frontend and build the app
29- WORKDIR /app/frontend
30- RUN npm run build
57+ COPY --from=build-frontend /app/frontend/build /app/frontend/build
3158
32- # Install dependencies for the server
33- WORKDIR /app/server
34- RUN npm run build
59+ COPY --from=build-server /app/server/build /app/server/build
60+ COPY --from=build-server /app/server/package.json /app/server/package.json
3561
3662# Set production environment after build
3763ENV NODE_ENV=production
@@ -40,4 +66,5 @@ ENV NODE_ENV=production
4066EXPOSE 3001
4167
4268# Start the server
43- CMD ["npm" , "start" ]
69+ WORKDIR /app/server
70+ CMD ["pnpm" , "start" ]
0 commit comments