-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
57 lines (45 loc) · 1.41 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
ARG DATABASE_HOST=localhost DATABASE_PORT=27017 DATABASE_NAME=top-contributors HOST=localhost PORT=8080 NODE_ENV=dev USER=node TLS_ENABLED=true CA_PATH='/certificates/do-mongodb-ca-certificate.crt'
###########
# BUILDER #
###########
FROM node:16-alpine3.14 AS builder
# pass the global args
ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
ARG PORT
ARG HOST
ARG NODE_ENV
ARG TLS_ENABLED
ARG CA_PATH
# copy build context and install dependencies
WORKDIR /workspace
COPY . .
# Inject the enviromental variables
ENV DATABASE_HOST=${DATABASE_HOST} DATABASE_PORT=${DATABASE_PORT} DATABASE_NAME=${DATABASE_NAME} PORT=${PORT} HOST=${HOST} NODE_ENV=${NODE_ENV} TLS_ENABLED=${TLS_ENABLED} CA_PATH=${CA_PATH}
RUN npm install
###########
# PROJECT #
###########
FROM node:16-slim
# pass the global args
ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
ARG PORT
ARG HOST
ARG NODE_ENV
ARG USER
ARG TLS_ENABLED
ARG CA_PATH
# copy builder output to project workdir
WORKDIR /app
COPY --from=builder /workspace /app
COPY --from=builder /workspace/node_modules /app/node_modules
COPY --from=builder /workspace/package.json /app/
# Inject the enviromental variables
ENV DATABASE_HOST=${DATABASE_HOST} DATABASE_PORT=${DATABASE_PORT} DATABASE_NAME=${DATABASE_NAME} PORT=${PORT} HOST=${HOST} NODE_ENV=${NODE_ENV} TLS_ENABLED=${TLS_ENABLED} CA_PATH=${CA_PATH}
# set user context
# USER ${USER}
EXPOSE ${PORT}
CMD [ "npm", "run", "start" ]