Dockerfile.lerna 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # The aim for the base image here is to only keep package*.json files while having the
  2. # same directory structure to be able to have lerna dependencies installed once and cached
  3. # as long as the package*.json files have not changed. In the future, we can further optimize
  4. # it by creating slim package files that only contain *dependencies and name keys.
  5. FROM node:18.13.0@sha256:d9061fd0205c20cd47f70bdc879a7a84fb472b822d3ad3158aeef40698d2ce36 as base
  6. WORKDIR /home/node
  7. COPY --chown=1000:1000 ./ ./
  8. # Remove files that are not json packages
  9. RUN find . -type f ! -name 'package*.json' -delete
  10. # Remove directories that are empty now
  11. RUN find . -type d -empty -delete
  12. COPY ./lerna.json ./
  13. COPY ./tsconfig.base.json ./
  14. FROM node:18.13.0@sha256:d9061fd0205c20cd47f70bdc879a7a84fb472b822d3ad3158aeef40698d2ce36 as lerna
  15. # 1000 is the uid and gid of the node user
  16. USER 1000
  17. RUN mkdir -p /home/node/.npm
  18. RUN mkdir -p /home/node/node_modules
  19. WORKDIR /home/node
  20. COPY --from=base --chown=1000:1000 /home/node ./
  21. RUN --mount=type=cache,uid=1000,gid=1000,id=lerna,target=/home/node/.npm \
  22. --mount=type=cache,uid=1000,gid=1000,id=lerna,target=/home/node/node_modules \
  23. npm ci && cp -r node_modules node_modules_cache
  24. # Folders in the cache are not visible in the container that's why we copy
  25. # them and then move them back.
  26. RUN rm -rf node_modules && mv node_modules_cache node_modules