2024-07-23 02:59:41 +00:00
FROM node:20-alpine AS base
## Install dependencies only when needed
## Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
2024-05-27 22:20:58 +00:00
RUN apk add --no-cache libc6-compat
2024-08-31 10:42:28 +00:00
RUN corepack enable && corepack prepare pnpm@9.6.0 --activate
2024-05-27 22:20:58 +00:00
2024-07-23 02:59:41 +00:00
## Enable `pnpm add --global` on Alpine Linux by setting
## home location environment variable to a location already in $PATH
## https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235
2024-05-27 22:20:58 +00:00
ENV PNPM_HOME=/usr/local/bin
# update and install latest dependencies, add dumb-init package
# add a non root user
RUN apk update && apk upgrade && apk add dumb-init ffmpeg make gcc g++ python3
2024-07-23 02:59:41 +00:00
## install yt-dlp
RUN wget -O /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp && chmod +x /usr/local/bin/yt-dlp
2024-05-27 22:20:58 +00:00
2024-07-23 02:59:41 +00:00
WORKDIR /app
2024-05-27 22:20:58 +00:00
2024-07-23 02:59:41 +00:00
FROM base AS build
## Copy the manifests and lockfiles into the build context
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc .
2024-07-28 00:42:09 +00:00
COPY ./services/capture/package.json ./services/capture/pnpm-lock.yaml ./services/capture/
2024-07-23 02:59:41 +00:00
COPY ./packages/types/package.json ./packages/types/pnpm-lock.yaml ./packages/types/
COPY ./packages/utils/package.json ./packages/utils/pnpm-lock.yaml ./packages/utils/
2024-09-06 05:39:08 +00:00
COPY ./packages/fetchers/package.json ./packages/fetchers/pnpm-lock.yaml ./packages/fetchers/
2024-07-23 02:59:41 +00:00
## install npm packages
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch
2024-07-28 00:42:09 +00:00
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --recursive --prefer-offline
2024-07-23 02:59:41 +00:00
2024-07-28 00:42:09 +00:00
## Copy in all project files
COPY ./services/capture/ ./services/capture/
2024-07-23 02:59:41 +00:00
COPY ./packages/types/ ./packages/types/
COPY ./packages/utils/ ./packages/utils/
2024-09-06 05:39:08 +00:00
COPY ./packages/fetchers/ ./packages/fetchers/
2024-07-23 02:59:41 +00:00
## Run the build process and generate the artifacts
RUN pnpm run -r build
RUN mkdir -p /prod/capture
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --filter=@futureporn/capture deploy --prod /prod/capture
2024-07-28 00:42:09 +00:00
2024-07-23 02:59:41 +00:00
2024-08-01 19:16:35 +00:00
FROM build AS dev
WORKDIR /app/services/capture
ENTRYPOINT ["pnpm", "run", "dev"]
2024-07-23 02:59:41 +00:00
## start the app with dumb init to spawn the Node.js runtime process
## with signal support
2024-07-25 13:53:52 +00:00
## The mode @futureporn/capture uses when starting is determined by FUNCTION environment variable. (worker|api)
2024-07-23 02:59:41 +00:00
FROM base AS capture
ENV HOSTNAME=0.0.0.0 NODE_ENV=production
COPY --from=build /prod/capture .
CMD [ "dumb-init", "node", "dist/index.js" ]