-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (39 loc) · 1.47 KB
/
Dockerfile
File metadata and controls
55 lines (39 loc) · 1.47 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
# Stage: base image
FROM ghcr.io/ministryofjustice/hmpps-node:24-alpine AS base
ARG BUILD_NUMBER
ARG GIT_REF
ARG GIT_BRANCH
ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
WORKDIR /app
# Cache breaking and ensure required build / git args defined
RUN test -n "$BUILD_NUMBER" || (echo "BUILD_NUMBER not set" && false)
RUN test -n "$GIT_REF" || (echo "GIT_REF not set" && false)
RUN test -n "$GIT_BRANCH" || (echo "GIT_BRANCH not set" && false)
# Define env variables for runtime health / info
ENV BUILD_NUMBER=${BUILD_NUMBER}
ENV GIT_REF=${GIT_REF}
ENV GIT_BRANCH=${GIT_BRANCH}
# Stage: build assets
FROM base as build
ARG BUILD_NUMBER
ARG GIT_REF
ARG GIT_BRANCH
COPY package*.json .allowed-scripts.mjs .npmrc ./
RUN CYPRESS_INSTALL_BINARY=0 NPM_CONFIG_AUDIT=false NPM_CONFIG_FUND=false npm run setup
ENV NODE_ENV='production'
COPY . .
RUN --mount=type=secret,id=sentry SENTRY_AUTH_TOKEN=$(cat /run/secrets/sentry) \
npm run build
RUN npm prune --no-audit --omit=dev
# Stage: copy production assets and dependencies
FROM base
COPY --from=build --chown=appuser:appgroup /app/package.json /app/package-lock.json /app/technicalUpdates.json ./
COPY --from=build --chown=appuser:appgroup /app/assets ./assets
COPY --from=build --chown=appuser:appgroup /app/dist ./dist
COPY --from=build --chown=appuser:appgroup \
/app/node_modules ./node_modules
EXPOSE 3000 3001
ENV NODE_ENV='production'
USER 2000
CMD [ "npm", "start" ]