From 471b5786718845c82ec2c5cc614ce4b764911531 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 13 May 2021 10:02:43 -0700 Subject: [PATCH 1/5] stdlib: #FetchGit extra args Signed-off-by: Sam Alba --- stdlib/dagger/op/op.cue | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stdlib/dagger/op/op.cue b/stdlib/dagger/op/op.cue index 43484781..b590160e 100644 --- a/stdlib/dagger/op/op.cue +++ b/stdlib/dagger/op/op.cue @@ -77,9 +77,13 @@ package op } #FetchGit: { - do: "fetch-git" - remote: string - ref: string + do: "fetch-git" + remote: string + ref: string + keepGitDir?: bool + // FIXME: the two options are currently ignored until we support buildkit secrets + authTokenSecret?: string | bytes + authHeaderSecret?: string | bytes } #Copy: { From 5692accf376787a9aed9afe56037a78b0f95b189 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 13 May 2021 10:33:15 -0700 Subject: [PATCH 2/5] implemented fetch-git buildkit options (keepdir and auth secrets) Signed-off-by: Sam Alba --- dagger/pipeline.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/dagger/pipeline.go b/dagger/pipeline.go index 27df448d..04b7d436 100644 --- a/dagger/pipeline.go +++ b/dagger/pipeline.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "net" + "net/url" "path" "strings" @@ -762,6 +763,34 @@ func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value, st llb.Stat 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. // // 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( remote, 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 } From 2d2c5a8fedc0e42ec4bc002b62dfab60ab1f407f Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 13 May 2021 10:33:31 -0700 Subject: [PATCH 3/5] tests: added tests for keepgitdir Signed-off-by: Sam Alba --- tests/ops/fetch-git/gitdir/main.cue | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/ops/fetch-git/gitdir/main.cue diff --git a/tests/ops/fetch-git/gitdir/main.cue b/tests/ops/fetch-git/gitdir/main.cue new file mode 100644 index 00000000..61fc0607 --- /dev/null +++ b/tests/ops/fetch-git/gitdir/main.cue @@ -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 + } + }, +] From 637c980c20d192ccb98fd1e2e96f49caad72707d Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 13 May 2021 12:36:13 -0700 Subject: [PATCH 4/5] tests: added missing test in ops.bats Signed-off-by: Sam Alba --- tests/ops.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ops.bats b/tests/ops.bats index 43faf285..1a17f134 100644 --- a/tests/ops.bats +++ b/tests/ops.bats @@ -105,6 +105,9 @@ setup() { run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/nonexistent/bork assert_failure + run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/gitdir + assert_failure + # FIXME: distinguish missing inputs from incorrect config # run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/invalid # assert_failure From 0dc63bb30e141cbb2684fb5663f3d1629a7b6c80 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 13 May 2021 12:45:51 -0700 Subject: [PATCH 5/5] tests: fixed test result Signed-off-by: Sam Alba --- tests/ops.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ops.bats b/tests/ops.bats index 1a17f134..943acdef 100644 --- a/tests/ops.bats +++ b/tests/ops.bats @@ -106,7 +106,7 @@ setup() { assert_failure run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/gitdir - assert_failure + assert_success # FIXME: distinguish missing inputs from incorrect config # run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/invalid