- First we must login to the remote OpenShift cluster as recommended by the provider. For example:
Next, it is necessary to note the remote OpenShift's Docker registry. This registry is required so that we can push our created images to the remote registry, which enables other services deployed in OpenShift to consume them. In our case it will be registry.online-int.openshift.com.
- Create an OpenShift project:
- Switch to the project:
- Build your image that you'd like to test in remote OpenShift. I've used Infinispan server Docker image which is extended in our project.
Our Dockerfile looks like this. It doesn't really modify any behaviour, it just shows that we can create our own image based on another image and push it to the remote OpenShift's Docker registry. Should you be interested in how to build a Docker image from a snapshot of Infinispan server, refer to an older article: Bleeding edge on Docker
- Build the remote container's image where tests will be run. In our case WildFly with a few modifications.
The Dockerfile for a modified WildFly server looks like this:
The Dockerfile above exposes port 9990, this is required so that Arquillian is to be able to perform a remote deployment via the management port. Furthermore, we also expose the management interface on address 0.0.0.0 so that the port is forwarded to the localhost. Finally, we add a user who will later connect and login via Arquillian.
- Login to remote docker registry:
- Tag your images and push them to the remote docker registry.
sudo docker tag infinispan-server-dev registry.online-int.openshift.com/myproject/infinispan-server-dev
sudo docker push registry.online-int.openshift.com/myproject/infinispan-server-dev
sudo docker tag wildfly11-testrunner registry.online-int.openshift.com/myproject/wildfly11-testrunner
sudo docker push registry.online-int.openshift.com/myproject/wildfly11-testrunner
- Enable image stream lookups for our images so that we can use them from our application.
oc set image-lookup wildfly11-testrunner
- Create an application that will be using our infinispan-server-dev image:
- Run the functional tests from Maven:
kkF_eC3ZXcsddf5RUeZFXw4Ce9rC_uVVZt875mLsQ
clean test -f functional-tests/pom.xml
This maven command specifies a property named kubernetes.auth.token. This token is used to create an OpenShiftClient instance within the WildFly container.
The arquillian.xml file follows.
Notice the definitionsFile property which specifies the WildFly server's pod. We previously pushed the image and created the image stream that is now available in OpenShift. And the wildfly11-testrunner consumes the WildFly image by pointing to the image stream called "wildfly11-testrunner:latest"
Here's the json definition
The test class is less interesting. It basically needs a method annotated with @Deployment. This method tells Arquillian which classes/libraries to bundle withing the archive which is deployed in a remote container (in this case, WildFly 11).
Another interesting part is that Arquillian Cube's annotations such as @Named, or @RouteURL don't work in-container as of now. Similar to injecting OpenShiftClient via @ArquillianResource. So we have to create our own instances manually.
There you go. The full working example is available at https://github.com/mgencur/arquillian-remote-openshift-example . The project has a convenient Makefile which can do all the steps by simply invoking `make test-remote`. The readme file provides more info how to run the tests.
Žádné komentáře:
Okomentovat