forked from m9sweeper/m9sweeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
87 lines (67 loc) · 2.39 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
#####################
## STAGE 1 - BUILD ##
#####################
FROM node:20.10-buster-slim as builder
# Install Python3 used in dependencies for building
RUN apt update && \
apt install -y python3 make
# BUILD BACK END
WORKDIR /usr/src/app/backend
COPY ./dash/backend/package.json /usr/src/app/backend
COPY ./dash/backend/package-lock.json /usr/src/app/backend
RUN mkdir /usr/src/app/backend/vendor
COPY ./dash/backend/vendor /usr/src/app/backend/vendor
RUN node --version && npm --version
RUN npm ci && \
chown -R root:root node_modules
COPY /dash/backend /usr/src/app/backend/
RUN npm run prebuild
RUN npm run build:prod:webpack
RUN npm prune --production
# manually install a couple npm packages
RUN rm -f node_modules/@nestjs-modules/mailer && rm -f node_modules/knexnest && \
cp -r vendor/nestjs-mailer node_modules/@nestjs-modules/mailer && \
cp -r vendor/knexnest node_modules/knexnest
# BUILD FRONT END
WORKDIR /usr/src/app/frontend
COPY ./dash/frontend/package.json /usr/src/app/frontend
COPY ./dash/frontend/package-lock.json /usr/src/app/frontend
COPY ./dash/frontend/vendor /usr/src/app/frontend/vendor
RUN npm ci && \
chown -R root:root node_modules
WORKDIR /usr/src/app
COPY ./dash/frontend /usr/src/app/frontend
WORKDIR /usr/src/app/frontend
RUN npm run build:prod
RUN npm prune --production
#########################
## Stage 2: Build Docs ##
#########################
FROM klakegg/hugo:0.111.3-ext-ubuntu as docs-builder
RUN git config --global --add safe.directory /src
WORKDIR /usr/src/
COPY ./docs/ /usr/src/
COPY ./.git /usr/src/.git
RUN hugo --config config-local.toml
######################
## Stage 3: DELIVER ##
######################
FROM node:20.10-alpine
# Make the app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/backend/dist /usr/src/app
COPY --from=builder /usr/src/app/backend/node_modules /usr/src/app/node_modules
COPY --from=builder /usr/src/app/backend/vendor /usr/src/app/vendor
COPY --from=docs-builder /usr/src/public /usr/src/app/public/docs
# Create non root user
RUN addgroup -g 1050 -S limitedaccessaccount && \
adduser -u 1050 -S limitedaccessaccount -G limitedaccessaccount && \
mkdir -p /usr/src/app/mnt/storage && \
chown -R limitedaccessaccount:limitedaccessaccount /usr/src/app
# Set non root user
USER 1050
# Expose the port the dashboard is on
EXPOSE 3000
# Start the server
CMD [ "node", "main" ]