mempool/docker/backend/Dockerfile
Erik Arvstedt be72c5109a
backend: Create npm script package
This script creates a directory `backend/package` which only contains the
files required by the backend at runtime:
- The contents of `dist`
- `node_modules` minus `typescript` and `@typescript-eslint`.
  These packages are build-only and are larger than the remaining whole package.

By using only `backend/package` in the Docker image,
the backend content size in the image is decreased by 70% to 31M.
This, along with the improved copying in the Dockerfile, reduces the
backend image size by 44% to 200M.
(Step `RUN chown -R 1000:1000 /backend ...` created a layer that effectively
duplicated the backend.)
2022-09-02 12:50:43 +02:00

27 lines
554 B
Docker

FROM node:16.16.0-buster-slim AS builder
ARG commitHash
ENV DOCKER_COMMIT_HASH=${commitHash}
WORKDIR /build
COPY . .
RUN apt-get update
RUN apt-get install -y build-essential python3 pkg-config
RUN npm install --omit=dev --omit=optional
RUN npm run package
FROM node:16.16.0-buster-slim
WORKDIR /backend
RUN chown 1000:1000 ./
COPY --from=builder --chown=1000:1000 /build/package ./package/
COPY --from=builder --chown=1000:1000 /build/mempool-config.json /build/start.sh /build/wait-for-it.sh ./
USER 1000
EXPOSE 8999
CMD ["/backend/start.sh"]