@@ -4,23 +4,24 @@ RUN apk upgrade --no-cache --available
44
55# BUILDER: a container to build the service dist directory
66FROM 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
1211RUN curl --proto '=https' --tlsv1.2 -sSfL https://get.static-web-server.net | sed "s/cp -ax/cp -a/g" | sh
1312# build the service
1413WORKDIR /service
1514COPY package.json pnpm-lock.yaml ./
1615RUN pnpm install
1716COPY . .
18- RUN npm run build
17+ RUN pnpm run build
1918# create base package.json with just name and version
2019RUN jq '{name, version, type}' package.json > ./package.json.run
2120
2221# RUNNER: a container to run the service
2322FROM base AS runner
23+ # install pnpm via corepack
24+ RUN corepack enable && corepack prepare pnpm@10.26.0 --activate
2425RUN adduser -D appuser
2526WORKDIR /home/appuser
2627USER appuser
@@ -30,17 +31,19 @@ COPY --from=builder /service/dist/data-portal/browser ./dist
3031COPY --from=builder /usr/local/bin/static-web-server /usr/local/bin
3132# copy the base package.json with name and version
3233COPY --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
3835COPY 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
4239COPY data-portal.default.yaml .
4340COPY 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
4548ENTRYPOINT ["node" ]
4649CMD ["/home/appuser/run.mjs" ]
0 commit comments