FROM node:12.7.0-alpine as node
RUN mkdir -p /usr/src/repo
ADD lerna.json /usr/src/repo/
ADD package.json \
yarn.lock \
.yarnrc \
/usr/src/repo/
ADD packages-jsons.tar.gz /usr/src/repo
WORKDIR /usr/src/repo
RUN yarn install --frozen-lockfile && yarn lerna bootstrap
# build steps
In order for all the *packages.json of all packages to be added to docker, we cant use ADD or COPY for multiple file as they don't support recreating unexisting paths like mkdir.
In my case we wanted to avoid using multiple ADD commands that generate a lote of intermediate images.
Another way is to generate a tar file that contains the package.json files and use the ADD command to extract it in the docker build phase.
GZIP=-n tar -czvf packages-jsons.tar.gz ./packages/*/package.json
The GZIP=-n
is nessasery here because normally gzip
would also include the timestamp for files. This will break the cache when doing docker ADD for the tar file.
You can see this when doing md5sum
check on the generate tar zip file. Each time a different hash because of the different zip file inside. When using the -n
option, the same hash.