ported op.#FetchGit to engine.#GitPull

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones 2021-12-20 12:47:42 -07:00
parent 2531d17ea6
commit 7ca84282be
No known key found for this signature in database
GPG Key ID: CFB3A382EB166F4C
4 changed files with 98 additions and 2 deletions

80
plan/task/gitPull.go Normal file
View File

@ -0,0 +1,80 @@
package task
import (
"context"
"net/url"
"github.com/moby/buildkit/client/llb"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/plancontext"
"go.dagger.io/dagger/solver"
)
func init() {
Register("GitPull", func() Task { return &gitPullTask{} })
}
type gitPullTask struct {
}
func (c gitPullTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
remote, err := v.Lookup("remote").String()
if err != nil {
return nil, err
}
ref, err := v.Lookup("ref").String()
if err != nil {
return nil, err
}
remoteRedacted := remote
if u, err := url.Parse(remote); err == nil {
remoteRedacted = u.Redacted()
}
gitOpts := []llb.GitOption{}
var opts struct {
KeepGitDir bool
}
if err := v.Decode(&opts); err != nil {
return nil, err
}
if opts.KeepGitDir {
gitOpts = append(gitOpts, llb.KeepGitDir())
}
// Secret
if authToken := v.Lookup("auth.token"); authToken.Exists() {
authTokenSecret, err := pctx.Secrets.FromValue(authToken)
if err != nil {
return nil, err
}
gitOpts = append(gitOpts, llb.AuthTokenSecret(authTokenSecret.ID()))
}
if authHeader := v.Lookup("auth.header"); authHeader.Exists() {
authHeaderSecret, err := pctx.Secrets.FromValue(authHeader)
if err != nil {
return nil, err
}
gitOpts = append(gitOpts, llb.AuthHeaderSecret(authHeaderSecret.ID()))
}
gitOpts = append(gitOpts, withCustomName(v, "FetchGit %s@%s", remoteRedacted, ref))
st := llb.Git(
remote,
ref,
gitOpts...,
)
result, err := s.Solve(ctx, st, pctx.Platform.Get())
if err != nil {
return nil, err
}
fs := pctx.FS.New(result)
return compiler.NewValue().FillFields(map[string]interface{}{
"contents": fs.MarshalCUE(),
})
}

View File

@ -12,10 +12,12 @@ package engine
// Pull a directory from a git remote
#GitPull: {
@dagger(notimplemented)
$dagger: task: _name: "GitPull"
remote: string
ref: string
auth: {
token?: #Secret
header?: #Secret
}
output: #FS
}

View File

@ -93,3 +93,7 @@ setup() {
"$DAGGER" --europa up ./scratch.cue -l debug
}
@test "task: #GitPull" {
cd "$TESTDIR"/tasks/gitPull/
"$DAGGER" --europa up ./exists.cue
}

View File

@ -0,0 +1,10 @@
package main
import "alpha.dagger.io/europa/dagger/engine"
engine.#Plan & {
actions: gitPull: engine.#GitPull & {
remote: "https://github.com/blocklayerhq/acme-clothing.git"
ref: "master"
}
}