Closed DaspawnW closed 1 month ago
I found a solution that is maybe not the best but at least it works on my machine ;-)
public class TestContainerProxySetup {
private static final String BASE_DOCKER_IMAGE = "rockstorm/git-server:2.45";
private static final String BUILD_DOCKER_IMAGE_NAME = "git-server-with-proxy:2.45";
private static final String HTTP_PROXY = "http://localhost:3128";
private static final String HTTPS_PROXY = "http://localhost:3128";
private static final String NO_PROXY = "*.server.lan";
public static DockerImageName getDockerImage() {
if (isProxyEnabled()) {
buildGitServerBaseImageWithProxy();
return DockerImageName.parse(BUILD_DOCKER_IMAGE_NAME).asCompatibleSubstituteFor(BASE_DOCKER_IMAGE);
}
return DockerImageName.parse(BASE_DOCKER_IMAGE);
}
public static boolean isProxyEnabled() {
// TODO: implement logic to check if proxy is enabled
return true;
}
private static void buildGitServerBaseImageWithProxy() {
new ImageFromDockerfile(BUILD_DOCKER_IMAGE_NAME, false)
.withDockerfileFromBuilder(builder -> {
builder.from(BASE_DOCKER_IMAGE)
.env(Map.of(
"HTTP_PROXY", HTTP_PROXY,
"HTTPS_PROXY", HTTPS_PROXY,
"NO_PROXY", NO_PROXY
)).build();
}).get();
}
}
static GitHttpServerContainer gitServer = new GitHttpServerContainer(TestContainerProxySetup.getDockerImage(),
new BasicAuthenticationCredentials("user", "password"))
.waitingFor(new HostPortWaitStrategy());
Thanks for reporting. I will have a deeper look on it after my vacation.
Hi @DaspawnW, please check whether the implementation in #146 would work for you. It is a little bit different from your proposal, but it helps to point me in the right direction.
Hi,
FIrst of all thanks a lot for the great project! I'm trying to get the project up and running but I experience in an isolated environment issues while building the Http Part: https://github.com/sparsick/testcontainers-git/blob/main/testcontainers-gitserver/src/main/java/com/github/sparsick/testcontainers/gitserver/http/GitHttpServerContainer.java#L56 It simply fails due to the missing ability to set an
HTTP_PROXY
during the build command.Is there any plan to support this in the future?
Thank you in advance, Best regards, Björn