-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
50 lines (36 loc) · 1.15 KB
/
Dockerfile
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
FROM node:18-bullseye-slim AS base
# Set for base and all layer that inherit from it
ENV NODE_ENV production
# Install all dependencies for the build step
FROM base AS deps
WORKDIR /app
# A lockfile is required
COPY package.json package-lock.json* ./
RUN \
if [ -f package-lock.json ]; then npm ci --include=dev; \
else echo "Lockfile not found." && exit 1; \
fi
# Filter out dev dependencies for production usage
FROM base AS deps-prod
WORKDIR /app
# Copy all deps and then prune only dev deps
COPY --from=deps /app/node_modules ./node_modules
COPY package.json package-lock.json* ./
RUN npm prune --omit=dev
# Build the source code
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY ./.env.azure ./.env
RUN npm run build
# Create the production image, copy all the files and run the server
FROM base AS runner
WORKDIR /app
COPY --from=deps-prod /app/node_modules ./node_modules
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/server ./server
EXPOSE 3000
ENV PORT 3000
CMD ["npm", "start"]