-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
130 lines (97 loc) · 3.19 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
###############################################################################
FROM node:22.8.0-alpine3.20 AS base
RUN apk add --update --no-cache make \
&& apk upgrade --update --no-cache openssl libcrypto3 libssl3 # FIX CVE-2024-5535
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
###############################################################################
FROM base AS lint
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
RUN apk add --update --no-cache make nodejs npm \
&& apk add --update --no-cache yamllint \
&& npm install -g --ignore-scripts markdownlint-cli
# [!TIP] Use a bind-mount to "/app" to override following "copys"
# for lint and test against "current" sources in this stage
# YAML sources
COPY ./.github ${WORKDIR}/
COPY ./compose.yaml ${WORKDIR}/
# Markdown sources
COPY ./docs ${WORKDIR}/
COPY ./README.md ${WORKDIR}/
COPY ./LICENSE.md ${WORKDIR}/
COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/
# Code source
COPY ./src ${WORKDIR}/src
COPY ./package.json ${WORKDIR}/package.json
COPY ./package-lock.json ${WORKDIR}/package-lock.json
COPY ./tsconfig.json ${WORKDIR}/
COPY ./Makefile ${WORKDIR}/
# code linting conf
COPY ./.prettierrc ${WORKDIR}/
COPY ./.prettierignore ${WORKDIR}/
COPY ./.eslintrc ${WORKDIR}/
COPY ./.eslintignore ${WORKDIR}/
# markdownlint conf
COPY ./.markdownlint.yaml ${WORKDIR}/
# yamllint conf
COPY ./.yamllint ${WORKDIR}/
COPY ./.yamlignore ${WORKDIR}/
COPY ./.gitignore ${WORKDIR}/
# Dependencies
RUN npm ci --verbose --ignore-scripts
CMD ["make", "lint"]
###############################################################################
FROM base AS development
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
# Code source
COPY ./src ${WORKDIR}/src
COPY ./package.json ${WORKDIR}/package.json
COPY ./package-lock.json ${WORKDIR}/package-lock.json
COPY ./Makefile ${WORKDIR}/
COPY ./tsconfig.json ${WORKDIR}/tsconfig.json
COPY ./tsconfig.prod.json ${WORKDIR}/tsconfig.prod.json
# Dependencies
COPY --from=lint /app/node_modules ${WORKDIR}/node_modules
RUN ls -alh
# CMD []
###############################################################################
FROM development AS builder
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
RUN npm run build
CMD ["ls", "-alh"]
###############################################################################
### In testing stage, can't use USER, due permissions issue
## in github actions environment:
##
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
##
FROM development AS testing
ENV LOG_LEVEL=info
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
COPY ./jest.config.ts /app/jest.config.ts
RUN ls -alh
CMD ["make", "test"]
###############################################################################
### In production stage
## in the production phase, "good practices" such as
## WORKSPACE and USER are maintained
##
FROM base AS production
ENV NODE_ENV=production
ENV LOG_LEVEL=info
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}
COPY --from=builder /app/dist ${WORKDIR}/dist
COPY ./Makefile ${WORKDIR}/
COPY ./package.json ${WORKDIR}/package.json
COPY ./package-lock.json ${WORKDIR}/package-lock.json
RUN npm ci --verbose --omit=dev --omit=optional --ignore-scripts --no-cache \
&& ls -alh
USER node
CMD ["ls", "-alh"]