medusa-stack-dockerized icon indicating copy to clipboard operation
medusa-stack-dockerized copied to clipboard

Build step in dockerfile

Open mifsudc opened this issue 1 year ago • 0 comments

medusa build outputs a standalone transpiled output, and isn't strictly required by medusa start, which serves straight from the typescript source files.

For production builds, if we want to minimize the size of the docker image we can update the dockerfile to use the transpiled output:

FROM node:20 AS builder

WORKDIR /app

COPY medusa-config.ts package.json yarn.lock ./

RUN yarn install

COPY . ./

RUN yarn build

WORKDIR /app/.medusa/server

RUN yarn install --production

FROM node:20-slim

WORKDIR /app

COPY --from=builder /app/.medusa/server ./

COPY ./docker-entrypoint.sh ./

RUN chmod +x ./docker-entrypoint.sh

ENTRYPOINT [ "./docker-entrypoint.sh" ]

CMD ["start"]

For non-development builds, or if we don't care about image size we can ignore it entirely:

FROM node:20-slim

WORKDIR /app

COPY docker-entrypoint.sh ./

RUN chmod +x ./docker-entrypoint.sh

COPY . ./

RUN yarn install

ENTRYPOINT ["./docker-entrypoint.sh"]

CMD ["develop"]

(My environment has a local medusa project, but you can sub the git clone in as required if no changes are required to the medusa setup)

mifsudc avatar Dec 30 '24 06:12 mifsudc