From f5866e5c73c629aea980b91a9f3ef8ca6792e95c Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 12 Aug 2024 11:45:30 +1000 Subject: [PATCH] fix: check if dockerhub or not correctly (#351) --- cmd/identify_imagebuild_test.go | 3 +++ internal/generator/buildvalues.go | 1 + internal/generator/container_registries.go | 3 +++ legacy/build-deploy-docker-compose.sh | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index f4db04e9..6f3aec44 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -529,6 +529,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { URL: "registry1.example.com", UsernameSource: ".lagoon.yml", PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)", + IsDockerHub: helpers.BoolPtr(false), }, }, Images: []imageBuilds{ @@ -656,6 +657,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { URL: "index.docker.io", UsernameSource: ".lagoon.yml", PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)", + IsDockerHub: helpers.BoolPtr(true), }, { Name: "my-other-custom-registry", @@ -665,6 +667,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { URL: "registry1.example.com", UsernameSource: ".lagoon.yml", PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)", + IsDockerHub: helpers.BoolPtr(false), }, }, Images: []imageBuilds{ diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 7708a709..ce6e805c 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -104,6 +104,7 @@ type ContainerRegistry struct { UsernameSource string `json:"usernameSource" description:"information regarding the source of the username"` PasswordSource string `json:"passwordSource" description:"information regarding the source of the password"` SecretName string `json:"secretName" description:"the name of the secret to be created for this registry"` + IsDockerHub *bool `json:"isDockerHub" description:"if this registry is dockerhub or not"` } type PodSecurityContext struct { diff --git a/internal/generator/container_registries.go b/internal/generator/container_registries.go index 37ea2992..1f287abc 100644 --- a/internal/generator/container_registries.go +++ b/internal/generator/container_registries.go @@ -66,8 +66,10 @@ func configureContainerRegistries(buildValues *BuildValues) error { username = &lagoon.EnvironmentVariable{Value: cr.Username} usernameSource = ".lagoon.yml" } + isDockerHub := false if cr.URL == "" { cr.URL = "index.docker.io" + isDockerHub = true buildValues.IgnoreImageCache = true } eru := cr.URL @@ -88,6 +90,7 @@ func configureContainerRegistries(buildValues *BuildValues) error { UsernameSource: usernameSource, PasswordSource: passwordSource, SecretName: secretName, + IsDockerHub: &isDockerHub, }) } return nil diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 5ca3c5e9..5c808974 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -571,7 +571,8 @@ do PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.usernameSource // false') PRIVATE_REGISTRY_CREDENTIAL=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.password // false') PRIVATE_REGISTRY_CREDENTIAL_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.passwordSource // false') - if [ $PRIVATE_CONTAINER_REGISTRY_URL != "false" ]; then + PRIVATE_CONTAINER_REGISTRY_ISDOCKERHUB=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.isDockerHub // false') + if [ $PRIVATE_CONTAINER_REGISTRY_ISDOCKERHUB == "false" ]; then echo "Attempting to log in to $PRIVATE_CONTAINER_REGISTRY_URL with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE" echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE" docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL $PRIVATE_CONTAINER_REGISTRY_URL