-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
63 lines (50 loc) · 1.87 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
ARG DATABASE_HOST=localhost DATABASE_PORT=27017 DATABASE_NAME=top-contributors HOST=localhost PORT=8080 USER=node TLS_ENABLED=true CA_PATH='/certificates/do-mongodb-ca-certificate.crt' NODE_ENV=development GITHUB_ACCESS_TOKEN=apikey
###########
# BUILDER #
###########
FROM node:18-alpine3.18 AS builder
# pass the global args
ARG GITHUB_ACCESS_TOKEN
ARG NODE_ENV
ARG HOST
ARG PORT
ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
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} GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN}
RUN npm install
###########
# PROJECT #
###########
FROM node:18-slim
# pass the global args
ARG GITHUB_ACCESS_TOKEN
ARG NODE_ENV
ARG HOST
ARG PORT
ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
ARG TLS_ENABLED
ARG CA_PATH
ARG USER
# copy builder output to project workdir
WORKDIR /app
COPY --from=builder --chown=${USER}:${USER} /workspace/models /app/models
COPY --from=builder --chown=${USER}:${USER} /workspace/utils /app/utils
COPY --from=builder --chown=${USER}:${USER} /workspace/server.js /app/server.js
COPY --from=builder --chown=${USER}:${USER} /workspace/node_modules /app/node_modules
COPY --from=builder --chown=${USER}:${USER} /workspace/package.json /app/
COPY --from=builder --chown=${USER}:${USER} /workspace/lists /app/lists
# 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} GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN}
# set user context
USER ${USER}
EXPOSE ${PORT}
CMD [ "npm", "run", "start" ]