-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement]: Add ability to specify dockerProvider for NewDockerComposeWith to be able to disable reaper #2669
Comments
Hi, you can disable the reaper at the properties level https://golang.testcontainers.org/features/configuration/#customizing-ryuk-the-resource-reaper. Is that enough for your use case? |
@mdelapenya the problem is that I can't pass any configuration objects to The same for property file. I will need to ask the whole team to create this file. So, it's better to have ability to configure the other default value without env way |
Also, other problem with property file is that it is global. When I put @mdelapenya do you have any concerns with configurating doker provider? Otherwise, I could work on it |
We are planning to remove the DockerProvider abstraction in https://github.com/testcontainers/testcontainers-go/tree/v1. Please take a look and let me know how you feel with that code. For historical reasons, #941, we removed the ability to skip the reaper by container, as we want a centralised way to do it, like in the rest of the testcontainers language libraries. For your use case, I'd recommend setting up the environment at the project level in your CI, or setting it up in your build file (Make? Taskfile?...) |
I'm in a similar boat- we've gone through a lot of effort to make the We're having trouble with not being able to control the ryuk/reaper params programmatically. We want to do things like extend the reconnection timeout from 10s -> 30s, force privileged=true (podman requires it), etc- but it's frustrating to instruct everyone to add a I tried to work around these limitations by setting the env from my test os.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "30s") however, there's a package-level Line 18 in b78a351
Do you foresee a way around this? |
How would you see having a properties file in the project root dir that is versioned alongside the project and takes precedence over the user's home file? The precedence chain would be: EnvVars < project properties file < home properties Wdyt? |
@quolpr reading your initial request more carefully:
I think you are more interested in the reuse mode I guess. Setting a container name (this will eventually change) and the Reuse field in the container request struct, you tell Ryuk to not remove a container. Is that what you need? |
@mdelapenya hmm, I will check, thanks! As for
That sounds good actually 🙂 |
For reference, the reusable docs: https://golang.testcontainers.org/features/creating_container/#reusable-container |
@mdelapenya but is it possible to use reusable container with docker compose? Here how I make up now:
Not sure how to pass to compose container that they should be reusable |
No, reusable mode is. not affecting to compose containers, although it could be a desired feature request. |
@mdelapenya oh yeah, it seems I need this. Btw, my initial issue was connected with compose, that I can't disable ryuk with it 🙂. And yeah, reusable will help with it |
Btw, as temporary workaround I made this: package docker
import (
"bytes"
"context"
_ "embed"
"fmt"
"os"
"sync"
"github.com/docker/compose/v2/pkg/api"
tc "github.com/testcontainers/testcontainers-go/modules/compose"
)
var (
containerInit sync.Once
compose tc.ComposeStack
errCompose error
)
//go:embed docker-compose.yml
var dockerCompose []byte
func init() {
// https://github.com/testcontainers/testcontainers-go/issues/2669#issuecomment-2271056446
os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
}
func startCompose(ctx context.Context) (tc.ComposeStack, error) {
containerInit.Do(func() {
cmp, err := tc.NewDockerComposeWith(tc.WithStackReaders(bytes.NewReader(dockerCompose)), tc.StackIdentifier("mag_collect_test"))
if err != nil {
return
}
err = cmp.Up(
ctx,
tc.WithRecreate(api.RecreateNever),
tc.WithRecreateDependencies(api.RecreateNever),
tc.Wait(true),
)
if err != nil {
return
}
compose = cmp
errCompose = err
})
if errCompose != nil {
return nil, fmt.Errorf("failed to start compose: %w", errCompose)
}
return compose, nil
} Set env variable in init |
I think this would be a great enhancement, as it could guarantee any newcomers to our project have an out-of-the-box experience that "just works" 🙂 . I could spin off a separate issue for that if we think it's a good idea. |
Envvars can now be set from within go without them getting nuked by the package init #2725 |
Proposal
The problem: on dev machine I want to have tests to run fast. We are using docker compose way to prepare test env, and after test run all containers are deleting. I actually want to keep them running, and to achieve this I need to specify env variables to disabled reaper. It's actually not comfortable way, and I want to be able to specify ryuk config manually.
What I suggest is to add to
composeStackOptions
new fielddockerProvider *testcontainers.DockerProvider
+ new optWithDockerProvider(provider *testcontainers.DockerProvider)
. So then I can call it with:The text was updated successfully, but these errors were encountered: