Skip to content

Commit

Permalink
Add patch for buildkit to fetch by commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yosifkit authored and tianon committed Jun 25, 2024
1 parent 2fe0dfe commit eb12897
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions buildkit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.14.1
COPY \
backport-5072-fetch-tags.patch \
containerd-arm64-v8.patch \
git-fetch-by-commit.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
Expand Down
1 change: 1 addition & 0 deletions buildkit/Dockerfile.0.13
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.13.2
COPY \
backport-5072-fetch-tags.patch \
containerd-arm64-v8.patch \
git-fetch-by-commit.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
Expand Down
1 change: 1 addition & 0 deletions buildkit/Dockerfile.rc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.14.0-rc2
COPY \
backport-5072-fetch-tags.patch \
containerd-arm64-v8.patch \
git-fetch-by-commit.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
Expand Down
1 change: 1 addition & 0 deletions buildkit/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY \
backport-5072-fetch-tags.patch \
{{ ) else "" end -}}
containerd-arm64-v8.patch \
git-fetch-by-commit.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
Expand Down
20 changes: 20 additions & 0 deletions buildkit/git-fetch-by-commit.patch
Original file line number Diff line number Diff line change
@@ -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
+ }
}
}

0 comments on commit eb12897

Please sign in to comment.