-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
46 lines (31 loc) · 1.07 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
# Using multi stage build
ARG BASE_IMAGE="node:22.3.0-bookworm-slim"
#### Build stage for compiling Typescript files ####
FROM ${BASE_IMAGE} AS builder
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json .
# Install dev and app dependencies
RUN npm install
# Copy all files to current dir
COPY . .
# Run build to compile typescript to javascript in 'dist' folder
RUN npm run build
#### Build stage for running the Javascript in production ####
FROM ${BASE_IMAGE}
ENV NODE_ENV=production
# Install timezone database to allow setting timezone through TZ environment variable
RUN apt install tzdata
# Don’t run Node.js apps as root
USER node
# Create app directory
WORKDIR /usr/src/app
COPY --chown=node:node package*.json .
# Install app dependencies only
RUN CI=true npm install --omit=dev
# Copy compiled files from 'dist' directory to current
COPY --chown=node:node --from=builder /usr/src/app/dist .
CMD [ "node", "index.js" ]