Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image pull and push failure #2047

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
73 changes: 38 additions & 35 deletions builder/sources/image_containerd_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ func (c *containerdImageCliImpl) GetDockerClient() *dockercli.Client {

func (c *containerdImageCliImpl) ImagePull(image string, username, password string, logger event.Logger, timeout int) (*ocispec.ImageConfig, error) {
printLog(logger, "info", fmt.Sprintf("start get image:%s", image), map[string]string{"step": "pullimage"})

defaultTLS := &tls.Config{
InsecureSkipVerify: true,
}
hostOpt := config.HostOptions{}
hostOpt.DefaultTLS = defaultTLS
hostOpt.Credentials = func(host string) (string, string, error) {
return username, password, nil
}
// 如果 image 以 "https://" 或 "http://" 开头,去掉前缀
if strings.HasPrefix(image, "https://") {
image = strings.TrimPrefix(image, "https://")

} else if strings.HasPrefix(image, "http://") {
image = strings.TrimPrefix(image, "http://")
hostOpt.DefaultScheme = "http"
} else {
hostOpt.DefaultScheme = "http"
}

named, err := refdocker.ParseDockerRef(image)
if err != nil {
return nil, err
Expand All @@ -122,24 +142,7 @@ func (c *containerdImageCliImpl) ImagePull(image string, username, password stri
}
return nil, nil
})
defaultTLS := &tls.Config{
InsecureSkipVerify: true,
}
hostOpt := config.HostOptions{}
hostOpt.DefaultTLS = defaultTLS
hostOpt.Credentials = func(host string) (string, string, error) {
return username, password, nil
}
// 如果 image 以 "https://" 或 "http://" 开头,去掉前缀
if strings.HasPrefix(image, "https://") {
image = strings.TrimPrefix(image, "https://")

} else if strings.HasPrefix(image, "http://") {
image = strings.TrimPrefix(image, "http://")
hostOpt.DefaultScheme = "http"
} else {
hostOpt.DefaultScheme = "http"
}
Tracker := docker.NewInMemoryTracker()
options := docker.ResolverOptions{
Tracker: Tracker,
Expand Down Expand Up @@ -189,6 +192,24 @@ func getImageConfig(ctx context.Context, image containerd.Image) (*ocispec.Image

func (c *containerdImageCliImpl) ImagePush(image, user, pass string, logger event.Logger, timeout int) error {
printLog(logger, "info", fmt.Sprintf("开始推送镜像:%s", image), map[string]string{"step": "pushimage"})
hostOptions := config.HostOptions{
DefaultTLS: &tls.Config{
InsecureSkipVerify: true,
},
Credentials: func(host string) (string, string, error) {
return user, pass, nil
},
}
// 如果 image 以 "https://" 或 "http://" 开头,去掉前缀
if strings.HasPrefix(image, "https://") {
image = strings.TrimPrefix(image, "https://")

} else if strings.HasPrefix(image, "http://") {
image = strings.TrimPrefix(image, "http://")
hostOptions.DefaultScheme = "http"
} else {
hostOptions.DefaultScheme = "http"
}

named, err := refdocker.ParseDockerRef(image)
if err != nil {
Expand Down Expand Up @@ -224,24 +245,6 @@ func (c *containerdImageCliImpl) ImagePush(image, user, pass string, logger even
Tracker: NewTracker,
}

hostOptions := config.HostOptions{
DefaultTLS: &tls.Config{
InsecureSkipVerify: true,
},
Credentials: func(host string) (string, string, error) {
return user, pass, nil
},
}
// 如果 image 以 "https://" 或 "http://" 开头,去掉前缀
if strings.HasPrefix(image, "https://") {
image = strings.TrimPrefix(image, "https://")

} else if strings.HasPrefix(image, "http://") {
image = strings.TrimPrefix(image, "http://")
hostOptions.DefaultScheme = "http"
} else {
hostOptions.DefaultScheme = "http"
}
options.Hosts = config.ConfigureHosts(ctx, hostOptions)
resolver := docker.NewResolver(options)
ongoing := newPushJobs(NewTracker)
Expand Down
Loading