Merge pull request #463 from samalba/fetchgit-features
Fetchgit features
This commit is contained in:
commit
78dbb64e6a
@ -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
|
||||
}
|
||||
|
||||
|
@ -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: {
|
||||
|
@ -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_success
|
||||
|
||||
# FIXME: distinguish missing inputs from incorrect config
|
||||
# run "$DAGGER" compute "$TESTDIR"/ops/fetch-git/invalid
|
||||
# assert_failure
|
||||
|
35
tests/ops/fetch-git/gitdir/main.cue
Normal file
35
tests/ops/fetch-git/gitdir/main.cue
Normal 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
|
||||
}
|
||||
},
|
||||
]
|
Reference in New Issue
Block a user