Skip to content

Commit

Permalink
fix: pull image failure
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail committed Nov 20, 2024
1 parent 2217167 commit 968e596
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions builder/sources/image_containerd_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ func (c *containerdImageCliImpl) ImagePull(image string, username, password stri
})

Tracker := docker.NewInMemoryTracker()
options := docker.ResolverOptions{
Tracker: Tracker,
Hosts: config.ConfigureHosts(pctx, hostOpt),
}

platformMC := platforms.Ordered([]ocispec.Platform{platforms.DefaultSpec()}...)
opts := []containerd.RemoteOpt{
Expand All @@ -150,13 +146,21 @@ func (c *containerdImageCliImpl) ImagePull(image string, username, password stri

// First attempt with HTTPS
hostOpt.DefaultScheme = "https"
options := docker.ResolverOptions{
Tracker: Tracker,
Hosts: config.ConfigureHosts(pctx, hostOpt),
}
opts = append(opts, containerd.WithResolver(docker.NewResolver(options)))

var img containerd.Image
img, err = c.client.Pull(pctx, reference, opts...)
if err != nil {
printLog(logger, "warn", fmt.Sprintf("HTTPS pull failed for image %s, trying HTTP", reference), map[string]string{"step": "pullimage"})
hostOpt.DefaultScheme = "http"
options = docker.ResolverOptions{
Tracker: Tracker,
Hosts: config.ConfigureHosts(pctx, hostOpt),
}
img, err = c.client.Pull(pctx, reference, opts...)
}

Expand Down

0 comments on commit 968e596

Please sign in to comment.