From a7688242a21a40b73a479e8fb71282da137b7c9a Mon Sep 17 00:00:00 2001 From: Zhengchen Tao Date: Sun, 17 May 2026 00:35:15 +0800 Subject: [PATCH] build: NuGet cache mount + buildx registry cache Mirror the cache infra added to nas-auth (commit a1ecba3): - Dockerfile: `RUN --mount=type=cache,target=/root/.nuget/packages` for restore + publish, with syntax 1.6 directive. - workflow: cache-from/cache-to registry cache mode=max, so buildkit layer cache survives across CI runs (fresh buildkit per run otherwise). First run after this still pays full cost; each subsequent run should drop ~50% off dotnet restore. --- .gitea/workflows/build-image.yml | 4 ++++ Dockerfile | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-image.yml b/.gitea/workflows/build-image.yml index eb75846..02f1092 100644 --- a/.gitea/workflows/build-image.yml +++ b/.gitea/workflows/build-image.yml @@ -70,6 +70,10 @@ jobs: with: context: . push: true + # buildx 每次 CI 起新的 buildkit 实例,layer cache 默认会丢。用 registry + # 当跨 CI run 的缓存。mode=max 把所有中间层(含 NuGet restore 那层)都存。 + cache-from: type=registry,ref=git.zhengchentao.win/zhengchen.tao/obsidian-mcp:buildcache + cache-to: type=registry,ref=git.zhengchentao.win/zhengchen.tao/obsidian-mcp:buildcache,mode=max labels: | org.opencontainers.image.source=https://git.zhengchentao.win/zhengchen.tao/obsidian-mcp org.opencontainers.image.revision=${{ steps.meta.outputs.full_sha }} diff --git a/Dockerfile b/Dockerfile index 351c48e..2e15f25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.6 # ─── Stage 1: build ─────────────────────────────────────────────────────────── FROM mcr.microsoft.com/dotnet/sdk:10.0 AS builder @@ -5,11 +6,13 @@ WORKDIR /src # 先只复制 csproj,利用层缓存加速 restore COPY obsidian-mcp.csproj ./ -RUN dotnet restore obsidian-mcp.csproj +RUN --mount=type=cache,target=/root/.nuget/packages \ + dotnet restore obsidian-mcp.csproj # 复制全部源码并 publish COPY . . -RUN dotnet publish obsidian-mcp.csproj \ +RUN --mount=type=cache,target=/root/.nuget/packages \ + dotnet publish obsidian-mcp.csproj \ --configuration Release \ --no-restore \ --output /app/publish