Fix docker hub login error when using image ref as target

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-06-18 22:01:16 +02:00
parent f842f1ed1d
commit 7d1bbcc416
6 changed files with 28 additions and 25 deletions

View File

@ -78,9 +78,8 @@ Push a docker image to a remote registry
| ------------- |:-------------: |:-------------: | | ------------- |:-------------: |:-------------: |
|*name* | `string` |Remote name (example: "index.docker.io/alpine:latest") | |*name* | `string` |Remote name (example: "index.docker.io/alpine:latest") |
|*source* | `dagger.#Artifact` |Image source | |*source* | `dagger.#Artifact` |Image source |
|*registry.target* | `*"https://index.docker.io/v1/" \| string` |Remote registry | |*auth.username* | `string` |Username |
|*registry.username* | `string` |Username | |*auth.secret* | `string` |Password or secret |
|*registry.secret* | `(string\|bytes)` |Password or secret |
### docker.#Push Outputs ### docker.#Push Outputs

View File

@ -63,7 +63,9 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred
} }
func parseAuthHost(host string) (*url.URL, error) { func parseAuthHost(host string) (*url.URL, error) {
if host == "registry-1.docker.io" { isDockerHub := !(strings.Contains(host, "amazonaws.com") || strings.Contains(host, "gcr.io") || strings.Contains(host, "microsoft.com"))
if host == "registry-1.docker.io" || isDockerHub {
host = "https://index.docker.io/v1/" host = "https://index.docker.io/v1/"
} }

View File

@ -1,7 +1,9 @@
plan:
module: .dagger/env/docker-pull/plan
name: docker-pull name: docker-pull
inputs: inputs:
ref: ref:
text: docker.io/daggerio/ci-test:qhkmeqmhmnqn@sha256:96640793ed325f893608508f1b60b9c19b547c178e45639a249989545894eed4 text: docker.io/daggerio/ci-test:otnlnwqyyxlk@sha256:35fc94d52b4fa53c2caa38ff11e13182e6f88c651eb0846728d1007d931f0d3c
sops: sops:
kms: [] kms: []
gcp_kms: [] gcp_kms: []
@ -17,8 +19,8 @@ sops:
SG1raUVNTzZIWDltV1pOS3hySHlJeWcKg3blmstOGcxtPww513+mAEA0MWOXwNAT SG1raUVNTzZIWDltV1pOS3hySHlJeWcKg3blmstOGcxtPww513+mAEA0MWOXwNAT
5ngRvG6MraW3g9dhIuUYOwjuJyz1Z07/DBEocSxnjSyw45ZCkM1/9Q== 5ngRvG6MraW3g9dhIuUYOwjuJyz1Z07/DBEocSxnjSyw45ZCkM1/9Q==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2021-06-12T15:01:07Z" lastmodified: "2021-06-18T19:57:47Z"
mac: ENC[AES256_GCM,data:kmryJiX4cnZTeyRcH+TljCj+m5kEA4yPu0gQkqS3apEolfNFWzkdlvRS2P+9EYO19iT1FxpNRwrs+G9qGeISubc48u2++Yb/mAUU4ilIu8flIPs3s63Ep8FeRv+hI3Govljjbjyds+3mR+o0Iv+KhpKBPDboXyRpWGlIijpBzLQ=,iv:ROAK7qmGn0jWDZp8uPLVbReqdgO9qw8EESkYdPjxLDk=,tag:8CrydkWN9xtJX8yItgjz+A==,type:str] mac: ENC[AES256_GCM,data:dS7zAl28vERwDOh8OwNmVNrcZ10Ypibl7HylXnJ0+CBGCx3b0C6+/TNgytZFjhhjhOyJbioaTIA/Rra3Okz2Y1beJcP90CfixkIOQvpespIN6yh92SN6m1MbGQzWB0lURnVwHhLlOyIsDK5PaLcbW9mVhwiH4Y2otH+xRNO+8Ls=,iv:1vRlh02EFWYqu2q/AQeHDRcIJIiKxZAp7lspQmPybRI=,tag:0DcXYSoLMAJ/09ZunKkezg==,type:str]
pgp: [] pgp: []
encrypted_suffix: secret encrypted_suffix: secret
version: 3.7.1 version: 3.7.1

View File

@ -55,7 +55,7 @@ TestPush: {
push: docker.#Push & { push: docker.#Push & {
"name": name "name": name
source: image source: image
registry: { auth: {
username: TestRegistry.username username: TestRegistry.username
"secret": secret.out "secret": secret.out
} }

View File

@ -1,3 +1,5 @@
plan:
module: .dagger/env/docker-push/plan
name: docker-push name: docker-push
inputs: inputs:
TestRegistry.secret: TestRegistry.secret:
@ -19,8 +21,8 @@ sops:
UjFJYTc1UUUzSFVkZjQ2blRsSGpVdVEKOanMR3+WlAgoDfqTUW7WPW1ytT3NdkTX UjFJYTc1UUUzSFVkZjQ2blRsSGpVdVEKOanMR3+WlAgoDfqTUW7WPW1ytT3NdkTX
4Rqo49QmnuKFJ9tKoBFQOqgIo8E/lpcOkeIUiy5e/35FvsZ/KFk/pg== 4Rqo49QmnuKFJ9tKoBFQOqgIo8E/lpcOkeIUiy5e/35FvsZ/KFk/pg==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2021-06-12T13:31:57Z" lastmodified: "2021-06-18T19:34:53Z"
mac: ENC[AES256_GCM,data:TrLGfqDj3lvZKroaPtlDuR0Ki+yoFDYFqIhW+g7iasVOzvDaqHepX8X/aLiHX+XHdTqGH6ehfu1k1BSaz6xKqqdIai9NIyokgIKXR1F5mRgK/aDhc6x/YvX3dSl79/4zBBblDpYNFhCarQMxeTSFP9GfW+e0+T/z10fHHlQub8o=,iv:Pab2qkZTqP/6j4LV0B97SACQm/UZPMkeahGjZLJ2fFg=,tag:r4IW1WRipuC/MdtwEzzEpA==,type:str] mac: ENC[AES256_GCM,data:2LqpZGLCgN4d72hZMSs9uuIy0Eh69eP9JfhCcCvnIUg8kXcr5/mThST3Xum1LHJsAwfXIxPQPuz2ZzlcWksgYczNalU+ibTVk6N3nLi4ynrbV5QXaoS2MUmJHx6Y4VsjKHg13DQOysqcCa3+vY3WKxZ/WLgkI0rVOwZMELQBfXo=,iv:LeVFP37Y0rpLJa3IpbHD0N1ZARH139dz434c+uLv+Yo=,tag:yjlfzzcvvFzmVnvBX+8aAg==,type:str]
pgp: [] pgp: []
encrypted_suffix: secret encrypted_suffix: secret
version: 3.7.1 version: 3.7.1

View File

@ -37,30 +37,28 @@ import (
// Image source // Image source
source: dagger.#Artifact @dagger(input) source: dagger.#Artifact @dagger(input)
// Image registry // Registry auth
registry: { auth: {
// Remote registry
target: string | *"https://index.docker.io/v1/" @dagger(input)
// Username // Username
username: string @dagger(input) username: string @dagger(input)
// Password or secret // Password or secret
secret: string | bytes @dagger(input) secret: string @dagger(input)
} }
push: #up: [ push: #up: [
op.#Load & {from: source}, op.#Load & {from: source},
if registry != _|_ { if auth != _|_ {
op.#DockerLogin & { op.#DockerLogin & {
target: registry.target target: name
username: registry.username username: auth.username
secret: registry.secret secret: auth.secret
} }
}, },
op.#PushContainer & {ref: name}, op.#PushContainer & {ref: name},
op.#Subdir & {dir: "/dagger"}, op.#Subdir & {dir: "/dagger"},
] ]