2

My question is very similar to this on:

Neither of these threads has arrived at a solution. Then I found this: https://medium.com/@xfor/yarn-workspaces-and-docker-39e30402b69b which advises that a multi-stage build be used like so:

FROM node:10-alpine as build

WORKDIR /usr/src/app

COPY package.json .
COPY yarn.lock .
COPY packages/shared ./packages/shared
COPY packages/api ./packages/api

RUN yarn install --pure-lockfile --non-interactive

WORKDIR /usr/src/app/packages/shared
RUN yarn build

WORKDIR /usr/src/app/packages/api
RUN yarn build

FROM node:10-alpine

WORKDIR /usr/src/app

COPY package.json .
COPY yarn.lock .

COPY --from=build /usr/src/app/packages/shared/package.json /usr/src/app/packages/shared/package.json
COPY --from=build /usr/src/app/packages/shared/dist /usr/src/app/packages/shared/dist

COPY --from=build /usr/src/app/packages/api/package.json /usr/src/app/packages/api/package.json
COPY --from=build /usr/src/app/packages/api/build /usr/src/app/packages/api/build

ENV NODE_ENV production

RUN yarn install --pure-lockfile --non-interactive --production

WORKDIR /usr/src/app/packages/api

CMD ["npm", "start"]

Unfortunately, I don't use yarn for managing my monorepo and my Dockerfile is located within the app level of the monorepo rather than at the root of the monorepo. I am using jazelle to manage my monorepo and was wondering if I would have to create a Dockerfile for each app at the root level.

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
reactor
  • 1,722
  • 1
  • 14
  • 34

0 Answers0