From 360cdf3f77889532ebfd429e658746bdc053f41c Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:02:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E6=97=B6=E6=8B=89=E5=8F=96=E5=B8=A6=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E4=BB=93=E5=BA=93=E9=95=9C=E5=83=8F=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#3320)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #3226 --- backend/app/service/container.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 3775f131b..f17e67cbd 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -2,6 +2,7 @@ package service import ( "context" + "encoding/base64" "encoding/json" "fmt" "io" @@ -26,6 +27,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" "github.com/gorilla/websocket" @@ -805,7 +807,25 @@ func checkImageExist(client *client.Client, image string) bool { } func pullImages(ctx context.Context, client *client.Client, image string) error { - out, err := client.ImagePull(ctx, image, types.ImagePullOptions{}) + options := types.ImagePullOptions{} + repos, _ := imageRepoRepo.List() + if len(repos) != 0 { + for _, repo := range repos { + if strings.HasPrefix(image, repo.DownloadUrl) && repo.Auth { + authConfig := registry.AuthConfig{ + Username: repo.Username, + Password: repo.Password, + } + encodedJSON, err := json.Marshal(authConfig) + if err != nil { + return err + } + authStr := base64.URLEncoding.EncodeToString(encodedJSON) + options.RegistryAuth = authStr + } + } + } + out, err := client.ImagePull(ctx, image, options) if err != nil { return err }