From 7d5dc58cd567d5675f58d41792ce7edd29c9cca1 Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Sun, 17 Nov 2024 10:53:38 -0500 Subject: [PATCH] add `Dockerfile` for deployment --- Dockerfile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..30fb81f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:22-slim AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable + + +# use Docker layers as the build cache instead of the local pnpm cache (I chose this method because this works in all environments, even ephemeral Github Actions VMs): +FROM base AS prod +WORKDIR /app +COPY pnpm-lock.yaml /app +RUN pnpm fetch --prod +COPY . /app +RUN pnpm run build + + +FROM base +WORKDIR /app +COPY --from=prod /app/node_modules /app/node_modules +COPY --from=prod /app/dist /app +EXPOSE 4321 +# set the host to 0.0.0.0 so that it can be accessed from outside the container (doesn't work without this, even with the `-p 4321:4321` docker option): +ENV HOST="0.0.0.0" +CMD [ "node", "server/entry.mjs" ] \ No newline at end of file