Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions pkg/devspace/build/builder/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"encoding/base64"
"encoding/json"
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
command2 "github.com/loft-sh/loft-util/pkg/command"
"github.com/sirupsen/logrus"
"io"
"os"
"path/filepath"
"strings"

devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
command2 "github.com/loft-sh/loft-util/pkg/command"
"github.com/sirupsen/logrus"

"github.com/docker/cli/cli/streams"
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"

Expand Down Expand Up @@ -112,13 +113,21 @@ func (b *Builder) BuildImage(ctx devspacecontext.Context, contextPath, dockerfil

// Authenticate
if !b.skipPush && !b.helper.ImageConf.SkipPush {
ctx.Log().Info("Authenticating (" + displayRegistryURL + ")...")
_, err = b.Authenticate(ctx.Context())
if err != nil {
return errors.Errorf("Error during image registry authentication: %v", err)
}
if pullsecrets.IsAzureContainerRegistry(registryURL) {
ctx.Log().Warn("Using an Azure Container Registry(ACR), skipping authentication. You may need to refresh your credentials by running 'az acr login'")
b.authConfig, err = b.client.GetAuthConfig(ctx.Context(), registryURL, true)
if err != nil {
return err
}
} else {
ctx.Log().Info("Authenticating (" + displayRegistryURL + ")...")
_, err = b.Authenticate(ctx.Context())
if err != nil {
return errors.Errorf("Error during image registry authentication: %v", err)
}

ctx.Log().Done("Authentication successful (" + displayRegistryURL + ")")
ctx.Log().Done("Authentication successful (" + displayRegistryURL + ")")
}
}

// Buildoptions
Expand Down
7 changes: 4 additions & 3 deletions pkg/devspace/pullsecrets/init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pullsecrets

import (
"strings"
"time"

devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
Expand All @@ -19,6 +18,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const AzureContainerRegistryUsername = "00000000-0000-0000-0000-000000000000"

func (r *client) EnsurePullSecret(ctx devspacecontext.Context, dockerClient docker.Client, namespace, registryURL string) error {
pullSecret := &latest.PullSecretConfig{Registry: registryURL}

Expand Down Expand Up @@ -175,8 +176,8 @@ func (r *client) createPullSecret(ctx devspacecontext.Context, dockerClient dock

// Handle Azure Container Registry (ACR) when credentials helper does not provide a username
// https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli#az-acr-login-with---expose-token
if username == "" && strings.HasSuffix(authConfig.ServerAddress, "azurecr.io") {
username = "00000000-0000-0000-0000-000000000000"
if username == "" && IsAzureContainerRegistry(authConfig.ServerAddress) {
username = AzureContainerRegistryUsername
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/devspace/pullsecrets/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pullsecrets

import (
"strings"

"github.com/docker/distribution/reference"
dockerregistry "github.com/docker/docker/registry"
)
Expand All @@ -23,3 +25,7 @@ func GetRegistryFromImageName(imageName string) (string, error) {

return repoInfo.Index.Name, nil
}

func IsAzureContainerRegistry(serverAddress string) bool {
return strings.HasSuffix(serverAddress, "azurecr.io")
}