Skip to content

Reference library for parsing and loading Compose YAML files

License

Notifications You must be signed in to change notification settings

compose-spec/compose-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e3dffbf · Dec 19, 2024
May 13, 2024
Feb 7, 2024
Oct 30, 2024
Feb 27, 2024
May 16, 2024
Oct 7, 2024
Mar 22, 2024
Sep 30, 2024
Apr 19, 2024
Jan 21, 2024
Dec 19, 2024
Dec 2, 2024
Dec 2, 2024
Dec 11, 2024
Jan 3, 2022
Nov 12, 2024
Dec 2, 2024
Jan 15, 2024
Dec 11, 2024
Jul 11, 2024
Oct 9, 2024
Feb 28, 2023
Feb 27, 2024
Jan 23, 2024
Jan 24, 2020
Mar 19, 2020
Mar 25, 2020
Feb 3, 2020
Jun 16, 2020
Jun 21, 2024
Jun 22, 2020
Sep 15, 2024
Jun 7, 2024
Jun 7, 2024
Feb 4, 2024
Jun 3, 2024

Repository files navigation

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 := cli.ProjectFromOptions(ctx, options)
	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

Check the compose-spec.json file is sync with the compose-spec repository

make check_compose_spec

Used by