From d3dca120f7d24cb303964d7807f0d906817f489b Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 31 Jan 2022 23:07:50 +0100 Subject: [PATCH] Implement modifications for engine.#Dockerfile tests, and fix lint errors Signed-off-by: guillaume --- pkg/dagger.io/dagger/engine/image.cue | 9 ++++----- plan/task/dockerfile.go | 21 +++++++++++++++------ tests/tasks/dockerfile/build_auth.cue | 8 +++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pkg/dagger.io/dagger/engine/image.cue b/pkg/dagger.io/dagger/engine/image.cue index dbd5d63a..990269d5 100644 --- a/pkg/dagger.io/dagger/engine/image.cue +++ b/pkg/dagger.io/dagger/engine/image.cue @@ -69,7 +69,7 @@ package engine // Authentication auth?: { username: string - secret: string | #Secret + secret: #Secret } // Root filesystem of downloaded image @@ -96,11 +96,10 @@ package engine } // Authentication - auth: [...{ - target: string + auth: [registry=string]: { username: string - secret: string | #Secret - }] + secret: #Secret + } platforms?: [...string] target?: string diff --git a/plan/task/dockerfile.go b/plan/task/dockerfile.go index 397da66e..1254114f 100644 --- a/plan/task/dockerfile.go +++ b/plan/task/dockerfile.go @@ -30,15 +30,24 @@ type dockerfileTask struct { func (t *dockerfileTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { lg := log.Ctx(ctx) - - // Read auth info - auth, err := decodeAuthValue(pctx, v.Lookup("auth")) + auths, err := v.Lookup("auth").Fields() if err != nil { return nil, err } - for _, a := range auth { - s.AddCredentials(a.Target, a.Username, a.Secret.PlainText()) - lg.Debug().Str("target", a.Target).Msg("add target credentials") + + for _, auth := range auths { + // Read auth info + a, err := decodeAuthValue(pctx, auth.Value) + if err != nil { + return nil, err + } + // Extract registry target from dest + target, err := solver.ParseAuthHost(auth.Label()) + if err != nil { + return nil, err + } + s.AddCredentials(target, a.Username, a.Secret.PlainText()) + lg.Debug().Str("target", target).Msg("add target credentials") } source, err := pctx.FS.FromValue(v.Lookup("source")) diff --git a/tests/tasks/dockerfile/build_auth.cue b/tests/tasks/dockerfile/build_auth.cue index 6f150143..897deebc 100644 --- a/tests/tasks/dockerfile/build_auth.cue +++ b/tests/tasks/dockerfile/build_auth.cue @@ -22,12 +22,10 @@ engine.#Plan & { build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - auth: [{ - target: "daggerio/ci-test:private-pull" + auth: "daggerio/ci-test:private-pull": { username: "daggertest" - - secret: sopsSecrets.output.DOCKERHUB_TOKEN.contents - }] + secret: sopsSecrets.output.DOCKERHUB_TOKEN.contents + } dockerfile: contents: """ FROM daggerio/ci-test:private-pull@sha256:c74f1b1166784193ea6c8f9440263b9be6cae07dfe35e32a5df7a31358ac2060 """