-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
75 lines (53 loc) · 1.9 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
66
67
68
69
70
71
72
73
74
75
## ===========================================================> The common stage
FROM node:20 AS base
ENV NODE_ENV=production
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
## Remove unnecessary files from `node_modules` directory
RUN ( wget -q -O /dev/stdout https://gobinaries.com/tj/node-prune | sh ) \
&& node-prune
## ======================================================> The build image stage
FROM base AS build
ENV NODE_ENV=development
COPY . .
## This step could install only the missing dependencies (ie., development deps ones)
## but there's no way to do that with this NPM version
RUN npm ci --only=production
## Compile the TypeScript source code
# RUN npm link
## =================================================> The production image stage
FROM node:20-alpine AS prod
ENV NODE_ENV=production
WORKDIR /app
## Copy required file to run the production application
COPY --from=base --chown=node:node /app/node_modules ./node_modules
COPY --from=base --chown=node:node /app/*.json ./
COPY --from=build --chown=node:node /app/src /app/src
# COPY --from=build --chown=node:node /app/sndevopscli.js /app/
RUN npm link
# COPY --from=build --chown=node:node /usr/local/lib/node_modules/sndevopscli /usr/local/bin/sndevopscli
## https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html
# RUN apk add --no-cache dumb-init
# RUN npm link
# RUN chmod +x sndevopscli.js
## Dropping privileges
USER node
## Running the app wrapped by the init system for helping on graceful shutdowns
CMD [ "sndevopscli" ]
# FROM node:20-alpine as builder
# # Create app directory
# WORKDIR /app
# ENV NODE_ENV=production
# COPY sndevopscli.js package*.json ./
# COPY . /app
# RUN npm ci --only=production
# FROM node:20-alpine
# WORKDIR /app
# COPY . .
# RUN npm install .
# RUN npm link
# RUN chmod +x sndevopscli.js
# RUN ln sndevopscli.js sndevopscli
# # USER node
# CMD [ "echo Get a command" ]