Reference library for parsing and loading Compose YAML files https://compose-spec.io
  • Go 99.7%
  • Makefile 0.2%
Find a file
Nicolas De Loof 08138d8f47 fix(loader): resolve the env_file and project_directory of a nested include against its declaring file
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 2026-11-13 10:40:28 +01:00
.github ci: read the golangci-lint version from ci/Dockerfile 2026-10-23 08:40:57 +02:00
ci ci: install golangci-lint from its official image 2026-10-22 19:11:02 +02:00
cli Revert the Logger option: warnings go through the global logrus logger again 2026-10-25 14:08:20 +01:00
cmd use go.yaml.in/yaml/v4 2025-11-12 14:33:23 +01:00
consts Revert "Fix compose schema" 2024-05-16 14:56:09 +02:00
dotenv Revert the Logger option: warnings go through the global logrus logger again 2026-10-25 14:08:20 +01:00
errdefs errdefs: fix the doc-comment of IsIncompatibleError 2026-10-22 17:37:02 +02:00
format format: tell whether a volume can be said in the short syntax 2026-11-12 10:14:32 +01:00
graph lint: enable forbidigo to require t.Context() in tests 2026-10-22 17:10:59 +02:00
internal/generate/containerspec Revert the Logger option: warnings go through the global logrus logger again 2026-10-25 14:08:20 +01:00
interpolation interpolation: fuzz the interpolation of a model 2026-10-23 16:00:08 +02:00
loader fix(loader): resolve the env_file and project_directory of a nested include against its declaring file 2026-11-13 10:40:28 +01:00
override override: drop the dead volumeIndexer assignment for devices 2026-10-25 11:34:37 +01:00
paths paths: resolve an additional build context written as a number or a boolean 2026-10-25 11:34:53 +01:00
schema fix(loader): resolve the extends of a job against the jobs of the file 2026-10-23 10:03:58 +02:00
scripts/validate/template run dockerized 2025-02-25 09:28:04 +01:00
template Extract variables nested in required-error messages 2026-11-09 09:16:25 +01:00
transform Revert the Logger option: warnings go through the global logrus logger again 2026-10-25 14:08:20 +01:00
tree lint: fix gocritic, gofumpt and govet issues 2026-09-29 18:37:20 +02:00
types fix(types): resolve the images of hook volumes and of jobs 2026-11-10 15:09:04 +01:00
utils replace uses of testify 2026-08-27 12:20:33 +02:00
validation validation: leave a non-boolean external to the model decoding 2026-10-23 16:00:08 +02:00
.gitattributes test(loader): golden-file harness pinning loader output 2026-09-10 17:44:16 +02:00
.gitignore template: fuzz Substitute and ExtractVariables 2026-10-23 16:00:08 +02:00
.golangci.yml lint: replace gocyclo with gocognit, as in docker/compose 2026-10-22 19:24:33 +02:00
.pre-commit-config.yaml Remove dependency on docker/docker 2020-01-24 16:41:49 +01:00
AGENTS.md docs: TESTING.md codifies the testing contract 2026-09-02 18:41:28 +02:00
CODE_OF_CONDUCT.md Add code of conduct 2020-03-19 13:47:06 +01:00
CONTRIBUTING.md Add contributing guide 2020-03-25 15:45:24 +01:00
go.mod build: bump Go to 1.26.11 2026-11-12 10:56:41 +01:00
go.sum build(deps): bump go.yaml.in/yaml/v4 to v4.0.0 2026-11-05 18:16:21 +01:00
LICENSE license 2025-05-14 09:17:18 +02:00
MAINTENANCE.md docs: rewrite MAINTENANCE.md for the current codebase 2026-10-22 17:36:43 +02:00
Makefile template: fuzz Substitute and ExtractVariables 2026-10-23 16:00:08 +02:00
NOTICE Add NOTICE file 2020-06-22 11:46:47 +02:00
package.go docs: use the /v2 module path in the import comment and the badge 2026-10-22 17:36:43 +02:00
parsing.md Update go-yaml to the official fork 2025-07-15 07:40:54 +02:00
README.md docs(readme): fix the make targets that do not exist 2026-10-22 17:36:43 +02:00
TESTING.md template: fuzz Substitute and ExtractVariables 2026-10-23 16:00:08 +02:00

compose-go

Continuous integration Go Reference

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

Used by