-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (35 loc) · 1.21 KB
/
Copy pathDockerfile
File metadata and controls
46 lines (35 loc) · 1.21 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
# ---- Stage 1: Build ----
FROM node:22-alpine AS build
WORKDIR /app
# Copy dependency manifests first for better layer caching
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci
# Copy the rest of the source code
COPY . .
# Accept the API key as a build arg so it gets baked into the static bundle.
# On Render, set VITE_GEMINI_API_KEY in the Environment tab and Render
# will automatically pass environment variables as Docker build args.
ARG VITE_GEMINI_API_KEY
# Write .env file from the build arg so Vite picks it up during the build
RUN if [ -n "$VITE_GEMINI_API_KEY" ]; then \
echo "VITE_GEMINI_API_KEY=$VITE_GEMINI_API_KEY" > .env; \
fi
# Build the production bundle
RUN npm run build
# ---- Stage 2: Serve ----
FROM nginx:stable-alpine
# Copy the built assets to Nginx's default serve directory
COPY --from=build /app/dist /usr/share/nginx/html
# SPA support: redirect all routes to index.html
RUN printf 'server {\n\
listen 80;\n\
server_name localhost;\n\
root /usr/share/nginx/html;\n\
index index.html;\n\
location / {\n\
try_files $uri $uri/ /index.html;\n\
}\n\
}\n' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]