-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (79 loc) · 2.83 KB
/
Dockerfile
File metadata and controls
112 lines (79 loc) · 2.83 KB
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
# Global variables
ARG COMMIT=""
ARG APP_USER=pcgldaco
ARG WORKDIR=/app
#######################################################
# Configure Base Image
#######################################################
FROM node:22-alpine AS base
ARG APP_USER
ARG WORKDIR
RUN apk update
RUN apk add --no-cache libc6-compat
# # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# RUN apk add --no-cache libc6-compat
# # install pnpm as root user, before updating node ownership
# RUN npm i -g pnpm
# Create non-root user
ENV APP_UID=9999
ENV APP_GID=9999
RUN addgroup -S -g $APP_GID ${APP_USER} \
&& adduser -S -u $APP_UID -g $APP_GID ${APP_USER}
RUN mkdir -p ${WORKDIR} \
&& chown -R ${APP_USER}:${APP_USER} ${WORKDIR}
# Enables pnpm
RUN corepack enable
WORKDIR ${WORKDIR}
USER ${APP_USER}:${APP_USER}
COPY --chown=${APP_USER}:${APP_USER} . ./
RUN pnpm install --ignore-scripts --frozen-lockfile
RUN pnpm build:all
#######################################################
# UI Server
#######################################################
FROM nginx:1.27-alpine-slim as daco-ui
ARG APP_USER
ARG WORKDIR
ARG DACO_UI_DIR=${WORKDIR}/apps/ui
# Create non-root user
ENV APP_UID=9999
ENV APP_GID=9999
RUN addgroup -S -g $APP_GID ${APP_USER} \
&& adduser -S -u $APP_UID -g $APP_GID ${APP_USER}
# Modify permissions on nginx for our new user
RUN chown -R ${APP_USER}:${APP_USER} /var/cache/nginx && \
chown -R ${APP_USER}:${APP_USER} /etc/nginx/ && \
chmod -R 755 /etc/nginx/ && \
chown -R ${APP_USER}:${APP_USER} /var/log/nginx
RUN mkdir -p /etc/nginx/ssl/ && \
chown -R ${APP_USER}:${APP_USER} /etc/nginx/ssl/ && \
chmod -R 755 /etc/nginx/ssl/
RUN touch /var/run/nginx.pid && \
chown -R ${APP_USER}:${APP_USER} /var/run/nginx.pid /run/nginx.pid
RUN chown -R ${APP_USER}:${APP_USER} /docker-entrypoint.d && \
chown -R ${APP_USER}:${APP_USER} /usr/share/nginx/html
# Switch to new user
USER ${APP_USER}
# Copy the runtime environmental variable replacement script
COPY --from=base ${DACO_UI_DIR}/docker/replace-env-script.sh /docker-entrypoint.d/replace-env-script.sh
RUN chmod +x /docker-entrypoint.d/replace-env-script.sh
# Copy site and nginx config
COPY --from=base ${DACO_UI_DIR}/dist /usr/share/nginx/html
COPY --from=base ${DACO_UI_DIR}/docker/nginx.conf.template /etc/nginx/templates/nginx.conf.template
RUN rm -f /etc/nginx/conf.d/default.conf
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
#######################################################
# DACO API
#######################################################
FROM base as daco-api
ARG APP_USER
ARG WORKDIR
ARG BUILDER_APP_DIR=${WORKDIR}/apps/api
USER ${APP_USER}
ENV NODE_ENV=production
ENV PORT=3000
EXPOSE 3000
WORKDIR ${BUILDER_APP_DIR}
CMD ["pnpm", "start:prod"]