-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (40 loc) · 1.5 KB
/
Dockerfile
File metadata and controls
55 lines (40 loc) · 1.5 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
FROM node:22-alpine AS base
# Use a consistent working directory across all stages
WORKDIR /app
# 1) Install dependencies
FROM base AS deps
# If your application uses environment variables for compile-time configuration, you can use arguments
# to configure them when building the image.
# ARG FOO=BAR
# ENV REACT_APP_FOO=${FOO}
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
# Uncomment the next line if you're not using Classic Yarn
#COPY ./.yarn ./.yarn
# Install dependencies using the detected lockfile
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# 2) Run the build
FROM base AS builder
# Copy installed dependencies
COPY --from=deps /app/node_modules ./node_modules
# Copy all source files
COPY . .
# Build the app using the detected package manager
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
# 3) Create minimal image to serve the app
FROM nginxinc/nginx-unprivileged:1.25-alpine as runner
# Copy built files to nginx web root
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy your custom nginx config
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]