Im trying to utilise docker/cli client library in my own project to create/manage stacks.
I am however facing issues building the project.
Code below:
package main
import (
"fmt"
"log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/stack"
"github.com/docker/cli/cli/flags"
)
func main() {
cli, err := command.NewDockerCli(command.WithStandardStreams())
if err != nil {
log.Fatal(err)
}
cli.Initialize(flags.NewClientOptions())
cmd := stack.NewStackCommand(cli)
cmd.SetArgs([]string{"deploy", "--compose-file", "docker-compose.yml", "test"})
err = cmd.Execute()
if err != nil {
log.Fatal(err)
}
fmt.Println("success!")
}
I have setup a minimal go.mod:
module github.com/dev/test
go 1.16
When i run go get
; i get the following errors:
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api/defaults: cannot find module providing package github.com/docker/swarmkit/api/defaults
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api/genericresource: cannot find module providing package github.com/docker/swarmkit/api/genericresource
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api imports
google.golang.org/grpc/transport: cannot find module providing package google.golang.org/grpc/transport
I have had a deeper look into the docker/cli repo and it appears that the project does not use go modules; instead its using the older vendor
dir approach.
I was wondering how i can get the project to compile. Is there a way for go get
to automatically reference the packages in the vendor
directory of the imported docker/cli
project?