fp/dockerfiles/scout.dockerfile

43 lines
1.8 KiB
Docker

FROM node:20 AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /app
RUN curl -s https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest | grep "browser_download_url.*yt-dlp_linux\"" | cut -d : -f 2,3 | tr -d "\"" | wget -q -O /usr/local/bin/yt-dlp -i - && chmod +x /usr/local/bin/yt-dlp
## @important If pnpm is downloading node during the build, that's a bandwidth-expensive mistake.
## Node already exists in the docker image at /usr/local/bin/node.
## We should use the node version that exists in the docker image.
## The only thing that should be downloaded by corepack is pnpm.
## The reason we explicitly set a pnpm version here is because we want to have pnpm cached.
## We haven't copied any .npmrc or package.json files at this point in the build, so corepack has no way of knowing which version to get.
## There might be a more optimal way of doing this that doesn't require syncing this version with the version in package.json
## but I'm not sure what that would look like.
##
## @important match the pnpm version between all pnpm workspace packages or multiple versions of pnpm will get installed (slow)
RUN corepack enable && corepack prepare pnpm@9.6.0 --activate
ENTRYPOINT ["pnpm"]
FROM base AS install
COPY pnpm-lock.yaml .npmrc package.json .
COPY ./services/scout/ ./services/scout/
COPY ./packages/types/ ./packages/types/
COPY ./packages/utils/ ./packages/utils/
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
FROM install AS build
RUN pnpm -r build
RUN pnpm deploy --filter=scout --prod /prod/scout
FROM install AS dev
WORKDIR /app/services/scout
CMD ["run", "dev"]
FROM base AS prod
COPY --from=build /prod/scout .
CMD ["run", "start"]