From 5468f60e39483a3e9cd1a36f103ff3e579a16395 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 24 Jun 2021 11:42:34 +0200 Subject: [PATCH] Normalize reference to login on registry Signed-off-by: Tom Chauveau --- solver/registryauth.go | 11 +++++- stdlib/.dagger/env/docker-pull/values.yaml | 6 +-- stdlib/docker/docker.cue | 46 ++++++++++------------ 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/solver/registryauth.go b/solver/registryauth.go index 2c47d49c..1a51d322 100644 --- a/solver/registryauth.go +++ b/solver/registryauth.go @@ -6,6 +6,7 @@ import ( "strings" "sync" + "github.com/docker/distribution/reference" bkauth "github.com/moby/buildkit/session/auth" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -63,9 +64,15 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred } func parseAuthHost(host string) (*url.URL, error) { - isDockerHub := !(strings.Contains(host, "amazonaws.com") || strings.Contains(host, "gcr.io") || strings.Contains(host, "microsoft.com")) + if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") && strings.Contains(host, "/") { + ref, err := reference.ParseNormalizedNamed(host) + if err != nil { + return nil, err + } + host = ref.String() + } - if host == "registry-1.docker.io" || isDockerHub { + if strings.Contains(host, "docker.io") { host = "https://index.docker.io/v1/" } diff --git a/stdlib/.dagger/env/docker-pull/values.yaml b/stdlib/.dagger/env/docker-pull/values.yaml index 9637ece1..86e2fe33 100644 --- a/stdlib/.dagger/env/docker-pull/values.yaml +++ b/stdlib/.dagger/env/docker-pull/values.yaml @@ -3,7 +3,7 @@ plan: name: docker-pull inputs: ref: - text: docker.io/daggerio/ci-test:otnlnwqyyxlk@sha256:35fc94d52b4fa53c2caa38ff11e13182e6f88c651eb0846728d1007d931f0d3c + text: docker.io/daggerio/ci-test:xtyzsocvpici@sha256:35fc94d52b4fa53c2caa38ff11e13182e6f88c651eb0846728d1007d931f0d3c sops: kms: [] gcp_kms: [] @@ -19,8 +19,8 @@ sops: SG1raUVNTzZIWDltV1pOS3hySHlJeWcKg3blmstOGcxtPww513+mAEA0MWOXwNAT 5ngRvG6MraW3g9dhIuUYOwjuJyz1Z07/DBEocSxnjSyw45ZCkM1/9Q== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-18T19:57:47Z" - mac: ENC[AES256_GCM,data:dS7zAl28vERwDOh8OwNmVNrcZ10Ypibl7HylXnJ0+CBGCx3b0C6+/TNgytZFjhhjhOyJbioaTIA/Rra3Okz2Y1beJcP90CfixkIOQvpespIN6yh92SN6m1MbGQzWB0lURnVwHhLlOyIsDK5PaLcbW9mVhwiH4Y2otH+xRNO+8Ls=,iv:1vRlh02EFWYqu2q/AQeHDRcIJIiKxZAp7lspQmPybRI=,tag:0DcXYSoLMAJ/09ZunKkezg==,type:str] + lastmodified: "2021-06-24T09:36:46Z" + mac: ENC[AES256_GCM,data:ncBmzJ8Tl1HkI5KUHTQowZVbrczoub1JBWLzK0FD6A2wh5vLVa/KHzcW1N6kXlzNMN7GDSAD8LAiPsW5uQoMDz4uFkrAMtdfXNsZ5jP7dZJawAh1J4PjDhc5vnKLJq7Ps/u1dsECiZWt1tk+R3KH7xGahZXXKCHfib8k3OEkiqQ=,iv:zjeA3oZ9JBE+bOO66R2xmJup7a9bBvDYUhrQg1H9kE0=,tag:Wjdsw5rbPfgQdMXaDAwAAQ==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/docker/docker.cue b/stdlib/docker/docker.cue index 07782226..1a37324f 100644 --- a/stdlib/docker/docker.cue +++ b/stdlib/docker/docker.cue @@ -3,7 +3,6 @@ package docker import ( "alpha.dagger.io/dagger" - "alpha.dagger.io/alpine" "alpha.dagger.io/dagger/op" ) @@ -63,35 +62,30 @@ import ( ] // Image ref - ref: string @dagger(output) + ref: { + string + + #up: [ + op.#Load & {from: push}, + + op.#Export & { + source: "/image_ref" + }, + ] + } @dagger(output) // Image digest - digest: string @dagger(output) + digest: { + string - #up: [ - op.#Load & {from: alpine.#Image & { - package: { - bash: true - jq: true - } - }}, + #up: [ + op.#Load & {from: push}, - op.#Exec & { - always: true - args: ["/bin/bash", "-c", #""" - jq --arg key0 'ref' --arg value0 $(cat /dagger/image_ref) \ - --arg key1 'digest' --arg value1 $(cat /dagger/image_digest) \ - '. | .[$key0]=$value0 | .[$key1]=$value1 '<<< '{}' > /out - """#, - ] - mount: "/dagger": from: push - }, - - op.#Export & { - source: "/out" - format: "json" - }, - ] + op.#Export & { + source: "/image_digest" + }, + ] + } @dagger(output) } #Run: {