Skip to content

Commit f5866e5

Browse files
fix: check if dockerhub or not correctly (#351)
1 parent d5fd8c4 commit f5866e5

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

cmd/identify_imagebuild_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
529529
URL: "registry1.example.com",
530530
UsernameSource: ".lagoon.yml",
531531
PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)",
532+
IsDockerHub: helpers.BoolPtr(false),
532533
},
533534
},
534535
Images: []imageBuilds{
@@ -656,6 +657,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
656657
URL: "index.docker.io",
657658
UsernameSource: ".lagoon.yml",
658659
PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)",
660+
IsDockerHub: helpers.BoolPtr(true),
659661
},
660662
{
661663
Name: "my-other-custom-registry",
@@ -665,6 +667,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
665667
URL: "registry1.example.com",
666668
UsernameSource: ".lagoon.yml",
667669
PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)",
670+
IsDockerHub: helpers.BoolPtr(false),
668671
},
669672
},
670673
Images: []imageBuilds{

internal/generator/buildvalues.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type ContainerRegistry struct {
104104
UsernameSource string `json:"usernameSource" description:"information regarding the source of the username"`
105105
PasswordSource string `json:"passwordSource" description:"information regarding the source of the password"`
106106
SecretName string `json:"secretName" description:"the name of the secret to be created for this registry"`
107+
IsDockerHub *bool `json:"isDockerHub" description:"if this registry is dockerhub or not"`
107108
}
108109

109110
type PodSecurityContext struct {

internal/generator/container_registries.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ func configureContainerRegistries(buildValues *BuildValues) error {
6666
username = &lagoon.EnvironmentVariable{Value: cr.Username}
6767
usernameSource = ".lagoon.yml"
6868
}
69+
isDockerHub := false
6970
if cr.URL == "" {
7071
cr.URL = "index.docker.io"
72+
isDockerHub = true
7173
buildValues.IgnoreImageCache = true
7274
}
7375
eru := cr.URL
@@ -88,6 +90,7 @@ func configureContainerRegistries(buildValues *BuildValues) error {
8890
UsernameSource: usernameSource,
8991
PasswordSource: passwordSource,
9092
SecretName: secretName,
93+
IsDockerHub: &isDockerHub,
9194
})
9295
}
9396
return nil

legacy/build-deploy-docker-compose.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ do
571571
PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.usernameSource // false')
572572
PRIVATE_REGISTRY_CREDENTIAL=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.password // false')
573573
PRIVATE_REGISTRY_CREDENTIAL_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.passwordSource // false')
574-
if [ $PRIVATE_CONTAINER_REGISTRY_URL != "false" ]; then
574+
PRIVATE_CONTAINER_REGISTRY_ISDOCKERHUB=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.isDockerHub // false')
575+
if [ $PRIVATE_CONTAINER_REGISTRY_ISDOCKERHUB == "false" ]; then
575576
echo "Attempting to log in to $PRIVATE_CONTAINER_REGISTRY_URL with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE"
576577
echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE"
577578
docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL $PRIVATE_CONTAINER_REGISTRY_URL

0 commit comments

Comments
 (0)