-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (31 loc) · 1.26 KB
/
Copy pathDockerfile
File metadata and controls
36 lines (31 loc) · 1.26 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
# ---------------------------------------------------------------------------
# EcoSync — single-image build for Google Cloud Run.
#
# Stage 1 compiles the React dashboard. Stage 2 installs the FastAPI backend
# and copies the built frontend into ./static so one service serves both the
# API (/api/v1/*) and the SPA. Cloud Run injects $PORT at runtime.
# ---------------------------------------------------------------------------
# Stage 1: build the frontend
FROM node:20-slim AS frontend
WORKDIR /app/frontend
ARG VITE_GOOGLE_MAPS_API_KEY=""
ENV VITE_GOOGLE_MAPS_API_KEY=$VITE_GOOGLE_MAPS_API_KEY
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build
# Stage 2: backend + bundled static frontend
FROM python:3.12-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=8080
WORKDIR /app
COPY backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY backend/ ./
COPY --from=frontend /app/frontend/dist ./static
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT}/health || exit 1
# Use JSON form with sh -c and exec so $PORT is expanded and signals are forwarded.
CMD ["sh", "-c", "exec uvicorn main:app --host 0.0.0.0 --port ${PORT}"]