fp/d.worker.dockerfile

75 lines
3.9 KiB
Plaintext
Raw Normal View History

2024-07-17 08:55:08 +00:00
## d.worker.dockerfile
##
2024-07-19 04:41:41 +00:00
## @futureporn/worker is the system component which runs background tasks.
## Tasks such as thumbnail generation, video encoding, file transfers, etc.
##
2024-07-17 08:55:08 +00:00
## 'temporal-worker' is already a pod name (temporal helm chart creates it for it's internal use)
## so our docker image is called fp/worker, not fp/temporal-worker
## not that we need to name the docker image differently, but
## the hope with this name is to keep the mental concept of the two pods separate by having different names
##
## @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.
2024-07-18 20:48:52 +00:00
FROM node:20 AS base
2024-07-14 05:20:35 +00:00
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /app
2024-07-17 08:55:08 +00:00
RUN corepack enable && corepack prepare pnpm@9.2.0 --activate
2024-07-14 05:20:35 +00:00
2024-07-18 20:48:52 +00:00
FROM base AS build
2024-07-17 08:55:08 +00:00
WORKDIR /app
RUN mkdir -p /app/packages/temporal-worker && mkdir -p /prod/temporal-worker
## Copy manfiests, lockfiles, and configs into docker context
COPY package.json pnpm-lock.yaml .npmrc .
COPY ./packages/image/pnpm-lock.yaml ./packages/image/package.json ./packages/image/
COPY ./packages/scout/pnpm-lock.yaml ./packages/scout/package.json ./packages/scout/
COPY ./packages/storage/pnpm-lock.yaml ./packages/storage/package.json ./packages/storage/
COPY ./packages/temporal-workflows/pnpm-lock.yaml ./packages/temporal-workflows/package.json ./packages/temporal-workflows/
COPY ./packages/temporal-worker/pnpm-lock.yaml ./packages/temporal-worker/package.json ./packages/temporal-worker/
COPY ./packages/types/pnpm-lock.yaml ./packages/types/package.json ./packages/types/
COPY ./packages/utils/pnpm-lock.yaml ./packages/utils/package.json ./packages/utils/
## 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
2024-07-14 05:20:35 +00:00
COPY ./packages/image/ ./packages/image/
2024-07-17 08:55:08 +00:00
COPY ./packages/scout/ ./packages/scout/
COPY ./packages/storage/ ./packages/storage/
2024-07-14 05:20:35 +00:00
COPY ./packages/temporal-workflows/ ./packages/temporal-workflows/
2024-07-17 08:55:08 +00:00
COPY ./packages/temporal-worker/ ./packages/temporal-worker/
COPY ./packages/types/ ./packages/types/
COPY ./packages/utils/ ./packages/utils/
2024-07-14 05:20:35 +00:00
2024-07-17 08:55:08 +00:00
## Transpile TS into JS
2024-07-18 20:48:52 +00:00
## we have to build @futureporn/image first because other packages depend on it's build js files
## next we have to build temporal-workflows because other packages depend on it's built js files
RUN pnpm --filter=@futureporn/image build
2024-07-17 08:55:08 +00:00
RUN pnpm --filter=@futureporn/temporal-workflows build
RUN pnpm --filter=!@futureporn/temporal-workflows -r build
2024-07-14 05:20:35 +00:00
2024-07-17 08:55:08 +00:00
## Deploy (copy all production code into one place)
RUN pnpm deploy --filter=@futureporn/temporal-worker --prod /prod/temporal-worker
2024-07-19 04:41:41 +00:00
RUN ls -lash /prod/temporal-worker
# RUN ls -lash /prod/temporal-worker/
2024-07-14 05:20:35 +00:00
2024-07-18 20:48:52 +00:00
FROM base AS worker
2024-07-14 05:20:35 +00:00
COPY --from=build /prod/temporal-worker .
2024-07-17 08:55:08 +00:00
RUN ls -la .
2024-07-14 05:20:35 +00:00
ENTRYPOINT ["pnpm", "start"]