Normalize reference to login on registry

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-06-24 11:42:34 +02:00
parent 7d1bbcc416
commit 5468f60e39
3 changed files with 32 additions and 31 deletions

View File

@ -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/"
}

View File

@ -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

View File

@ -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: {