-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContainerfile
More file actions
79 lines (59 loc) · 2.14 KB
/
Containerfile
File metadata and controls
79 lines (59 loc) · 2.14 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Build stage
FROM docker.io/library/node:22.18.0 AS base
WORKDIR /app
# Development stage
FROM base as dev
CMD ["sh", "-c", "npm install && npm run dev"]
FROM base as builder
# Copy build trigger file to force rebuilds when it changes
COPY .render-build-trigger /tmp/build-trigger
# Copy package files
COPY package*.json ./
# Install dependencies (including dev dependencies for build)
RUN npm ci
# Copy source code
COPY . .
# Accept build arguments for Vite environment variables
ARG VITE_PRODUCT_NAME
ARG VITE_LOGTO_ENDPOINT
ARG VITE_LOGTO_APP_ID
ARG VITE_API_BASE_URL
ARG VITE_SIGNIN_REDIRECT_URI
ARG VITE_SIGNOUT_REDIRECT_URI
# Set environment variables for Vite build
ENV VITE_PRODUCT_NAME=$VITE_PRODUCT_NAME
ENV VITE_LOGTO_ENDPOINT=$VITE_LOGTO_ENDPOINT
ENV VITE_LOGTO_APP_ID=$VITE_LOGTO_APP_ID
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_SIGNIN_REDIRECT_URI=$VITE_SIGNIN_REDIRECT_URI
ENV VITE_SIGNOUT_REDIRECT_URI=$VITE_SIGNOUT_REDIRECT_URI
# Build the application
RUN npm run build
# Distribution stage (for local use only - static files only)
FROM scratch as dist
COPY --from=builder /app/dist /
# Production stage (default for deployment)
FROM nginx:1.25-alpine as production
# Install gettext for envsubst command
RUN apk add --no-cache gettext
# Remove default nginx configuration
RUN rm -rf /usr/share/nginx/html/*
# Copy built static files from builder stage
COPY --from=builder /app/dist /usr/share/nginx/html/
# Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Create nginx user if it doesn't exist
RUN addgroup -g 101 -S nginx || true
RUN adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx || true
# Set correct permissions
RUN chown -R nginx:nginx /usr/share/nginx/html
RUN chmod -R 755 /usr/share/nginx/html
# Expose port (default 8080, can be overridden by PORT env var)
ARG PORT=8080
ENV PORT=${PORT}
EXPOSE ${PORT}
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT:-8080}/ || exit 1
# Start nginx
CMD ["sh", "-c", "envsubst '$$PORT' < /etc/nginx/nginx.conf > /tmp/nginx.conf && nginx -c /tmp/nginx.conf -g 'daemon off;'"]