diff --git a/.dockerignore b/.dockerignore index 6962a17c..dc3d92a0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: CC0-1.0 -.git node_modules config lib diff --git a/Dockerfile b/Dockerfile index 8ddb8102..bdc966c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,24 @@ # # SPDX-License-Identifier: Apache-2.0 AND AFL-3.0 -# We can't use alpine anymore because crypto has rust deps. -FROM node:20-slim +FROM alpine/git:latest as git-stamp-stage COPY . /tmp/src +RUN cd /tmp/src && git describe > version.txt.tmp && mv version.txt.tmp version.txt + +FROM node:20-slim as build-stage +COPY . /tmp/src +COPY --from=git-stamp-stage /tmp/src/version.txt version.txt RUN cd /tmp/src \ - && yarn install --network-timeout 100000 \ + && yarn install --frozen-lockfile --network-timeout 100000 \ && yarn build \ - && mv lib/ /draupnir/ \ - && mv node_modules / \ - && mv draupnir-entrypoint.sh / \ - && mv package.json / \ - && mv version.txt / \ - && cd / \ - && rm -rf /tmp/* + && yarn install --frozen-lockfile --production --network-timeout 100000 + +FROM node:20-slim as final-stage +COPY --from=git-stamp-stage /tmp/src/version.txt version.txt +COPY --from=build-stage /tmp/src/lib/ /draupnir/ +COPY --from=build-stage /tmp/src/node_modules /node_modules +COPY --from=build-stage /tmp/src/draupnir-entrypoint.sh / +COPY --from=build-stage /tmp/src/package.json / ENV NODE_ENV=production ENV NODE_CONFIG_DIR=/data/config