Skip to content

Reference library for the parsing and loading Compose files

License

Notifications You must be signed in to change notification settings

ndeloof/compose-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 (
	"fmt"
	"github.com/compose-spec/compose-go/loader"
	"github.com/compose-spec/compose-go/types"
	"log"
)

func main() {
	composeFilePath := "docker-compose.yml"
	projectName := "my_project"

	options, err := loader.NewProjectOptions(
		[]string{composeFilePath},
		types.WithOsEnv,
		types.WithDotEnv,
		types.WithName(projectName),
	)
	if err != nil {
		log.Fatal(err)
	}

	project, err := loader.ProjectFromOptions(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

About

Reference library for the parsing and loading Compose files

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.4%
  • Other 0.6%