Skip to content

Commit

Permalink
feat: check latest result (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Mar 13, 2024
1 parent 84f7ad8 commit c9ed263
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions service/compose_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/compose-spec/compose-go/loader"
"github.com/compose-spec/compose-go/types"
composeCmd "github.com/docker/compose/v2/cmd/compose"
"github.com/docker/docker/client"

"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -205,11 +206,31 @@ func (a *ComposeApp) IsUpdateAvailableWith(storeComposeApp *ComposeApp) bool {

mainAppImage, mainAppTag := docker.ExtractImageAndTag(mainApp.Image)

// TODO to async the check for consist with the version tag app
if mainAppTag == "latest" {
// logger.Info("main app image tag is latest, thus no update available", zap.String("image", mainApp.Image))
// return false
logger.Info("main app is latest, update to latest")
return true
// check image digest when tag is latest.
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
defer cli.Close()

imageInfo, _, err := cli.ImageInspectWithRaw(ctx, mainAppImage)

if err != nil {
logger.Error("failed to inspect image", zap.Error(err), zap.String("name", mainAppImage))
return false
}
match, err := docker.CompareDigest(storeComposeApp.Services[0].Image, imageInfo.RepoDigests)
if err != nil {
logger.Error("failed to compare digest", zap.Error(err), zap.String("name", mainAppImage))
return false
}
if match {
logger.Info("main app image tag is latest, thus no update available", zap.String("image", mainApp.Image))
return false
} else {
logger.Info("main app image tag is latest, but digest is different, thus update is available", zap.String("image", mainApp.Image))
return true
}
}

storeMainApp := storeComposeApp.App(mainAppName)
Expand Down

0 comments on commit c9ed263

Please sign in to comment.