1
0
mirror of https://github.com/moby/buildkit.git synced 2026-01-06 04:01:11 +03:00
Commit Graph

94 Commits

Author SHA1 Message Date
Justin Chadwell
7eb8713972 Merge pull request #4473 from jedevc/fix-git-sha-conflict 2023-12-13 19:48:57 +00:00
Justin Chadwell
6a8d2ca2bd git: ensure that pin matches checked-out commit
Previously, it was very possible for the CacheKey function to return a
sha key that was *not* the checked out commit.

There are two cases that I've encountered where this can happen:
- An annotated tag will have the pin of the tag, and not the underlying
  commit, which will be HEAD after the checkout.
- If multiple tags have the same path component (e.g. "mytag" and
  "abc/mytag") then the first alphabetical tag will be selected when (in
  this case "abc/mytag").

To avoid this kind of case, we can't just search for a single match in
the results for ls-remote. There's no way to filter for just an exact
match, so we need to scan through the output ourselves. Additionally, we
need to dereference the annotated tags by also selecting refs ending in
"^{}" - which have the commit that the tag points at.

Finally, I've improved the test suite around this to check that:
- The cache-key pin is equivalent to the checked out commit
- We can check out non-master branches
- That full ref syntax like "refs/heads/<branch-name>" and
  "refs/tags/<tag-name>" (or even "refs/<anything>") can be used.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-12-13 10:06:42 +00:00
Tonis Tiigi
8a2a3e83ec replace context.WithCancel with WithCancelCause
Keep stack traces for cancellation errors where possible.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:06 -08:00
Justin Chadwell
6e86128d07 git: add missing RedactCredentials call in cache description
It's possible for a git url to contain encoded credentials - even though
this practice is not recommended. For safety, we attempt to censor the
credentials before putting them into cache descriptions and error
messages.

However, we were previously missing one of these, and we would put an
uncensored git url into the git checkout snapshot cache ref description.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-11-07 10:38:41 +00:00
Justin Chadwell
9a51bb0ff1 git: use custom giturl type to preserve original remote
This resolves a regression introduced in
50e75e3565. In this previous patch, I'd
incorrectly assumed that scp-like URLs can express a subset of
"standard"-URLs and so we can always safely convert them for
consistency. This isn't true - the URL "git@example.com:foo" should be
resolved to the home directory of the host, however, the converted URL
"ssh://git@example.com/foo" will be resolved to the root of the host.

To resolve this, we need to not perform this conversion. However, we
also need preserve the behaviour of firm distinction between SCP and
normal URL types (so as to keep proper port parsing).

To do this, we add a new GitURL type to the gitutil package. This new
type contains all useful fields shared in common between the standard
libraries url package and our custom scp-style url parsing package. This
keeps the previous property of a single clean interface to all GitURLs,
while also ensuring that we preserve the original URL to pass to the Git
CLI (making sure we strip fragments out, which are used as
buildkit-level metadata).

As a side-effect of this, the client-side calling code for parsing
git urls is simplified (so we don't have to do fragment wrangling at
every call point).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-10-12 19:17:11 +01:00
Justin Chadwell
319130de80 test: git tag test should not sign tags
Co-authored-by: Alex Suraci <suraci.alex@gmail.com>

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-24 12:22:15 +01:00
Justin Chadwell
d34b2471cd git: centralize git cli operations
Move all of the git command line logic into a single object, inspired by
the object already in buildx.

The basic implemenation allows for configuring a git cli for a specific
repository, along with various authorization settings and custom
binaries. Commands can be run for that repository, and a few helpers are
provided for accessing data on it - more to come in the future
hopefully.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-24 12:22:15 +01:00
Justin Chadwell
50e75e3565 git: update parsing to clarify between scp-style urls
This should also resolve the ports parsing issue.

Co-authored-by: Aaron Lehmann <alehmann@netflix.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Justin Chadwell
a31379b74a chore: fix git freebsd to match file names
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-16 10:28:26 +01:00
Alex Suraci
6b27487fec source: make sources pluggable
Sources are a pretty neat extension point, except there are a few code
paths that hard-code against each type. This moves code around and
adjusts interfaces so that Source implementations are self-contained and
merely need to be registered with the source.Manager.

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2023-08-16 09:57:55 +01:00
Artem Khramov
c415d85fe0 FreeBSD port
Buildkit code is mostly generic enough to support FreeBSD, however
there are some quirks / infrastructural pieces that need to be
addressed for full support, to name some

-    contenthash.NewFromStat attempts to set Devmajor / Devminor for
    regular files, assuming that RDev is zero for regular
    files. Unlike on Linux, it's not the case for FreeBSD.

-    containerdexecutor.Run uses bind mounts for rootfs. Bind mounts
    are not supported in FreeBSD and we should use nullfs instead

-    There is no CI job to run tests on FreeBSD

-    Some dependencies weren't ported

This change ports buildkit to FreeBSD

Signed-off-by: Artem Khramov <akhramov@pm.me>
Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com>
2023-07-28 17:02:53 +03:00
Tonis Tiigi
e34d10d72d git: set umask without reexec
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-05-29 17:31:08 -07:00
CrazyMax
7ce3bfcca2 git: override the locale to ensure consistent output
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-02-08 12:50:50 +01:00
Justin Chadwell
3f706e5adc lint: add nolint:gosec comments where required
Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-10-26 12:46:40 +01:00
Tõnis Tiigi
b6dc269b5d Merge pull request #3195 from corhere/git-protocol-from-user
source/git: isolate git from local system
2022-10-19 11:23:43 -07:00
Cory Snider
b55e86e7f7 source/git: isolate git from local system
Prevent git commands we run from reading the user or system
configuration, or cloning submodules from the local filesystem.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-10-11 16:12:24 -04:00
Sebastiaan van Stijn
4a6fd2ace7 source/git: Snapshot(): use filepath.WalkDir
WalkDir is more performant as it doesn't perform an os.Lstat on every
visited file or directory.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-09 16:56:14 +02:00
Eng Zer Jun
be6501b654 test: use T.TempDir to create temporary test directory
This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `os.MkdirTemp`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-07-24 02:27:26 +08:00
Sebastiaan van Stijn
21e9e9641e Remove uses of deprecated io/ioutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-10 00:57:07 +01:00
Kohei Tokunaga
3b7422996a cache: Clean up temporary mount pool on restart
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2022-02-23 16:33:25 +09:00
Erik Sipsma
bb09f3c032 Improve progress output for merge+diff ops.
Now, when a merge or diff ref is unlazied, the progress will show up
under the vertex for the merge/diff ref. Additionally, any ancestors of
the op that also need to be unlazied as part of unlazying the merge/diff
will show status updates under its vertex in the progress.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-02-08 11:26:05 -08:00
Tõnis Tiigi
edfc3f0d89 Merge pull request #2570 from alexcb/fix-git-clone-tag
Add support for annotated git tags
2022-01-29 10:14:23 -08:00
Alex Couture-Beil
9e1a9d24e8 Add support for git tags
This fixes errors such as:

    error: cannot update ref 'refs/heads/v2.30.0': trying to write non-commit object 2d9685d47a7e516281aa093bf0cddc8aafa72448 to branch 'refs/heads/v2.30.0'

which occur when cloning a tag rather than branch.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2022-01-28 11:51:19 -08:00
Tonis Tiigi
ffce8218e3 keep buffer of logs to show on failure when regular logs are clipped
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-24 21:30:46 -08:00
coryb
397c98bdf8 fix panic from umask-git on invalid ref
If the ref is invalid we are seeing a panic from `umask-git` because
the error type is not always a unix.WaitStatus:
```
    #1 0.227 fatal: Not a valid object name 000111222333444555666777888999aaabbbcccd^{commit}
    #1 0.229 panic: interface conversion: interface {} is syscall.WaitStatus, not unix.WaitStatus
    #1 0.229
    #1 0.229 goroutine 1 [running]:
    #1 0.229 github.com/moby/buildkit/source/git.gitMain()
    #1 0.229 	/src/source/git/gitsource_unix.go:66 +0x27d
    #1 0.229 github.com/docker/docker/pkg/reexec.Init(...)
    #1 0.229 	/src/vendor/github.com/docker/docker/pkg/reexec/reexec.go:26
    #1 0.229 main.init.0()
    #1 0.229 	/src/cmd/buildkitd/main.go:76 +0xf6
    #1 0.633 fatal: reference is not a tree: 000111222333444555666777888999aaabbbcccd
    #1 0.635 panic: interface conversion: interface {} is syscall.WaitStatus, not unix.WaitStatus
    #1 0.635
    #1 0.635 goroutine 1 [running]:
    #1 0.635 github.com/moby/buildkit/source/git.gitMain()
    #1 0.635 	/src/source/git/gitsource_unix.go:66 +0x27d
    #1 0.635 github.com/docker/docker/pkg/reexec.Init(...)
    #1 0.635 	/src/vendor/github.com/docker/docker/pkg/reexec/reexec.go:26
    #1 0.635 main.init.0()
    #1 0.635 	/src/cmd/buildkitd/main.go:76 +0xf6
```

This is from trying to solve:
```
    llb.Git("https://github.com/moby/buildkit.git", "000111222333444555666777888999aaabbbcccd")
```

Signed-off-by: coryb <cbennett@netflix.com>
2022-01-03 15:59:26 -08:00
Tõnis Tiigi
fce4a32258 Merge pull request #2335 from sipsma/mergeop-impl
MergeOp
2021-11-18 11:52:15 -08:00
Erik Sipsma
d73e62f878 Add initial MergeOp implementation.
This consists of just the base MergeOp with support for merging LLB
results that include deletions using hardlinks as the efficient path
and copies as fallback.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-18 11:10:48 -08:00
Tõnis Tiigi
345c677b85 Merge pull request #2397 from tonistiigi/git-deterministic
git: make fetch with keep-git-dir more deterministic
2021-11-17 22:39:33 -08:00
Erik Sipsma
9321ec2f82 Refactor cache record mount cache.
This is mostly just preparation for merge-op. The existing
Extract method is updated to be usable for unlazying any type of refs
rather than just lazy blobs. The way views are created is simplified and
centralized in one location.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-17 11:02:16 -08:00
CrazyMax
54b8ff2fc8 go fmt: add //go:build
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-10-28 13:26:43 +02:00
Tonis Tiigi
28250bf74e git: make fetch with keep-git-dir more deterministic
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-10-05 23:59:33 -07:00
Tõnis Tiigi
509b73d91e Merge pull request #2356 from crazy-max/git-umask
Standard user umask for git process
2021-09-27 18:44:13 -07:00
CrazyMax
3f1152f657 Standard user umask for git process
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-09-27 20:10:19 +02:00
CrazyMax
5fcc94454f Generate and embed build sources
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-09-18 01:39:35 +02:00
CrazyMax
8bb242e7ac Refactor url redacting util
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-09-14 17:39:07 +02:00
Erik Sipsma
a9f1980ebb Refactor cache metadata interface.
There are a few goals with this refactor:
1. Remove external access to fields that no longer make sense and/or
   won't make sense soon due to other potential changes. For example,
   there can now be multiple blobs associated with a ref (for different
   compression types), so the fact that you could access the "Blob"
   field from the Info method on Ref incorrectly implied there was just
   a single blob for the ref. This is on top of the fact that there is
   no need for external access to blob digests.
2. Centralize use of cache metadata inside the cache package.
   Previously, many parts of the code outside the cache package could
   obtain the bolt storage item for any ref and read/write it directly.
   This made it hard to understand what fields are used and when. Now,
   the Metadata method has been removed from the Ref interface and
   replaced with getters+setters for metadata fields we want to expose
   outside the package, which makes it much easier to track and
   understand. Similar changes have been made to the metadata search
   interface.
3. Use a consistent getter+setter interface for metadata, replacing
   the mix of interfaces like Metadata(), Size(), Info() and other
   inconsistencies.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-08-25 19:15:09 +00:00
Morlay
18b49fd7dc refactor to use util/bklog instead of using logurs directly
Signed-off-by: Morlay <morlay.null@gmail.com>
2021-07-13 11:42:31 +08:00
Tonis Tiigi
fb32dad95b git: fix default branch detection
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-07-06 16:34:43 -07:00
Levi Harrison
ccc9f20895 Moved getDefaultBranch function to gitsource
It is my suspecion that the tests were failing on previous commits because of the lack of authentication and other stuff like that available in gitidentifier as compared to gitsource

Signed-off-by: Levi Harrison <levisamuelharrison@gmail.com>
2021-07-06 15:38:00 -07:00
Tõnis Tiigi
03af083def Merge pull request #2144 from thaJeztah/bump_golang
update to go 1.16
2021-06-08 10:30:33 -07:00
Sebastiaan van Stijn
22dd74ae93 update to go 1.16
This updates all occurrences of Go 1.13 to Go 1.16; also updated
the code that's used to redact credentials in URLs to use the Go
implementation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-02 00:31:57 +02:00
Tonis Tiigi
3bdb6b5159 git: support subdir component
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-05-19 22:13:04 -07:00
Alex Couture-Beil
5d2fd7eb45 Redact credentials from URLs before returning errors
this is to prevent errors such as

    failed to fetch remote https://user:password@github.com/user/private-repo-failure.git: exit status 128

from leaking the password; now it will be displayed like:

    failed to fetch remote https://user:xxxxx@non-existant-host/user/private-repo.git: exit status 128

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2021-04-28 10:39:15 -07:00
Pierre Fenoll
a471427331 Fix potential crash on nil value
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
2021-04-15 15:01:02 +02:00
Tonis Tiigi
5bf64293f8 git: set token only for main remote access
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-02-19 00:25:35 -08:00
Alex Couture-Beil
985bd6e7fb disable host key checking when none are given
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-11-12 19:26:24 -08:00
Alex Couture-Beil
92e89a3374 Fixes related to the PR
- back out changes to changing the git url
 - fix gid
 - ignore global ssh config option when specifying known hosts

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-11-12 17:32:29 -08:00
Alex Couture-Beil
486c5fd5c6 change ssh auth sock perms to 0700
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-11-11 08:20:33 -08:00
Alex Couture-Beil
f2c8eb177c Support cloning from non-standard git repos
- fixes assumption that ssh git clones must be via the `git` user.
- allows passing the SSH_AUTH_SOCK from the client to GitSource
- allows passing a known_host entry for ssh

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-11-10 15:55:17 -08:00
Tonis Tiigi
e3b05289d8 add session injection to remote loading
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:44 -08:00