diff --git a/app/server/resources/images.go b/app/server/resources/images.go index ef14737..d3bc656 100644 --- a/app/server/resources/images.go +++ b/app/server/resources/images.go @@ -123,6 +123,10 @@ func ImagesBulkActions() []ui.MenuAction { Prompt: "Are you sure you want to prune all unused images?", Command: "images.prune", }, + ui.MenuAction{ + Label: "pull latest images", + Command: "images.pull", + }, ) return actions } diff --git a/app/server/server/images.go b/app/server/server/images.go index 44cc236..ddb8669 100644 --- a/app/server/server/images.go +++ b/app/server/server/images.go @@ -64,6 +64,61 @@ func (Images) RunCommand(server *Server, session *melody.Session, command ui.Com }), ) + // Bulk - Pull + case "images.pull": + images := resources.ImagesList(server.Docker) + + for _, image := range images { + if image.Version != "latest" { + continue + } + + task := process.LongTask{ + Function: resources.ImagePull, + Args: map[string]interface{}{"Image": image.Name}, + OnStep: func(update string) { + metadata := make(map[string]string) + json.Unmarshal([]byte(update), &metadata) + + message := fmt.Sprintf("Pulling : %s", image.Name) + message += fmt.Sprintf("
Status : %s", metadata["status"]) + if _, ok := metadata["progress"]; ok { + message += fmt.Sprintf("
Progress : %s", metadata["progress"]) + } + + server.SendNotification( + session, + ui.NotificationInfo(ui.NP{ + Content: ui.JSON{ + "Message": message, + }, + }), + ) + }, + OnError: func(err error) { + server.SendNotification( + session, + ui.NotificationError(ui.NP{Content: ui.JSON{"Message": err.Error()}}), + ) + }, + OnDone: func() { + server.SendNotification( + session, + ui.NotificationSuccess(ui.NP{ + Content: ui.JSON{"Message": fmt.Sprintf("The image %s was succesfully pulled", image.Name)}, Follow: "images.list", + }), + ) + }, + } + task.RunSync(server.Docker) + } + server.SendNotification( + session, + ui.NotificationSuccess(ui.NP{ + Content: ui.JSON{"Message": "All your latest image were succesfully pulled"}, Follow: "images.list", + }), + ) + // Single - Default remove case "image.remove.default": var image resources.Image