mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-08 18:52:32 +08:00
feat(container): optimize image pull display (#8140)
This commit is contained in:
parent
0d4abe8e8f
commit
fc649ded94
3 changed files with 20 additions and 21 deletions
|
|
@ -475,7 +475,7 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerOperate) error {
|
|||
go func() {
|
||||
taskItem.AddSubTask(i18n.GetWithName("ContainerImagePull", req.Image), func(t *task.Task) error {
|
||||
if !checkImageExist(client, req.Image) || req.ForcePull {
|
||||
if err := pullImages(ctx, client, req.Image); err != nil {
|
||||
if err := pullImages(taskItem, client, req.Image); err != nil {
|
||||
if !req.ForcePull {
|
||||
return err
|
||||
}
|
||||
|
|
@ -617,7 +617,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error {
|
|||
go func() {
|
||||
taskItem.AddSubTask(i18n.GetWithName("ContainerImagePull", req.Image), func(t *task.Task) error {
|
||||
if !checkImageExist(client, req.Image) || req.ForcePull {
|
||||
if err := pullImages(ctx, client, req.Image); err != nil {
|
||||
if err := pullImages(taskItem, client, req.Image); err != nil {
|
||||
if !req.ForcePull {
|
||||
return err
|
||||
}
|
||||
|
|
@ -683,7 +683,7 @@ func (u *ContainerService) ContainerUpgrade(req dto.ContainerUpgrade) error {
|
|||
go func() {
|
||||
taskItem.AddSubTask(i18n.GetWithName("ContainerImagePull", req.Image), func(t *task.Task) error {
|
||||
if !checkImageExist(client, req.Image) || req.ForcePull {
|
||||
if err := pullImages(ctx, client, req.Image); err != nil {
|
||||
if err := pullImages(taskItem, client, req.Image); err != nil {
|
||||
if !req.ForcePull {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1156,7 +1156,8 @@ func checkImageExist(client *client.Client, imageItem string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func pullImages(ctx context.Context, client *client.Client, imageName string) error {
|
||||
func pullImages(task *task.Task, client *client.Client, imageName string) error {
|
||||
dockerCli := docker.NewClientWithExist(client)
|
||||
options := image.PullOptions{}
|
||||
repos, _ := imageRepoRepo.List()
|
||||
if len(repos) != 0 {
|
||||
|
|
@ -1180,16 +1181,7 @@ func pullImages(ctx context.Context, client *client.Client, imageName string) er
|
|||
options.RegistryAuth = authStr
|
||||
}
|
||||
}
|
||||
out, err := client.ImagePull(ctx, imageName, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
_, err = io.Copy(io.Discard, out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return dockerCli.PullImageWithProcessAndOptions(task, imageName, options)
|
||||
}
|
||||
|
||||
func loadCpuAndMem(client *client.Client, containerItem string) dto.ContainerListStats {
|
||||
|
|
|
|||
|
|
@ -263,15 +263,12 @@ func (u *ImageService) ImagePull(req dto.ImagePull) error {
|
|||
}
|
||||
imageName = repo.DownloadUrl + "/" + req.ImageName
|
||||
}
|
||||
|
||||
out, err := client.ImagePull(context.TODO(), imageName, options)
|
||||
dockerCli := docker.NewClientWithExist(client)
|
||||
err = dockerCli.PullImageWithProcessAndOptions(taskItem, imageName, options)
|
||||
taskItem.LogWithStatus(i18n.GetMsgByKey("TaskPull"), err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
body, _ := io.ReadAll(out)
|
||||
taskItem.LogSuccess(i18n.GetWithName("ImaegPullRes", "\n"+string(body)))
|
||||
return nil
|
||||
}, nil)
|
||||
_ = taskItem.Execute()
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ func NewClient() (Client, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func NewClientWithExist(cli *client.Client) Client {
|
||||
return Client{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
cli *client.Client
|
||||
}
|
||||
|
|
@ -174,8 +180,8 @@ func setLog(id, newLastLine string, task *task.Task) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
|
||||
out, err := c.cli.ImagePull(context.Background(), imageName, image.PullOptions{})
|
||||
func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string, options image.PullOptions) error {
|
||||
out, err := c.cli.ImagePull(context.Background(), imageName, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -213,3 +219,7 @@ func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
|
||||
return c.PullImageWithProcessAndOptions(task, imageName, image.PullOptions{})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue