-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
112 lines (82 loc) · 2.89 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
# ------------------------------------------------------------------------------
# nginx Redirect
# ------------------------------------------------------------------------------
FROM nginx:1.23.3-alpine-slim AS redirect
COPY script/redirect /usr/local/bin/
RUN chmod +x /usr/local/bin/redirect
EXPOSE 80
CMD ["redirect"]
# ------------------------------------------------------------------------------
# Base
# ------------------------------------------------------------------------------
FROM node:20-alpine as base
ENV APP_HOME /srv/app
ENV DEPS_HOME /deps
ENV TEST_HOME /srv/test
ARG NODE_ENV
ENV NODE_ENV ${NODE_ENV:-production}
# ------------------------------------------------------------------------------
# Base
# ------------------------------------------------------------------------------
FROM node:20 as full
ENV APP_HOME /srv/app
ENV DEPS_HOME /deps
ENV TEST_HOME /srv/test
ARG NODE_ENV
ENV NODE_ENV ${NODE_ENV:-production}
# ------------------------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------------------------
FROM base AS dependencies
RUN mkdir -p ${DEPS_HOME}
WORKDIR $DEPS_HOME
COPY package.json $DEPS_HOME/package.json
COPY package-lock.json $DEPS_HOME/package-lock.json
RUN npm ci
# ------------------------------------------------------------------------------
# Web
# ------------------------------------------------------------------------------
FROM base AS web
COPY --from=dependencies ${DEPS_HOME}/package.json ${APP_HOME}/package.json
COPY --from=dependencies ${DEPS_HOME}/package-lock.json ${APP_HOME}/package-lock.json
COPY --from=dependencies ${DEPS_HOME}/node_modules ${APP_HOME}/node_modules
ARG current_sha
ARG time_of_build
ENV CURRENT_SHA=$current_sha
ENV TIME_OF_BUILD=$time_of_build
RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
COPY . ${APP_HOME}
RUN if [ "$NODE_ENV" = "production" ]; then \
npm run build:assets:prod && \
npm run build; \
else \
npm run build:assets && \
npm run build; \
fi
EXPOSE 3000
ENTRYPOINT [ "./docker-entrypoint.sh" ]
CMD ["node", "dist/main"]
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
FROM full AS test
RUN mkdir -p ${TEST_HOME}
WORKDIR ${TEST_HOME}
RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb
COPY --from=dependencies ${DEPS_HOME}/package.json ${TEST_HOME}/package.json
COPY --from=dependencies ${DEPS_HOME}/package-lock.json ${TEST_HOME}/package-lock.json
COPY --from=dependencies ${DEPS_HOME}/node_modules ${TEST_HOME}/node_modules
COPY --from=dependencies /root/.cache/Cypress /root/.cache/Cypress
COPY --from=web ${APP_HOME} ${TEST_HOME}