Giter Site home page Giter Site logo

Comments (6)

decentral1se avatar decentral1se commented on August 20, 2024

Oh, think I found it in compose-ref:

func load(file string) (*compose.Config, error) {
	b, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}
	config, err := loader.ParseYAML(b)
	if err != nil {
		return nil, err
	}
	var files []compose.ConfigFile
	files = append(files, compose.ConfigFile{Filename: file, Config: config})
	return loader.Load(compose.ConfigDetails{
		WorkingDir:  ".",
		ConfigFiles: files,
	})
}

I can't quite get it to run right now but it seems like a good start.

from compose-go.

hiimdoublej-swag avatar hiimdoublej-swag commented on August 20, 2024

Just stumbled upon this as well, would like some section in README to try out but I guess the developers for this assumed golang familiarity. For what it's worth I think you can just modify some of the tests to get going.

from compose-go.

qknight avatar qknight commented on August 20, 2024

@decentral1se did you get something working? If so, could you plase paste it here?

from compose-go.

qknight avatar qknight commented on August 20, 2024

I got this here working:

import (
	"fmt"
	"github.com/compose-spec/compose-go/loader"
	"log"
)
import "github.com/compose-spec/compose-go/types"

func main() {
	file := "docker-compose.yaml"

	var configFiles []types.ConfigFile = []types.ConfigFile{{Filename: file}}
	var configDetails types.ConfigDetails = types.ConfigDetails{WorkingDir: ".", ConfigFiles: configFiles}

	p, e := loader.Load(configDetails)
	if e != nil {
		log.Fatalf("Failed to load file: %v", e)
	}
	fmt.Println("xxxxxxxx Name xxxxxxxxxx")
	fmt.Println(p.Name)
	fmt.Println("xxxxxxxx Services xxxxxxxxxx")
	for i := range p.Services {
		fmt.Println(p.Services[i].Name)
	}
	fmt.Println("xxxxxxxxxxxxxxxxxx")
}

from compose-go.

decentral1se avatar decentral1se commented on August 20, 2024

Ended up not using it @qknight, glad you got something going!

from compose-go.

ndeloof avatar ndeloof commented on August 20, 2024

The recommended approach is tu rely on cli.ProjectFromOptions
see https://github.com/docker/compose/blob/main/cmd/compose/compose.go for a concrete example

from compose-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.