From a96ad91e0f28c788e291dd04b9e9fb9d17e61fe0 Mon Sep 17 00:00:00 2001 From: Basti Ortiz <39114273+BastiDood@users.noreply.github.com> Date: Tue, 6 Aug 2024 01:04:33 +0800 Subject: [PATCH] refactor(docker): separate install step from source copy --- Dockerfile | 22 +++++++++++++--------- fly.toml | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 99097ed..ceb14dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,24 @@ # syntax=docker/dockerfile:1.7-labs - -# https://pnpm.io/docker -FROM node:22.5.1-alpine3.20 AS base +FROM node:22.5.1-alpine3.20 AS build ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable pnpm WORKDIR /drap -COPY . . -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile - -FROM base AS build +COPY pnpm-lock.yaml ./ +RUN pnpm fetch +COPY . ./ +RUN pnpm install --recursive --offline RUN pnpm --parallel --recursive build RUN pnpm --filter=drap-email --prod deploy /prod/email RUN pnpm --filter=drap-app --prod deploy /prod/app FROM node:22.5.1-alpine3.20 AS deploy -COPY --from=build /prod /prod +COPY --from=build /prod/ /drap/ EXPOSE 3000 -CMD tail -f /dev/null + +# This is the command to start the SvelteKit server. The background email worker +# should be spawned as a separate process somehow. When deploying to Fly.io +# (see the fly.toml), we use Process Groups to spawn both the main SvelteKit +# server and the email worker at the same time. For the sake of supplying a +# # default entry point, the following `CMD` starts the SvelteKit server. +CMD ["node", "/prod/app/build/index.js"] diff --git a/fly.toml b/fly.toml index 3fa58dd..5c6c3c9 100644 --- a/fly.toml +++ b/fly.toml @@ -2,8 +2,8 @@ app = 'drap-app' primary_region = 'sin' [processes] -app = 'node /prod/app/build/index.js' -email = 'node --enable-source-maps /prod/email/dist/main.js' +app = 'node /drap/app/build/index.js' +email = 'node --enable-source-maps /drap/email/dist/main.js' [http_service] processes = ['app']