-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
89 lines (64 loc) · 2.02 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
88
89
# Stage: base image
ARG BUILD_NUMBER
ARG GIT_REF
FROM node:20.12-bookworm-slim as base
LABEL maintainer="HMPPS Digital Studio <info@digital.justice.gov.uk>"
ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
RUN addgroup --gid 2000 --system appgroup && \
adduser --uid 2000 --system appuser --gid 2000
WORKDIR /app
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl
# Stage: build assets
FROM base as build
ARG BUILD_NUMBER
ARG GIT_REF
RUN apt-get install -y make python3 wget gnupg gnupg1 gnupg2 \
&& rm -rf /var/lib/apt/lists/*
COPY package*.json ./
RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit
COPY . .
RUN npm run build
ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0}
ENV GIT_REF ${GIT_REF:-dummy}
RUN export BUILD_NUMBER=${BUILD_NUMBER} && \
export GIT_REF=${GIT_REF} && \
npm run record-build-info
RUN npm prune --no-audit --production
# Stage: copy production assets and dependencies
FROM base
ARG BUILD_NUMBER
ARG GIT_REF
ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0}
ENV GIT_REF ${GIT_REF:-dummy}
RUN apt-get update && \
apt-get upgrade -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
# Install AWS RDS Root cert
RUN mkdir -p /home/appuser/.postgresql \
&& curl https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem \
> /app/root.cert
COPY --from=build --chown=appuser:appgroup \
/app/package.json \
/app/package-lock.json \
/app/log.js \
./
COPY --from=build --chown=appuser:appgroup \
/app/build-info.json ./dist/build-info.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
COPY --from=build --chown=appuser:appgroup \
/app/migrations ./migrations
COPY --from=build --chown=appuser:appgroup \
/app/package.json ./dist/package.json
EXPOSE 3000
ENV NODE_ENV='production'
USER 2000
CMD [ "npm", "start" ]