-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.frontend
More file actions
85 lines (67 loc) · 2.54 KB
/
Copy pathDockerfile.frontend
File metadata and controls
85 lines (67 loc) · 2.54 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
80
81
82
83
84
85
# ===========================================
# Stage 1: Build
# ===========================================
FROM node:20-alpine AS builder
WORKDIR /app
ARG NEXT_PUBLIC_API_URL=/api
ARG NEXT_PUBLIC_APP_NAME=BookStore
ARG NEXT_PUBLIC_APP_DESCRIPTION="Professional Vietnamese E-Commerce BookStore Platform"
ARG NEXT_PUBLIC_VNPAY_ENABLED=false
ARG API_PROXY_TARGET=https://bookstore-api-a1xl.onrender.com/api
ARG APP_GIT_SHA=unknown
ARG APP_VERSION=unknown
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
ENV NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME}
ENV NEXT_PUBLIC_APP_DESCRIPTION=${NEXT_PUBLIC_APP_DESCRIPTION}
ENV NEXT_PUBLIC_VNPAY_ENABLED=${NEXT_PUBLIC_VNPAY_ENABLED}
ENV API_PROXY_TARGET=${API_PROXY_TARGET}
ENV APP_GIT_SHA=${APP_GIT_SHA}
ENV NEXT_PUBLIC_APP_GIT_SHA=${APP_GIT_SHA}
ENV NEXT_PUBLIC_APP_VERSION=${APP_VERSION}
# Copy package files first (for dependency caching)
COPY frontend/package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY frontend/ ./
# Build the application
RUN npm run build
# ===========================================
# Stage 2: Runtime
# ===========================================
FROM node:20-alpine AS runner
WORKDIR /app
ARG NEXT_PUBLIC_API_URL=/api
ARG NEXT_PUBLIC_APP_NAME=BookStore
ARG NEXT_PUBLIC_APP_DESCRIPTION="Professional Vietnamese E-Commerce BookStore Platform"
ARG NEXT_PUBLIC_VNPAY_ENABLED=false
ARG API_PROXY_TARGET=https://bookstore-api-a1xl.onrender.com/api
ARG APP_GIT_SHA=unknown
ARG APP_VERSION=unknown
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
ENV NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME}
ENV NEXT_PUBLIC_APP_DESCRIPTION=${NEXT_PUBLIC_APP_DESCRIPTION}
ENV NEXT_PUBLIC_VNPAY_ENABLED=${NEXT_PUBLIC_VNPAY_ENABLED}
ENV API_PROXY_TARGET=${API_PROXY_TARGET}
ENV APP_GIT_SHA=${APP_GIT_SHA}
ENV NEXT_PUBLIC_APP_GIT_SHA=${APP_GIT_SHA}
ENV NEXT_PUBLIC_APP_VERSION=${APP_VERSION}
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy built artifacts
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
# Install curl for healthcheck
RUN apk add --no-cache curl
# Expose port
EXPOSE 3000
USER nextjs
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1
CMD ["node", "server.js"]