-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
65 lines (45 loc) · 1.53 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
###################
# BUILD FOR LOCAL DEVELOPMENT
###################
FROM node:20-alpine As development
USER node
# Create app directory
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY --chown=node:node package*.json ./
COPY --chown=node:node .npmignore ./
COPY --chown=node:node .npmrc ./
# Install app dependencies
RUN npm ci --ignore-scripts
# Bundle app source
COPY --chown=node:node . .
###################
# BUILD FOR PRODUCTION
###################
# Base image for production
FROM node:20-alpine As build
USER node
# Create app directory
WORKDIR /usr/src/app
COPY --chown=node:node package*.json ./
COPY --chown=node:node .npmignore ./
COPY --chown=node:node .npmrc ./
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
# Bundle app source
COPY --chown=node:node . .
RUN npm run build
# Set NODE_ENV environment variable
ENV NODE_ENV production
RUN npm ci --ignore-scripts --only=production && npm cache clean --force
###################
# PRODUCTION
###################
# Base image for production
FROM node:20-alpine As production
# Copy the bundled code to the production image
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist
# Start the server using the production build
CMD [ "node", "dist/main.js" ]