GitHub - compose-spec/compose-go: Reference library for parsing and loading Compose YAML files (original) (raw)
compose-go
Go reference library for parsing and loading Compose files as specified by theCompose specification.
Usage
package main
import ( "context" "fmt" "log"
"github.com/compose-spec/compose-go/v2/cli"
)
func main() { composeFilePath := "docker-compose.yml" projectName := "my_project" ctx := context.Background()
options, err := cli.NewProjectOptions(
[]string{composeFilePath},
cli.WithOsEnv,
cli.WithDotEnv,
cli.WithName(projectName),
)
if err != nil {
log.Fatal(err)
}
project, err := options.LoadProject(ctx)
if err != nil {
log.Fatal(err)
}
// Use the MarshalYAML method to get YAML representation
projectYAML, err := project.MarshalYAML()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(projectYAML))
}
Build the library
To build the library, you could either use the makefile
or use the go build command
Run the tests
You can run the tests with the makefile
or with the go test command
Other helpful make commands
Run the linter
Check the license headers
Check the compose-spec.json
file is sync with the compose-spec
repository