-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (52 loc) · 2.25 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (52 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## Multistage Dockerfile for Cloud Run
# Builder: install deps and build frontend + bundle server
FROM node:20-bullseye AS builder
WORKDIR /app
ENV npm_config_ignore_optional=true
# ---------------------------------------------------------------
# Firebase / Vite build-time env vars
# Pass these when building: docker build --build-arg VITE_FIREBASE_API_KEY=xxx ...
# Or set them in Cloud Build substitutions / CI environment.
# These are baked into the frontend bundle by Vite.
# ---------------------------------------------------------------
ARG VITE_FIREBASE_API_KEY
ARG VITE_FIREBASE_AUTH_DOMAIN
ARG VITE_FIREBASE_PROJECT_ID
ARG VITE_FIREBASE_STORAGE_BUCKET
ARG VITE_FIREBASE_MESSAGING_SENDER_ID
ARG VITE_FIREBASE_APP_ID
ARG VITE_FIREBASE_MEASUREMENT_ID
ARG VITE_FIRESTORE_DATABASE_ID
ENV VITE_FIREBASE_API_KEY=$VITE_FIREBASE_API_KEY
ENV VITE_FIREBASE_AUTH_DOMAIN=$VITE_FIREBASE_AUTH_DOMAIN
ENV VITE_FIREBASE_PROJECT_ID=$VITE_FIREBASE_PROJECT_ID
ENV VITE_FIREBASE_STORAGE_BUCKET=$VITE_FIREBASE_STORAGE_BUCKET
ENV VITE_FIREBASE_MESSAGING_SENDER_ID=$VITE_FIREBASE_MESSAGING_SENDER_ID
ENV VITE_FIREBASE_APP_ID=$VITE_FIREBASE_APP_ID
ENV VITE_FIREBASE_MEASUREMENT_ID=$VITE_FIREBASE_MEASUREMENT_ID
ENV VITE_FIRESTORE_DATABASE_ID=$VITE_FIRESTORE_DATABASE_ID
# Copy package manifests first for caching
COPY package.json package-lock.json* ./
# Install all deps (including dev) needed for build
RUN npm ci --ignore-optional --prefer-offline --no-audit --progress=false
# Copy source
COPY . .
# Build frontend and bundle server (creates dist/server.cjs)
RUN npm run build
# Runtime image: smaller, production-only
FROM node:20-bullseye-slim AS runner
WORKDIR /app
# Use production environment
ENV NODE_ENV=production
# Copy built artifacts
COPY --from=builder /app/dist ./dist
# Copy package manifests and install only production deps
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev --prefer-offline --no-audit --progress=false
# Expose the port Cloud Run expects via the $PORT env var (set at runtime)
EXPOSE 8080
# Use a non-root user where possible (node image already creates user 'node')
USER node
# Start the bundled server
CMD ["node", "dist/server.cjs"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD curl -f http://localhost:$PORT/health || exit 1