65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"hoster/internals/conf"
|
|
"io/fs"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
dc "github.com/compose-spec/compose-go/v2/cli"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func CmdCheckUpdated(c *cli.Context) error {
|
|
projectRoot := conf.App.MustString("projects.root")
|
|
|
|
composeFiles := []string{}
|
|
|
|
// Find compose files recursively
|
|
err := filepath.WalkDir(projectRoot, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
// Ignore errors on purpose.
|
|
return nil
|
|
}
|
|
|
|
if d.IsDir() {
|
|
return nil
|
|
}
|
|
|
|
fileName := d.Name()
|
|
|
|
if strings.HasPrefix(fileName, "docker-compose") && (strings.HasSuffix(fileName, ".yml") || strings.HasSuffix(fileName, ".yaml")) {
|
|
composeFiles = append(composeFiles, path)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
composeFilePath := composeFiles[0]
|
|
|
|
options, err := dc.NewProjectOptions(
|
|
[]string{composeFilePath},
|
|
)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
project, err := dc.ProjectFromOptions(context.Background(), options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for srvName, srv := range project.AllServices() {
|
|
fmt.Printf("%s => %s\n", srvName, srv.Image)
|
|
}
|
|
|
|
return nil
|
|
}
|