-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
65 lines (53 loc) · 2.49 KB
/
dockerfile
File metadata and controls
65 lines (53 loc) · 2.49 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
# ---------------------------------------------------------------------------- #
# BASE IMAGE #
# ---------------------------------------------------------------------------- #
FROM node:20-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# Use pnpm
RUN corepack enable
# ---------------------------------------------------------------------------- #
# BUILD IMAGE #
# ---------------------------------------------------------------------------- #
FROM base AS build-base
COPY . /usr/src/app/
WORKDIR /usr/src/app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --ignore-scripts
# Build libs
RUN pnpm run -r --filter "./packages/**" build
# ---------------------------------------------------------------------------- #
# CLIENT #
# ---------------------------------------------------------------------------- #
# Build the client app
FROM build-base AS client-build
WORKDIR /usr/src/app
RUN pnpm run --filter "client" build
# Host the client app
FROM nginx:alpine AS client
# Remove default files
RUN rm -rf /usr/share/nginx/html/*
# Use custom nginx configuration
COPY --from=client-build /usr/src/app/apps/client/nginx.template.conf /etc/nginx/conf.d/config.template
# Copy app files
COPY --from=client-build /usr/src/app/apps/client/dist/put3/browser/ /usr/share/nginx/html
EXPOSE 80
# Set environment variables and restart nginx
CMD envsubst '${API_PATH} ${SOCKET_PATH}' < /usr/share/nginx/html/assets/config/env.template.json > /usr/share/nginx/html/assets/config/env.json && \
envsubst '${ACCESS_ORIGIN} ${SERVER_PORT}' < /etc/nginx/conf.d/config.template > /etc/nginx/conf.d/default.conf && \
nginx -g 'daemon off;'
# ---------------------------------------------------------------------------- #
# SERVER #
# ---------------------------------------------------------------------------- #
# Build the server app
FROM build-base AS server-build
WORKDIR /usr/src/app
RUN pnpm run --filter "server" build
RUN pnpm deploy --filter=server --prod /prod/server
# Host the server app
FROM base AS server
COPY --from=server-build /prod/server /prod/server
WORKDIR /prod/server
# Delete source files (typescript)
RUN rm -rf src
ENV NODE_ENV=production
EXPOSE 3000