如何在GO代码中拆下ArangodB的测试容器?

发布于 2025-02-06 12:44:19 字数 1039 浏览 0 评论 0原文

我正在尝试使用 https://golang.testcontainers.org 从图像中设置Docker容器我指定,而代码处于执行中。如上所述,将在程序终止之前清理容器,将在程序终止之前进行清理。

这是我必须设置一个“ ArangocontainerRequest”的代码:

arangoContainerRequest := testcontainers.ContainerRequest{
    Image:        "arangodb/arangodb:3.7.5",
    Name:         "arango",
    ExposedPorts: []string{"8529/tcp"},
    Env: map[string]string{
        // what config details to specify?
    },
    WaitingFor: wait.ForLog("Waiting for connections").WithStartupTimeout(time.Minute * 15),
}

这是我必须启动容器并推迟其终止的代码:

arangoContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
    ContainerRequest: arangoContainerRequest,
    Started:          true,
})
defer arangoContainer.Terminate(ctx)

有了这些代码,我得到了一个超时消息,说“上下文截止日期超过”,其中容器时间甚至没有被创建。

也许对于“ ArangocontainerRequest”地图中“ Env”字段的某些配置值,可以动态启用容器(也许容器不太笨重),但我无法弄清楚它。

任何形式的帮助都将不胜感激。

I'm trying to use https://golang.testcontainers.org to setup a docker container from the image that I specify, while the code is in execution. The container spun out, will be cleaned up before the program terminates, as mentioned in the above link.

This is the code I have to setup an "arangoContainerRequest" :

arangoContainerRequest := testcontainers.ContainerRequest{
    Image:        "arangodb/arangodb:3.7.5",
    Name:         "arango",
    ExposedPorts: []string{"8529/tcp"},
    Env: map[string]string{
        // what config details to specify?
    },
    WaitingFor: wait.ForLog("Waiting for connections").WithStartupTimeout(time.Minute * 15),
}

This is the code I have to start the container up and defer its termination :

arangoContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
    ContainerRequest: arangoContainerRequest,
    Started:          true,
})
defer arangoContainer.Terminate(ctx)

With these in place, I'm getting a timeout message saying "context deadline exceeded", where the container times out without even being created.

Maybe for some config value for the "Env" field in the "arangoContainerRequest" map, the container can be spun out dynamically (so that maybe the container isn't too bulky), but I'm unable to figure out the same.

Any form of help would be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没企图 2025-02-13 12:44:19

我会考虑查看Arangodb的官方文档,即Docker Hub页面: https:https:// https:// hub.docker.com/_/arangodb

我认为此代码段将帮助您设置容器,因为它对我有用。

    ctx := context.Background()

    networkName := "backend"

    newNetwork, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{
        NetworkRequest: testcontainers.NetworkRequest{
            Name:           networkName,
            CheckDuplicate: true,
        },
    })
    if err != nil {
        t.Fatal(err)
    }
    t.Cleanup(func() {
        require.NoError(t, newNetwork.Remove(ctx))
    })

    arangodb, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
        ContainerRequest: testcontainers.ContainerRequest{
            Image: "arangodb/arangodb:latest",
            Env: map[string]string{
                "ARANGODB_USERNAME":    "myuser",
                "ARANGODB_PASSWORD":    "mypassword",
                "ARANGODB_DBNAME":      "graphdb",
                "ARANGO_ROOT_PASSWORD": "myrootpassword",
            },
            Networks: []string{networkName},
            Resources: container.Resources{
                Memory: 256 * 1024 * 1024, // 512 MB
            },
            WaitingFor: wait.ForLog("is ready for business").WithStartupTimeout(time.Minute * 1),
        },
        Started: true,
    })
    require.NoError(t, err)
    defer arangodb.Terminate(ctx)

I'd consider checking out the official docs for ArangoDB, i.e. the Docker Hub page for it: https://hub.docker.com/_/arangodb

I think this code snippet will help you out in setting up the container, as it works for me.

    ctx := context.Background()

    networkName := "backend"

    newNetwork, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{
        NetworkRequest: testcontainers.NetworkRequest{
            Name:           networkName,
            CheckDuplicate: true,
        },
    })
    if err != nil {
        t.Fatal(err)
    }
    t.Cleanup(func() {
        require.NoError(t, newNetwork.Remove(ctx))
    })

    arangodb, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
        ContainerRequest: testcontainers.ContainerRequest{
            Image: "arangodb/arangodb:latest",
            Env: map[string]string{
                "ARANGODB_USERNAME":    "myuser",
                "ARANGODB_PASSWORD":    "mypassword",
                "ARANGODB_DBNAME":      "graphdb",
                "ARANGO_ROOT_PASSWORD": "myrootpassword",
            },
            Networks: []string{networkName},
            Resources: container.Resources{
                Memory: 256 * 1024 * 1024, // 512 MB
            },
            WaitingFor: wait.ForLog("is ready for business").WithStartupTimeout(time.Minute * 1),
        },
        Started: true,
    })
    require.NoError(t, err)
    defer arangodb.Terminate(ctx)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文