Should a developer be able to create a docker artifact from a lerna monorepo in their development environment? Should a developer be able to create a docker artifact from a lerna monorepo in their development environment? docker docker

Should a developer be able to create a docker artifact from a lerna monorepo in their development environment?


We got a similar issue and here is what we did: Put the Dockerfile in the root of the monorepo (where the lerna.json locates).

The reason: You really treat the whole repo as a single source of truth, and you want any modification to the whole repo to be reflected in the docker image, so it makes less sense to have separate Dockerfiles for individual packages.

Dockerfile

FROM node:12.13.0SHELL ["/bin/bash", "-c"]RUN mkdir -p /appWORKDIR /app# Install app dependenciesCOPY package.json /app/package.jsonCOPY yarn.lock /app/yarn.lockCOPY packages/frontend/package.json /app/packages/frontend/package.jsonCOPY packages/backend/package.json /app/packages/backend/package.jsonCOPY lerna.json /app/lerna.jsonRUN ["/bin/bash", "-c", "yarn install"]# Bundle app sourceCOPY . /appRUN ["/bin/bash", "-c", "yarn bootstrap"]RUN ["/bin/bash", "-c", "yarn build"]EXPOSE 3000CMD [ "yarn", "start" ]

package.json

{  "private": true,  "workspaces": [    "packages/*"  ],  "scripts": {    "bootstrap": "lerna clean --yes && lerna bootstrap",    "build": "lerna run build --stream",    "start": "cross-env NODE_ENV=production node dist/backend/main",  },  "devDependencies": {    "lerna": "^3.19.0",    "cross-env": "^6.0.3"  },}