From 27d47764f8d4b588571ba93398ef2b9c2de8bb98 Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Thu, 31 Jul 2025 23:15:51 -0400 Subject: [PATCH] vinxi cache in docker build --- .dockerignore | 1 - Dockerfile | 47 ++++++++++++++++++++++++++++++++++++++++------- Makefile | 7 ++++++- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.dockerignore b/.dockerignore index e3527bd..0085f56 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ node_modules Dockerfile Makefile -pnpm-lock.yaml README.md .output .vinxi diff --git a/Dockerfile b/Dockerfile index 6bb7f59..3590f18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,45 @@ +# === STAGE 1: Build & Dependencies === +FROM node:22 AS builder + +WORKDIR /app + +# Install pnpm and enable corepack +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Copy the lockfile and package.json to leverage caching +COPY package.json pnpm-lock.yaml ./ + +# Use a cache mount to persist the pnpm store across builds. +# The 'pnpm install' command will use this persistent cache. +RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \ + pnpm install --frozen-lockfile + +# Copy the rest of the application files +COPY . . + +# Use a second cache mount for the Vinxi build artifacts. +# This tells Docker to mount a persistent cache directory to a build-cache location. +# The `pnpm run build` command will now use this cache for incremental builds. +# We'll assume a `.vinxi` or `.cache` directory for this example. +RUN --mount=type=cache,target=/app/.vinxi \ + pnpm run build + +# === STAGE 2: Production Final Image === FROM node:22-alpine WORKDIR /app + +# Enable corepack and install only production dependencies +RUN corepack enable && corepack prepare pnpm@latest --activate +COPY package.json pnpm-lock.yaml ./ +# This install can also use the cache mount to avoid re-downloading +RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \ + pnpm install --frozen-lockfile --prod + +# Copy the compiled assets and lockfile from the builder stage +COPY --from=builder /app/.output ./.output +COPY --from=builder /app/package.json ./package.json + EXPOSE 3000 -COPY package.json ./ -RUN npm install - -COPY . . -RUN npm run build - -CMD ["npm", "run", "start"] +CMD ["pnpm", "start"] \ No newline at end of file diff --git a/Makefile b/Makefile index b1e9d84..3600cf1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,12 @@ SHELL := /bin/bash build: - docker build --platform linux/arm64 -t games . + sudo docker buildx build --load \ + --cache-from=type=local,src=/var/cache/docker-build \ + --cache-to=type=local,dest=/var/cache/docker-build \ + --platform linux/arm64 \ + --tag games . + start: sudo docker run -p $(PORT):3000 -t games