component/web: Implement nicer compose reader
This commit is contained in:
parent
1855090f26
commit
668f1dd193
6 changed files with 130 additions and 85 deletions
43
pkg/compose/compose.go
Normal file
43
pkg/compose/compose.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/compose-spec/compose-go/cli"
|
||||
"github.com/compose-spec/compose-go/loader"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
)
|
||||
|
||||
// ComposeProject represents a compose project
|
||||
type Project = *types.Project
|
||||
|
||||
// Open loads a docker compose project from the given path.
|
||||
// The returned name indicates the name, as would be found by the 'docker compose' executable.
|
||||
// If the project could not be found, an appropriate error is returned.
|
||||
//
|
||||
// NOTE: This intentionally omits using any kind of api for docker compose.
|
||||
// This saves a *a lot* of dependencies.
|
||||
func Open(path string) (project Project, err error) {
|
||||
ppath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts, err := cli.NewProjectOptions(
|
||||
/* configs = */ nil,
|
||||
cli.WithWorkingDirectory(ppath),
|
||||
cli.WithDefaultConfigPath,
|
||||
cli.WithName(loader.NormalizeProjectName(filepath.Base(ppath))),
|
||||
cli.WithDotEnv,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proj, err := cli.ProjectFromOptions(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return proj, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue