-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
49 lines (35 loc) · 1.18 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
# Rebuild the source code only when needed
FROM node:lts-alpine AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN apk add --no-cache --virtual .gyp python3 make g++ \
&& corepack enable \
&& corepack prepare pnpm@latest --activate \
&& npm pkg delete scripts.prepare \
&& pnpm i --frozen-lockfile
WORKDIR /app
COPY . .
ENV NODE_ENV production
RUN npm pkg delete scripts.prepare \
&& pnpm build \
&& pnpm prune --prod
# Production image, copy all the files and run next
FROM node:lts-alpine AS runner
ENV NODE_ENV production
ENV PAYLOAD_CONFIG_PATH dist/payload.config.js
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nodejs
USER nodejs
WORKDIR /app
# Copy dependencies
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/assets ./assets
COPY --from=builder --chown=nodejs:nodejs /app/package.json ./package.json
RUN npm pkg set scripts.payload=payload
# Copy transpiled code
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/build ./build
USER nodejs
EXPOSE 3001
ENV PORT 3001
CMD ["node", "dist/server.js"]