Skip to content

Commit

Permalink
fix: check if dockerhub or not correctly (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Aug 12, 2024
1 parent d5fd8c4 commit f5866e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/identify_imagebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand Down
1 change: 1 addition & 0 deletions internal/generator/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions internal/generator/container_registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,6 +90,7 @@ func configureContainerRegistries(buildValues *BuildValues) error {
UsernameSource: usernameSource,
PasswordSource: passwordSource,
SecretName: secretName,
IsDockerHub: &isDockerHub,
})
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5866e5

Please sign in to comment.