Merge pull request #463 from samalba/fetchgit-features

Fetchgit features
This commit is contained in:
Andrea Luzzardi 2021-05-13 15:15:32 -07:00 committed by GitHub
commit 78dbb64e6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"net" "net"
"net/url"
"path" "path"
"strings" "strings"
@ -762,6 +763,34 @@ func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value, st llb.Stat
return st, err return st, err
} }
remoteRedacted := remote
if u, err := url.Parse(remote); err == nil {
remoteRedacted = u.Redacted()
}
gitOpts := []llb.GitOption{}
var opts struct {
AuthTokenSecret string
AuthHeaderSecret string
KeepGitDir bool
}
if err := op.Decode(&opts); err != nil {
return st, err
}
if opts.KeepGitDir {
gitOpts = append(gitOpts, llb.KeepGitDir())
}
if opts.AuthTokenSecret != "" {
gitOpts = append(gitOpts, llb.AuthTokenSecret(opts.AuthTokenSecret))
}
if opts.AuthHeaderSecret != "" {
gitOpts = append(gitOpts, llb.AuthTokenSecret(opts.AuthHeaderSecret))
}
gitOpts = append(gitOpts, llb.WithCustomName(p.vertexNamef("FetchGit %s@%s", remoteRedacted, ref)))
// FIXME: Remove the `Copy` and use `Git` directly. // FIXME: Remove the `Copy` and use `Git` directly.
// //
// Copy'ing is a costly operation which should be unnecessary. // Copy'ing is a costly operation which should be unnecessary.
@ -771,12 +800,12 @@ func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value, st llb.Stat
llb.Git( llb.Git(
remote, remote,
ref, ref,
llb.WithCustomName(p.vertexNamef("FetchGit %s@%s", remote, ref)), gitOpts...,
), ),
"/", "/",
"/", "/",
), ),
llb.WithCustomName(p.vertexNamef("FetchGit %s@%s [copy]", remote, ref)), llb.WithCustomName(p.vertexNamef("FetchGit %s@%s [copy]", remoteRedacted, ref)),
), nil ), nil
} }

View File

@ -80,6 +80,10 @@ package op
do: "fetch-git" do: "fetch-git"
remote: string remote: string
ref: string ref: string
keepGitDir?: bool
// FIXME: the two options are currently ignored until we support buildkit secrets
authTokenSecret?: string | bytes
authHeaderSecret?: string | bytes
} }
#Copy: { #Copy: {

View File

@ -105,6 +105,9 @@ setup() {
run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/nonexistent/bork run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/nonexistent/bork
assert_failure assert_failure
run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/gitdir
assert_success
# FIXME: distinguish missing inputs from incorrect config # FIXME: distinguish missing inputs from incorrect config
# run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/invalid # run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/invalid
# assert_failure # assert_failure

View File

@ -0,0 +1,35 @@
package testing
import "dagger.io/dagger/op"
repo1: #up: [
op.#FetchGit & {
remote: "https://github.com/blocklayerhq/acme-clothing.git"
ref: "master"
},
]
repo2: #up: [
op.#FetchGit & {
remote: "https://github.com/blocklayerhq/acme-clothing.git"
ref: "master"
keepGitDir: true
},
]
#up: [
op.#FetchContainer & {
ref: "alpine"
},
op.#Exec & {
args: ["sh", "-c", """
set -eu
[ ! -d /repo1/.git ]
[ -d /repo2/.git ]
"""]
mount: {
"/repo1": from: repo1
"/repo2": from: repo2
}
},
]