Skip to content

Commit b7449cc

Browse files
authored
Improve production Dockerfile (#256)
1 parent 71c7ee0 commit b7449cc

File tree

3 files changed

+213
-139
lines changed

3 files changed

+213
-139
lines changed

Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ RUN apk upgrade --no-cache --available
44

55
# BUILDER: a container to build the service dist directory
66
FROM base AS builder
7-
# install pnpm
8-
RUN npm install --global corepack@0.32.0
9-
RUN corepack prepare pnpm@10.26.0 --activate
7+
# install pnpm via corepack
8+
RUN corepack enable && corepack prepare pnpm@10.26.0 --activate
109
# install static web server
11-
RUN apk add curl jq sudo which
10+
RUN apk add --no-cache curl jq sudo which
1211
RUN curl --proto '=https' --tlsv1.2 -sSfL https://get.static-web-server.net | sed "s/cp -ax/cp -a/g" | sh
1312
# build the service
1413
WORKDIR /service
1514
COPY package.json pnpm-lock.yaml ./
1615
RUN pnpm install
1716
COPY . .
18-
RUN npm run build
17+
RUN pnpm run build
1918
# create base package.json with just name and version
2019
RUN jq '{name, version, type}' package.json > ./package.json.run
2120

2221
# RUNNER: a container to run the service
2322
FROM base AS runner
23+
# install pnpm via corepack
24+
RUN corepack enable && corepack prepare pnpm@10.26.0 --activate
2425
RUN adduser -D appuser
2526
WORKDIR /home/appuser
2627
USER appuser
@@ -30,17 +31,19 @@ COPY --from=builder /service/dist/data-portal/browser ./dist
3031
COPY --from=builder /usr/local/bin/static-web-server /usr/local/bin
3132
# copy the base package.json with name and version
3233
COPY --from=builder /service/package.json.run ./package.json
33-
USER root
34-
# make some dirs and files writeable for the appuser
35-
RUN touch ./dist/config.js && chown appuser ./dist ./dist/config.js ./package.json
36-
USER appuser
3734
# install run script
3835
COPY run.js ./run.mjs
3936
# install dependencies for run script
40-
RUN npm install js-yaml
37+
RUN pnpm add --prod --no-cache js-yaml
4138
# install configuration files
4239
COPY data-portal.default.yaml .
4340
COPY sws.toml .
41+
USER root
42+
# remove npm, corepack, and pnpm to trim the image and avoid outdated dependencies
43+
RUN rm -rf /usr/local/lib/node_modules /home/appuser/.local/share/pnpm /home/appuser/.cache
44+
# make some dirs and files writeable for the appuser
45+
RUN touch ./dist/config.js && chown appuser ./dist ./dist/config.js ./package.json
46+
USER appuser
4447

4548
ENTRYPOINT ["node"]
4649
CMD ["/home/appuser/run.mjs"]

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "data-portal",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
@@ -26,11 +26,6 @@
2626
"packageManager": "pnpm@10.26.0",
2727
"type": "module",
2828
"private": true,
29-
"pnpm": {
30-
"overrides": {
31-
"glob": "^13.0.0"
32-
}
33-
},
3429
"dependencies": {
3530
"@angular/animations": "^21.0.5",
3631
"@angular/cdk": "^21.0.3",

0 commit comments

Comments
 (0)