Skip to content
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

[Feature]: Support custom auth configs in container options #2759

Open
SpencerC opened this issue Aug 31, 2024 · 4 comments
Open

[Feature]: Support custom auth configs in container options #2759

SpencerC opened this issue Aug 31, 2024 · 4 comments
Labels
feature New functionality or new behaviors on the existing one

Comments

@SpencerC
Copy link

SpencerC commented Aug 31, 2024

Problem

In sandboxed/hermetic environments such as Bazel, $HOME is not available. This causes builds to fail following #2727. In our case, we're just using public registries so appearently being unable to load an auth config wasn't a problem before.

Solution

Add DockerConfig and DockerAuthConfig options to ContainerRequest or FromDockerfile.

Benefit

This would simplify the upgrade/management process for users running TestContainers in sandboxed environments. It also seems more consistent with the design of the rest of the package (e.g. configuration in code vs. environment variables).

Alternatives

Testers can always set DOCKER_CONFIG or DOCKER_AUTH_CONFIG in their bash profile, but then this needs to be done on every system running the tests.

Another approach is to map a sandbox path and set DOCKER_CONFIG at runtime:

dac, err := runfiles.Rlocation("_main/docker/.config")
if err != nil {
	log.Fatalf("could not get absolute path to docker auth config: %v", err)
}
if err := os.Setenv("DOCKER_CONFIG", dac); err != nil {
	log.Fatalf("could not set DOCKER_CONFIG: %v", err)
}

But this is a bit hacky.

Would you like to help contributing this feature?

Yes

@SpencerC SpencerC added the feature New functionality or new behaviors on the existing one label Aug 31, 2024
@SpencerC
Copy link
Author

I can do a PR for this if there's interest.

@SpencerC
Copy link
Author

SpencerC commented Sep 2, 2024

Testers can always set DOCKER_CONFIG or DOCKER_AUTH_CONFIG in their bash profile, but then this needs to be done on every system running the tests.

I'd like to walk back this statement a bit. Doing this works on my system (macOS), but has broken my colleagues' ability to run our tests. One is also running macOS, another is running linux.

@SpencerC
Copy link
Author

SpencerC commented Sep 2, 2024

@Geethree
Copy link

I too am hitting this on MacOS, linux is fine.

For awhile if I set env_inherit.. it would work, but that has stopped..

go_test(
    name = "testing_test",
    srcs = ["postgres_test.go"],
    embed = [":testing"],
    embedsrcs = [
        "migrations/20241006221227_test.down.sql",
        "migrations/20241006221227_test.up.sql",
    ],
    deps = [
        "@com_github_golang_migrate_migrate_v4//database/postgres",
        "@com_github_stretchr_testify//require",
    ],
    env_inherit = ["HOME"]
)

Any.. advice?

I don't fully follow you're runfiles approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

No branches or pull requests

2 participants