In this example we are making use of the WildFly runtime image to build a WildFly server docker image for our application (simple JAX_RS endpoint). In order to create a WildFly server containing our application, we are using the WildFly Maven Plugin.
The image is deployed and run locally using docker and to an Openshift cluster using Helm charts for WildFly.
High level view of the WildFly Maven plugin configuration
wildfly@maven(org.jboss.universe:community-universe)
: Resolve the latest released WildFly server.
cloud-server
WildFly CLI scripts executed at packaging time
- None
Extra content packaged inside the provisioned server
- None
Technologies required to build and deploy this example
- docker
- Helm chart for WildFly
wildfly/wildfly
. Minimal version2.0.0
.
-
You have docker setup.
-
You are logged into an OpenShift cluster and have
oc
command in your path -
You have installed Helm. Please refer to Installing Helm page to install Helm in your environment
-
You have installed the repository for the Helm charts for WildFly
helm repo add wildfly https://docs.wildfly.org/wildfly-charts/
NOTE
If you have already installed the Helm Charts for WildFly, make sure to update your repository to the latest version.
helm repo update
NOTE
Be sure you have created OpenShift project. In some clusters it is created by default, whereas in others you have to create it manually.
Check what project is currently active:
oc project -q
If above command returns with error stating no project has been set, create a project using following command:
oc new-project myproject
- Build the application and server
mvn clean package
- Build the docker image
docker build -t myapp:latest .
- Run the image
docker run myapp:latest
- Access the endpoint
curl http://<docker image IP>:8080/
- Stop the server
In the console type Ctrl-C
.
- Push the image to the Openshift Sandbox
Make sure to set the OPENSHIFT_IMAGE_REGISTRY
env variable with the actual route to the registry.
When logging to the registry, the route to the registry will be printed on the console.
export IMAGE=myapp:latest
export OPENSHIFT_NS=$(oc project -q)
oc registry login
# Copy the route in the env variable OPENSHIFT_IMAGE_REGISTRY
export OPENSHIFT_IMAGE_REGISTRY=$(oc registry info)
docker login -u openshift -p $(oc whoami -t) $OPENSHIFT_IMAGE_REGISTRY
docker tag $IMAGE $OPENSHIFT_IMAGE_REGISTRY/$OPENSHIFT_NS/$IMAGE
docker push $OPENSHIFT_IMAGE_REGISTRY/$OPENSHIFT_NS/$IMAGE
- Enable the pushed image stream resolution
oc set image-lookup myapp
- Deploy the example application using WildFly Helm charts
helm install myapp -f helm.yaml wildfly/wildfly
- Access the endpoint
curl https://$(oc get route myapp --template='{{ .spec.host }}')/