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

Support TestContainers #7927

Closed
gastaldi opened this issue Oct 5, 2020 · 16 comments
Closed

Support TestContainers #7927

gastaldi opened this issue Oct 5, 2020 · 16 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@gastaldi
Copy link

gastaldi commented Oct 5, 2020

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

This is a follow-up of testcontainers/testcontainers-java#2088.
It would be nice if podman could be used with TestContainers.

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 5, 2020
@mheon
Copy link
Member

mheon commented Oct 5, 2020

Can you link any current issues that need to be resolved here?

@zhangguanzhang
Copy link
Collaborator

this issue #7923
I was unable to recreate on master, I believe it was taken care of in cde367c

@ruddy32
Copy link

ruddy32 commented Oct 27, 2020

"//var/run/docker.sock" is not setup dynamically when API start.
It seem to be a problem with TestContainer.

@rhatdan
Copy link
Member

rhatdan commented Oct 27, 2020

You need to install podman-docker, for this to happen.

@rhatdan rhatdan closed this as completed Oct 31, 2020
@bsideup
Copy link

bsideup commented Oct 31, 2020

Hey @rhatdan,

does it mean that all known issues with Podman and Testcontainers are fixed now and that 100% of TC's test suite passes with Podman? 🎉

@rhatdan
Copy link
Member

rhatdan commented Nov 2, 2020

I have no idea. But we need specific issues reported to what is broken. No one on the Podman team is concentrating on testing TestContainers. Community members have been taking the lead on this, and reporting issues, that we will attempt to fix ASAP.

@psakar
Copy link
Contributor

psakar commented Nov 21, 2020

I was able to successfully run test involving postgresql db using podman built from 2.2.0.RC1 with fixes from #8440, #8429 and #8423

podman (rootless) started with

podman system service -t 0 tcp:localhost:8880 &

test containers started with following environment variables set

DOCKER_HOST=tcp://localhost:8880
TESTCONTAINERS_RYUK_DISABLED=true

Test containers version 1.14.3 or 1.15.0

@ruddy32
Copy link

ruddy32 commented Nov 22, 2020

Does it means podman API do not provide a docker compatible socket?

Applying changes to /usr/lib/systemd/user/podman.service with
ExecStart=/usr/bin/podman system service -t 0 tcp://localhost:8880
and remove socket Requires and After instruction

... and updating maven build configuration with

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<configuration>
		<systemPropertyVariables>
			<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
		</systemPropertyVariables>
		<environmentVariables>
			<DOCKER_HOST>tcp:///localhost:8880</DOCKER_HOST
			<TESTCONTAINERS_RYUK_DISABLED>true</TESTCONTAINERS_RYUK_DISABLED>
			<api.version>v2</api.version>
			<KEYCLOAK_SERVICE>http://localhost:8180</KEYCLOAK_SERVICE>
		</environmentVariables>
	</configuration>
</plugin>

... and running podman api using command systemctl --user start podman.service

give the following build result in maven test phase

Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
	at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:214)

Is there something wrong in my configuration?

@psakar
Copy link
Contributor

psakar commented Nov 22, 2020

@ruddy32 your comment does not provide enough information so anybody can provide you some useful help.
Best would be either link to your project with description how to reproduce or in case it is private project please create public "minimal" project reproducing your problem.

General hints based on your comment
0. Have you build the podman containing the fixes mentioned above ? (ATM only two are merged to master, you have to cherry pick the third one or wait for PR to be reviewed / possibly further fixed and merged)

  1. Make it work without systemd service first - that rules out problems cased by possibly wrong setup of service
  2. The exception mentioned in the end of your comment has root cause (which you have not pasted here).I've seen for example case, when root cause was ClassNotFound exception because of fasterxml related classes required for test containers "clashed" with old fasterxml dependency used by the project under test. That can be but does not have to be your case - hard to say without knowing the root cause of "Could not find a valid Docker environment"

@ruddy32
Copy link

ruddy32 commented Nov 22, 2020

Is there something wrong in my configuration?

I was using podman 2.1.1, which does not include last changes listed by @psakar :-(
Sorry for disturb!

@zkirill
Copy link

zkirill commented Nov 24, 2020

I was able to successfully run my Spring Boot test involving PostgreSQL with podman 2.2.0-dev (4fe7c3f) and testcontainers 1.15.0 after introducing a third environment variable [1] in addition to the ones @psakar specified:

TESTCONTAINERS_CHECKS_DISABLE=true

Also, my testcontainers setup completely ignored any normal location for testcontainers environment variables [1] and I had to set them in the Run/Debug Configurations of IntelliJ for the test. Otherwise, the environment variables would never be picked up by EnvironmentAndSystemPropertyClientProviderStrategy for whatever reason.

-- EDIT 2 --

The following approach also worked for me after I learned about podman-docker and referenced the Podman API documentation [2].

I could not use podman-docker by itself because I kept getting access denied exceptions on /var/run/docker.sock.

  1. Install podman-docker (is this still necessary given step 2?).
  2. Run # podman system service -t 0
  3. Set environment variable DOCKER_HOST=unix:///run/user/1000/podman/podman.sock.
  4. Make sure the environment variable to disable Ryuk is still set to true.

-- EDIT 3 --

Adding a reference to podman-system-service [3] explaining "rootful" service, "rootless" service and "$XDG_RUNTIME_DIR" to hopefully save someone else some time. It took me a while to piece this together because I did not understand what I was searching for.

[1] https://www.testcontainers.org/features/configuration/#configuration-locations
[2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/building_running_and_managing_containers/using-the-container-tools-api_using-the-container-tools-cli
[3] https://github.com/containers/podman/blob/master/docs/source/markdown/podman-system-service.1.md

@ruddy32
Copy link

ruddy32 commented Dec 20, 2020

Running podman 2.2.1 with

 systemctl --user start podman.service

Installing host with podman-docker 2.2.1.

Configuring maven 3.6.3 build with

 			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.22.2</version>
				<configuration>
					<environmentVariables>
						<DOCKER_HOST>unix:///run/user/1000/podman/podman.sock</DOCKER_HOST>
						<TESTCONTAINERS_RYUK_DISABLED>false</TESTCONTAINERS_RYUK_DISABLED>
						<api.version>v2</api.version>
						...
					</environmentVariables>
				</configuration>
			</plugin>

Running maven test produce following message

ERROR] fakeTest  Time elapsed: 0.009 s  <<< ERROR!
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: com.github.dockerjava.api.exception.InternalServerErrorException: 
Status 500: {"cause":"incorrect volume format, should be [host-dir:]ctr-dir[:option]","message":"fill out specgen: unix:///run/user/1000/podman/podman.sock:/var/run/docker.sock:rw: incorrect volume format, should be [host-dir:]ctr-dir[:option]","response":500}

DockerJava concat both DOCKER_HOST definition and '/var/run/docker.sock' instead of using DOCKER_HOST definition only (unix:///run/user/1000/podman/podman.sock:rw).

It seems to be a problem with DockerJava or TestContainer host configuration. Could it be a problem with Podman host configuration?

@mheon
Copy link
Member

mheon commented Dec 20, 2020

Providing the JSON payload for the failing container create call would be greatly helpful here - seems likely that Testcontainers is sending valid JSON but we're not parsing the volumes bit correctly.

@ruddy32
Copy link

ruddy32 commented Dec 23, 2020

Providing the JSON payload for the failing container create call would be greatly helpful here.

The container used is KeyCloack 10 and 11. How to capture JSON payload?

@mheon
Copy link
Member

mheon commented Dec 23, 2020

You can use socat to capture the HTTP traffic to and from the Podman socket; @baude knows how to do so better than I.

@bsantanna
Copy link

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

10 participants