forked from opengovsg/FormSG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.production
More file actions
59 lines (47 loc) · 2.5 KB
/
Dockerfile.production
File metadata and controls
59 lines (47 loc) · 2.5 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
# syntax=docker/dockerfile:1
ARG BUILD_BASE_IMAGE=ghcr.io/opengovsg/formsg:build-latest
ARG RUNTIME_BASE_IMAGE=ghcr.io/opengovsg/formsg:runtime-latest
# node-modules-builder stage installs/compiles the node_modules folder
# Build stage: node_modules already present in base image — just copy source and build
FROM ${BUILD_BASE_IMAGE} AS build
ARG APP_VERSION=""
ARG DD_RUM_APP_ID=""
ARG DD_RUM_CLIENT_TOKEN=""
WORKDIR /build
COPY . ./
# These options are only used in the build stage, not the start stage.
ENV NODE_OPTIONS="--max-old-space-size=4096"
ENV VITE_APP_VERSION=$APP_VERSION
ENV VITE_APP_DD_RUM_APP_ID=$DD_RUM_APP_ID
ENV VITE_APP_DD_RUM_CLIENT_TOKEN=$DD_RUM_CLIENT_TOKEN
RUN pnpm build
# Final stage: runtime deps and user already in base image
FROM ${RUNTIME_BASE_IMAGE}
LABEL maintainer=FormSG<form@open.gov.sg>
WORKDIR /opt/formsg
# Copy the built frontend dist for the backend to serve
COPY --from=build /build/apps/frontend/dist /opt/formsg/apps/frontend/dist
# Copy the built formsg-shared package and package.json for the backend to resolve
COPY --from=build /build/packages/shared/package.json /opt/formsg/packages/shared/
COPY --from=build /build/packages/shared/node_modules /opt/formsg/packages/shared/node_modules
COPY --from=build /build/packages/shared/dist /opt/formsg/packages/shared/dist
# Copy the built formsg-sdk package for the backend to resolve
COPY --from=build /build/packages/sdk/package.json /opt/formsg/packages/sdk/
COPY --from=build /build/packages/sdk/node_modules /opt/formsg/packages/sdk/node_modules
COPY --from=build /build/packages/sdk/cjs-entry.cjs /opt/formsg/packages/sdk/
COPY --from=build /build/packages/sdk/dist /opt/formsg/packages/sdk/dist
# Copy required node_modules, package.json scripts and built backend dist for the backend start script to run
COPY --from=build /build/pnpm-workspace.yaml /opt/formsg/pnpm-workspace.yaml
COPY --from=build /build/node_modules /opt/formsg/node_modules
COPY --from=build /build/package.json /opt/formsg/package.json
COPY --from=build /build/apps/backend/node_modules /opt/formsg/apps/backend/node_modules
COPY --from=build /build/apps/backend/package.json /opt/formsg/apps/backend/package.json
COPY --from=build /build/apps/backend/dist /opt/formsg/apps/backend/dist
# Run as non-privileged user (pre-created in runtime-base)
USER formsguser
ENV NODE_ENV=production
EXPOSE 4545
# tini is the init process that will adopt orphaned zombie processes
# e.g. chromium when launched to create a new PDF
ENTRYPOINT [ "tini", "--" ]
CMD [ "pnpm", "start" ]