From 968e5967c34e8557dc11cfb4775aec40224964ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=AF=E8=88=AA?= <101104760+ZhangSetSail@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:46:37 +0800 Subject: [PATCH] fix: pull image failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张启航 <101104760+ZhangSetSail@users.noreply.github.com> --- builder/sources/image_containerd_client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builder/sources/image_containerd_client.go b/builder/sources/image_containerd_client.go index 0aa2dd491..856609e76 100644 --- a/builder/sources/image_containerd_client.go +++ b/builder/sources/image_containerd_client.go @@ -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{ @@ -150,6 +146,10 @@ 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 @@ -157,6 +157,10 @@ func (c *containerdImageCliImpl) ImagePull(image string, username, password stri 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...) }