2024-07-23 02:59:41 +00:00
|
|
|
## d.mailbox.dockerfile
|
|
|
|
##
|
|
|
|
## @todo future improvement might be merging the dockerfiles for the various monorepo packages.
|
|
|
|
## this is not an easy task, so I'm not doing it right now.
|
|
|
|
## "make it work, make it right, make it fast" (in that order)
|
|
|
|
## Right now we are making things work with separate dockerfiles for each package.
|
|
|
|
## One thing to determine is build speed. If we're developing in Tilt and have to wait 20 minutes for the build to complete
|
|
|
|
## every time we change a file in any dependent package, then merging dockerfiles is not desirable.
|
|
|
|
## One of the slow parts of the docker build is copying all package directories into the build context.
|
|
|
|
## If we have a lot of packages, it takes a long time.
|
|
|
|
## I have yet to determine performance benchmarks, so it's unclear if merging dockerfiles is desirable.
|
|
|
|
##
|
|
|
|
## @todo another performance improvement would almost certainly be to move strapi, next, and similar packages from `packages/*` into `services/*`
|
|
|
|
## this way, when we're building the various @futureporn library-type packages, we don't have to filter and COPY the dependency packages one-by-one.
|
|
|
|
## instead, we add the entire `packages/*` directory and then move on to the next step.
|
|
|
|
|
|
|
|
FROM node:20 AS base
|
|
|
|
ENV PNPM_HOME="/pnpm"
|
|
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
|
|
WORKDIR /app
|
2024-08-31 10:42:28 +00:00
|
|
|
RUN corepack enable && corepack prepare pnpm@9.6.0 --activate
|
2024-07-23 02:59:41 +00:00
|
|
|
|
|
|
|
FROM base AS build
|
|
|
|
WORKDIR /app
|
2024-07-30 20:34:25 +00:00
|
|
|
RUN mkdir -p /app/services/mailbox && mkdir -p /prod/mailbox
|
2024-07-23 02:59:41 +00:00
|
|
|
|
|
|
|
## Copy manfiests, lockfiles, and configs into docker context
|
|
|
|
COPY package.json pnpm-lock.yaml .npmrc .
|
|
|
|
COPY ./packages/storage/pnpm-lock.yaml ./packages/storage/package.json ./packages/storage/
|
|
|
|
COPY ./packages/types/pnpm-lock.yaml ./packages/types/package.json ./packages/types/
|
|
|
|
COPY ./packages/utils/pnpm-lock.yaml ./packages/utils/package.json ./packages/utils/
|
2024-07-30 20:34:25 +00:00
|
|
|
COPY ./services/mailbox/pnpm-lock.yaml ./services/mailbox/package.json ./services/mailbox/
|
2024-07-23 02:59:41 +00:00
|
|
|
|
|
|
|
## Install npm packages
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --recursive --frozen-lockfile --prefer-offline
|
|
|
|
|
|
|
|
## Copy package code into docker context
|
|
|
|
COPY ./packages/storage/ ./packages/storage/
|
|
|
|
COPY ./packages/types/ ./packages/types/
|
|
|
|
COPY ./packages/utils/ ./packages/utils/
|
2024-07-30 20:34:25 +00:00
|
|
|
COPY ./services/mailbox/ ./services/mailbox/
|
2024-07-23 02:59:41 +00:00
|
|
|
|
|
|
|
## Transpile TS into JS
|
|
|
|
RUN pnpm --filter=@futureporn/mailbox build
|
|
|
|
# RUN pnpm -r build
|
|
|
|
|
|
|
|
## Copy all production code into one place
|
|
|
|
## `pnpm deploy` copies all dependencies into an isolated node_modules directory inside the target dir
|
|
|
|
## @see https://pnpm.io/cli/deploy
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm deploy --filter=@futureporn/mailbox --prod /prod/mailbox
|
|
|
|
|
|
|
|
|
|
|
|
FROM base AS mailbox
|
|
|
|
COPY --from=build /prod/mailbox .
|
|
|
|
RUN ls -la .
|
|
|
|
ENTRYPOINT ["pnpm", "start"]
|
|
|
|
|