Add Dofckerfile sveltekit node.md

This commit is contained in:
scambier 2024-12-12 13:22:26 +01:00
commit 584049dd9d

View File

@ -0,0 +1,32 @@
This Dockerfile maximizes layer caching through `pnpm fetch` and multi-step dependencies installation.
See https://pnpm.io/docker#example-3-build-on-cicd
```dockerfile
FROM node:22-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
# Fetch dependencies
FROM base AS install
COPY pnpm-lock.yaml ./
RUN pnpm fetch
COPY . .
# Install production dependencies
RUN pnpm install -r --offline --prod --frozen-lockfile
# Install dev dependencies (needed for the build step)
RUN pnpm install -r --offline --frozen-lockfile
# Build
ENV NODE_ENV=production
RUN pnpm build
ENTRYPOINT ["node", "build"]
EXPOSE 3000
```
You can safely clean with `docker builder prune --f` after that. It won't touch the cache.