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
38 changes: 38 additions & 0 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2023 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package registry

import "github.com/distribution/reference"

const (
// IndexHostname is the index hostname, used for authentication and image search.
IndexHostname = "index.docker.io"
// IndexServer is used for user auth and image search
IndexServer = "https://index.docker.io/v1/"
// IndexName is the name of the index
IndexName = "docker.io"
)

// GetAuthConfigKey special-cases using the full index address of the official
// index as the AuthConfig key, and uses the (host)name[:port] for private indexes.
func GetAuthConfigKey(reposName reference.Named) string {
Copy link
Member

@mdelapenya mdelapenya Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would see a lot of value having this as a shared component that can be used by Testcontainers, i.e.

I think the Go SDK has something similar to this here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, much to do in this area but don't want to expose yet until some other bits are sorted (it's why I put it in "internal" for now).

indexName := reference.Domain(reposName)
if indexName == IndexName || indexName == IndexHostname {
return IndexServer
}
return indexName
}
10 changes: 2 additions & 8 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"github.com/hashicorp/go-multierror"
"github.com/opencontainers/go-digest"
"golang.org/x/sync/errgroup"

"github.com/docker/compose/v2/internal/registry"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
)
Expand Down Expand Up @@ -281,13 +281,7 @@ func ImageDigestResolver(ctx context.Context, file *configfile.ConfigFile, apiCl
}

func encodedAuth(ref reference.Named, configFile driver.Auth) (string, error) {
repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil {
return "", err
}

key := registry.GetAuthConfigKey(repoInfo.Index)
authConfig, err := configFile.GetAuthConfig(key)
authConfig, err := configFile.GetAuthConfig(registry.GetAuthConfigKey(ref))
if err != nil {
return "", err
}
Expand Down
26 changes: 4 additions & 22 deletions pkg/compose/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ import (
"github.com/distribution/reference"
"github.com/docker/buildx/driver"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"golang.org/x/sync/errgroup"

"github.com/docker/compose/v2/internal/registry"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
)
Expand All @@ -51,14 +50,6 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio
eg, ctx := errgroup.WithContext(ctx)
eg.SetLimit(s.maxConcurrency)

info, err := s.apiClient().Info(ctx)
if err != nil {
return err
}
if info.IndexServerAddress == "" {
info.IndexServerAddress = registry.IndexServer
}

w := progress.ContextWriter(ctx)
for _, service := range project.Services {
if service.Build == nil || service.Image == "" {
Expand All @@ -79,7 +70,7 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio

for _, tag := range tags {
eg.Go(func() error {
err := s.pushServiceImage(ctx, tag, info, s.configFile(), w, options.Quiet)
err := s.pushServiceImage(ctx, tag, s.configFile(), w, options.Quiet)
if err != nil {
if !options.IgnoreFailures {
return err
Expand All @@ -93,22 +84,13 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio
return eg.Wait()
}

func (s *composeService) pushServiceImage(ctx context.Context, tag string, info system.Info, configFile driver.Auth, w progress.Writer, quietPush bool) error {
func (s *composeService) pushServiceImage(ctx context.Context, tag string, configFile driver.Auth, w progress.Writer, quietPush bool) error {
ref, err := reference.ParseNormalizedNamed(tag)
if err != nil {
return err
}

repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil {
return err
}

key := repoInfo.Index.Name
if repoInfo.Index.Official {
key = info.IndexServerAddress
}
authConfig, err := configFile.GetAuthConfig(key)
authConfig, err := configFile.GetAuthConfig(registry.GetAuthConfigKey(ref))
if err != nil {
return err
}
Expand Down