-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dockerfile
71 lines (63 loc) · 2.7 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
# This Dockerfile leverages multi-stage builds so
# only necessary build artifacts and resources are
# included in the final image.
# Define Angular major version used by the app, used to install
# corresponding Angular CLI globally.
ARG ANGULAR_MAJOR_VERSION=18
# Enable passing the tag of the Node.js image as a build argument,
# and define a default tag in case the build argument is not passed.
# The Node.js image is used as the base image of the app,
# https://hub.docker.com/_/node/.
ARG NODE_IMAGE_TAG=20-alpine
# 1. Create base image from official Node.js image.
FROM node:${NODE_IMAGE_TAG} AS base
# Change working directory.
WORKDIR /digital-edition-frontend-ng
# 2. Create intermediate build image, starting from base image.
FROM base AS build
# Redeclare ARG-variable to make it available in this stage.
ARG ANGULAR_MAJOR_VERSION
# Notify Docker that static browser content will be a volume,
# so it can be used by nginx. The volume should automatically
# be populated with the correct files from the image on first
# docker compose up. On recreating the container
# docker compose down --volumes needs to be run before
# running docker compose up since volumes are persistent and
# won't be replaced when images are updated.
VOLUME [ "/digital-edition-frontend-ng/dist/app/browser" ]
# Copy all files from the source folder to the
# workdir in the container filesystem.
COPY . .
# Install the Angular CLI globally.
RUN npm install -g @angular/cli@${ANGULAR_MAJOR_VERSION}
# Install app dependencies.
RUN npm install
# Run script that generates sitemap.txt.
RUN npm run generate-sitemap
# Run script that generates static html files for collection menus.
RUN npm run generate-static-collection-menus
# Build the Angular SSR app.
RUN npm run build:ssr
# Create precompressed versions of static files (dist/app/browser/).
RUN npm run compress
# 3. Create final image, starting from base image.
FROM base AS final
# Create a non-root user with a dedicated user group.
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy package.json and package-lock.json from the
# source folder to the workdir in the container filesystem.
COPY package.json package-lock.json ./
# Install production dependencies of the app only. This is
# necessary because proxy-server.js, which is outside the
# Angular build but runs the server, requires the 'express'
# module.
RUN npm install --omit=dev
# Copy the dist folder from the build image to the final,
# runtime image.
COPY --from=build /digital-edition-frontend-ng/dist /digital-edition-frontend-ng/dist
# Set NODE_ENV environment variable to production.
ENV NODE_ENV=production
# Switch to the non-root user before running the app.
USER appuser
# Run app.
CMD ["node","dist/app/proxy-server.js"]