mirror of
https://github.com/compose-spec/compose-go.git
synced 2026-11-15 06:55:57 +00:00
Reference library for parsing and loading Compose YAML files
https://compose-spec.io
- Go 99.7%
- Makefile 0.2%
An include entry declared in a file that is itself included resolved its relative env_file, and its relative project_directory, against the working directory of the process. For the files of an included project the includer only knows the directory its model is relative to, that of the project above, which is right for the paths of the model, and was used as a path of the file system to look for the env file. Take the project directory of the including file from the local resource loader set by the entry that included it, and lock the behavior with a suite loading include trees from several working directories. Fixes docker/compose#14488 Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> |
History
|
|
|---|---|---|
| .github | ||
| ci | ||
| cli | ||
| cmd | ||
| consts | ||
| dotenv | ||
| errdefs | ||
| format | ||
| graph | ||
| internal/generate/containerspec | ||
| interpolation | ||
| loader | ||
| override | ||
| paths | ||
| schema | ||
| scripts/validate/template | ||
| template | ||
| transform | ||
| tree | ||
| types | ||
| utils | ||
| validation | ||
| .gitattributes | ||
| .gitignore | ||
| .golangci.yml | ||
| .pre-commit-config.yaml | ||
| AGENTS.md | ||
| CODE_OF_CONDUCT.md | ||
| CONTRIBUTING.md | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| MAINTENANCE.md | ||
| Makefile | ||
| NOTICE | ||
| package.go | ||
| parsing.md | ||
| README.md | ||
| TESTING.md | ||
compose-go
Go reference library for parsing and loading Compose files as specified by the Compose 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
make build
or use the go build command
go build ./...
Run the tests
You can run the tests with the makefile
make test
or with the go test command
gotestsum ./...
Other helpful make commands
Run the linter
make lint
Check the license headers
make check-license