Skip to content

Commit

Permalink
feat(images): added support for bulk-pulling latest images
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Moss committed Jan 9, 2024
1 parent bc3e21b commit 0629435
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/server/resources/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
55 changes: 55 additions & 0 deletions app/server/server/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<br />Status : %s", metadata["status"])
if _, ok := metadata["progress"]; ok {
message += fmt.Sprintf("<br />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
Expand Down

0 comments on commit 0629435

Please sign in to comment.