Skip to content

Commit

Permalink
Update container.go
Browse files Browse the repository at this point in the history
  • Loading branch information
door7302 authored Jul 15, 2024
1 parent 52cb7fa commit 3e3b2a5
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func StopContainer(name string) {

}

func GetVersionLabel(names []string) string {

func GetVersionLabel(names string) string {
version := "N/A"
// Open Docker API
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
Expand All @@ -79,26 +79,24 @@ func GetVersionLabel(names []string) string {
}
defer cli.Close()

version := ""
for _, name := range names {
// Get the image details using the Docker API
imageInspect, _, err := cli.ImageInspectWithRaw(context.Background(), name)
if err != nil {
logger.Log.Errorf("Unable to retrieve Docker %s inspect data: %v", name, err)
version += name + "(N/A) "
continue
}

// Extract the version label from imageInspect.Config.Labels
vers, ok := imageInspect.Config.Labels["version"]
if !ok {
logger.Log.Errorf("Unable to retrieve Docker %s version", name)
version += name + "(N/A) "
continue
}
version += name + "(" + vers + ") "
logger.Log.Infof("%s container version is %s", name, version)

// Get the image details using the Docker API
imageInspect, _, err := cli.ImageInspectWithRaw(context.Background(), name)

Check failure on line 84 in container/container.go

View workflow job for this annotation

GitHub Actions / Build

undefined: name
if err != nil {
logger.Log.Errorf("Unable to retrieve Docker %s inspect data: %v", name, err)

Check failure on line 86 in container/container.go

View workflow job for this annotation

GitHub Actions / Build

undefined: name
return "N/A"

}

// Extract the version label from imageInspect.Config.Labels
vers, ok := imageInspect.Config.Labels["version"]

Check failure on line 92 in container/container.go

View workflow job for this annotation

GitHub Actions / Build

vers declared and not used
if !ok {
logger.Log.Errorf("Unable to retrieve Docker %s version", name)

Check failure on line 94 in container/container.go

View workflow job for this annotation

GitHub Actions / Build

undefined: name
return "N/A"

}

logger.Log.Infof("%s container version is %s", name, version)

Check failure on line 99 in container/container.go

View workflow job for this annotation

GitHub Actions / Build

undefined: name
return version

}

0 comments on commit 3e3b2a5

Please sign in to comment.