dockercliswarm包导入问题

我试图在我自己的项目中利用docker/cli客户端库来创建/管理堆栈。

但是,我在构建项目时遇到了问题。


代码如下:

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!")
}

我已经设置了一个最小的 go.mod:

module github.com/dev/test

go 1.16

当我跑步时go get;我收到以下错误:

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

我对docker/cli repo进行了更深入的研究,似乎该项目没有使用 go 模块;相反,它使用旧的vendordir 方法。

我想知道如何让项目编译。有没有办法go get自动引用vendor导入docker/cli项目目录中的包?

以上是dockercliswarm包导入问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>