github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/image/distributionutil/registry.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package distributionutil 16 17 import ( 18 "context" 19 20 "github.com/alibaba/sealer/logger" 21 22 "github.com/docker/docker/api/types" 23 24 distribution "github.com/distribution/distribution/v3" 25 26 "github.com/alibaba/sealer/pkg/image/reference" 27 "github.com/alibaba/sealer/utils" 28 ) 29 30 func NewV2Repository(named reference.Named, actions ...string) (distribution.Repository, error) { 31 authConfig, authErr := utils.GetDockerAuthInfoFromDocker(named.Domain()) 32 repo, err := getV2Repository(authConfig, named, actions...) 33 if err != nil && authErr != nil { 34 logger.Debug("failed to get auth info, err: %s", authErr) 35 } 36 return repo, err 37 } 38 39 func getV2Repository(authConfig types.AuthConfig, named reference.Named, actions ...string) (distribution.Repository, error) { 40 repo, err := NewRepository(context.Background(), authConfig, named.Repo(), registryConfig{Insecure: true, Domain: named.Domain()}, actions...) 41 if err == nil { 42 return repo, nil 43 } 44 return NewRepository(context.Background(), authConfig, named.Repo(), registryConfig{Insecure: true, NonSSL: true, Domain: named.Domain()}, actions...) 45 }