From 612102bfaaf636720718f7666613018d99a76e93 Mon Sep 17 00:00:00 2001 From: Joseph Ferguson Date: Fri, 21 Jun 2024 17:16:59 -0700 Subject: [PATCH] Add patch for buildkit to fetch by commit --- buildkit/Dockerfile | 1 + buildkit/Dockerfile.0.13 | 1 + buildkit/Dockerfile.rc | 1 + buildkit/Dockerfile.template | 1 + buildkit/git-fetch-by-commit.patch | 20 ++++++++++++++++++++ 5 files changed, 24 insertions(+) create mode 100644 buildkit/git-fetch-by-commit.patch diff --git a/buildkit/Dockerfile b/buildkit/Dockerfile index 7a7b1c2890b3..1f742c005301 100644 --- a/buildkit/Dockerfile +++ b/buildkit/Dockerfile @@ -13,6 +13,7 @@ COPY \ backport-5372-sbom-args.patch \ backport-moby-48455-fix-riscv64-seccomp.patch \ containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.0.13 b/buildkit/Dockerfile.0.13 index 0c47fa43030b..fecbdd2692d2 100644 --- a/buildkit/Dockerfile.0.13 +++ b/buildkit/Dockerfile.0.13 @@ -16,6 +16,7 @@ COPY \ backport-5372-sbom-args.patch \ backport-moby-48455-fix-riscv64-seccomp.patch \ containerd-arm64-v8-pre-0.15.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le-pre-0.16.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.rc b/buildkit/Dockerfile.rc index 23c7ee401f0b..2e92389660a5 100644 --- a/buildkit/Dockerfile.rc +++ b/buildkit/Dockerfile.rc @@ -11,6 +11,7 @@ ENV BUILDKIT_VERSION 0.17.0-rc2 COPY \ containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.template b/buildkit/Dockerfile.template index 390909979381..c342ec281a41 100644 --- a/buildkit/Dockerfile.template +++ b/buildkit/Dockerfile.template @@ -30,6 +30,7 @@ COPY \ "backport-5372-sbom-args.patch": { until: "0.17" }, "backport-moby-48455-fix-riscv64-seccomp.patch": { until: "0.17" }, "containerd-arm64-v8.patch": { older: { "0.15": "containerd-arm64-v8-pre-0.15.patch" } }, + "git-fetch-by-commit.patch": { }, "git-no-submodules.patch": { }, "mips64le.patch": { older: { "0.16": "mips64le-pre-0.16.patch" } }, "noclip.patch": { }, diff --git a/buildkit/git-fetch-by-commit.patch b/buildkit/git-fetch-by-commit.patch new file mode 100644 index 000000000000..12428d9ce0e6 --- /dev/null +++ b/buildkit/git-fetch-by-commit.patch @@ -0,0 +1,20 @@ +Description: try fetching by commit, then regular fall back to deeper fetching +Forwarded: no + +diff --git a/source/git/source.go b/source/git/source.go +index d139942fc..700982bd6 100644 +--- a/source/git/source.go ++++ b/source/git/source.go +@@ -459,6 +459,12 @@ func (gs *gitSourceHandler) Snapshot(ctx context.Context, g session.Group) (out + // skip fetch if commit already exists + if _, err := git.Run(ctx, "cat-file", "-e", ref+"^{commit}"); err == nil { + doFetch = false ++ } else { ++ // try fetching commit directly ++ // TODO limit to known working git hosts? ++ if _, err := git.Run(ctx, "fetch", "origin", ref+":"); err == nil { ++ doFetch = false ++ } + } + } +