55 lines
2.2 KiB
Docker
55 lines
2.2 KiB
Docker
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.
|
|
RUN apk add --no-cache libc6-compat
|
|
RUN corepack enable && corepack prepare --activate
|
|
|
|
## 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
|
|
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
|
|
|
|
## 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
|
|
|
|
WORKDIR /app
|
|
|
|
FROM base AS build
|
|
## Copy the manifests and lockfiles into the build context
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc .
|
|
COPY ./services/capture/package.json ./services/capture/pnpm-lock.yaml ./services/capture/
|
|
COPY ./packages/types/package.json ./packages/types/pnpm-lock.yaml ./packages/types/
|
|
COPY ./packages/utils/package.json ./packages/utils/pnpm-lock.yaml ./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 --prefer-offline
|
|
|
|
## Copy in all project files
|
|
COPY ./services/capture/ ./services/capture/
|
|
COPY ./packages/types/ ./packages/types/
|
|
COPY ./packages/utils/ ./packages/utils/
|
|
|
|
## 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
|
|
|
|
|
|
|
|
FROM build AS dev
|
|
WORKDIR /app/services/capture
|
|
ENTRYPOINT ["pnpm", "run", "dev"]
|
|
|
|
|
|
## start the app with dumb init to spawn the Node.js runtime process
|
|
## with signal support
|
|
## The mode @futureporn/capture uses when starting is determined by FUNCTION environment variable. (worker|api)
|
|
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" ] |