JBoss EAP and WildFly

Deploy a Jakarta REST catalog on JBoss EAP 8.1 for OpenShift: ImageStreams, an S2I assemble, a Deployment that follows the image tag, and health probes on port 9990. The same WAR runs on WildFly.

Updated CompTech Team

The Spring Boot and Quarkus labs each bring their own runtime. This lab puts a small Jakarta REST application on JBoss EAP 8.1, the Jakarta EE 10 server, and runs it on OpenShift. The server is provisioned at build time. The pod is a Deployment that follows an ImageStream tag, with probes on the management port.

WildFly is the project that EAP's server code is built from. The last section swaps the plugin and the images. The Deployment and the probe paths stay the same.

The application is a catalog of the same SKUs as Inventory: GET /catalog/GPU-NODE returns a name. Nothing is stored. A real catalog would read the database the Crunchy Postgres labs run.

Prerequisites

  • JDK 21 and Maven
  • OpenShift 4.x and oc, with a pull secret that can read registry.redhat.io
  • Podman, only if you build on the workstation (podman login registry.redhat.io)

EAP images are not on registry.access.redhat.com. A cluster that cannot pull registry.redhat.io has to mirror the two images below first.

Step 1: The WAR and the openshift profile

mkdir catalog-eap && cd catalog-eap
mkdir -p src/main/java/com/comptech/catalog

pom.xml. The openshift profile is what the S2I assemble script activates (mvn -Popenshift package). Plugin 2.0.0.Final-redhat-00009 is the version in the EAP 8.1 examples. If Maven cannot resolve it, use the current 2.0 plugin from maven.repository.redhat.com.

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.comptech</groupId>
  <artifactId>catalog-eap</artifactId>
  <version>1.0.0</version>
  <packaging>war</packaging>
  <properties>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.finalName>ROOT</project.build.finalName>
    <version.eap.plugin>2.0.0.Final-redhat-00009</version.eap.plugin>
  </properties>
  <repositories>
    <repository><id>redhat-ga</id><url>https://maven.repository.redhat.com/ga/</url></repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository><id>redhat-ga</id><url>https://maven.repository.redhat.com/ga/</url></pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>jakarta.ws.rs</groupId><artifactId>jakarta.ws.rs-api</artifactId>
      <version>3.1.0</version><scope>provided</scope>
    </dependency>
  </dependencies>
  <profiles><profile><id>openshift</id><build><plugins><plugin>
    <groupId>org.jboss.eap.plugins</groupId>
    <artifactId>eap-maven-plugin</artifactId>
    <version>${version.eap.plugin}</version>
    <configuration>
      <channels><channel><manifest>
        <groupId>org.jboss.eap.channels</groupId><artifactId>eap-8.1</artifactId>
      </manifest></channel></channels>
      <feature-packs>
        <feature-pack><location>org.jboss.eap:wildfly-ee-galleon-pack</location></feature-pack>
        <feature-pack><location>org.jboss.eap.cloud:eap-cloud-galleon-pack</location></feature-pack>
      </feature-packs>
      <layers><layer>cloud-server</layer></layers>
      <runtime-name>ROOT.war</runtime-name>
    </configuration>
    <executions><execution><goals><goal>package</goal></goals></execution></executions>
  </plugin></plugins></build></profile></profiles>
</project>

src/main/java/com/comptech/catalog/CatalogApp.java publishes the WAR at /. CatalogResource.java is the resource. Both classes are public, which is what Jakarta REST requires, so they are two files.

package com.comptech.catalog;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/")
public class CatalogApp extends Application {}
package com.comptech.catalog;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.Map;

@Path("/catalog")
public class CatalogResource {
    private static final Map<String, String> NAMES = Map.of(
        "SRV-RACK", "Rack server", "GPU-NODE", "GPU node", "TOR-SW", "Top-of-rack switch");

    @GET @Path("/{sku}") @Produces(MediaType.APPLICATION_JSON)
    public Response get(@PathParam("sku") String sku) {
        String name = NAMES.get(sku);
        if (name == null) return Response.status(Response.Status.NOT_FOUND).build();
        return Response.ok("{\"sku\":\"" + sku + "\",\"name\":\"" + name + "\"}").build();
    }
}

ROOT.war plus @ApplicationPath("/") makes the route /catalog/GPU-NODE.

cloud-server is the Galleon layer that trims EAP for a container and turns on MicroProfile Health. Health listens on the management interface, port 9990, at /health/live, /health/ready, and /health/started. The application listens on 8080. JBOSS_HOME inside the image is /opt/server.

Step 2: ImageStreams and the image

The builder image has Maven and the S2I scripts. It does not contain a server. Assemble runs the profile above and provisions one. The runtime image is what the pod runs.

oc new-project catalog
oc import-image eap81-builder \
  --from=registry.redhat.io/jboss-eap-8/eap81-openjdk21-builder-openshift-rhel9:latest --confirm
oc import-image eap81-runtime \
  --from=registry.redhat.io/jboss-eap-8/eap81-openjdk21-runtime-openshift-rhel9:latest --confirm
oc get imagestream

Dockerfile. The FROM lines are the ImageStreams you just imported, by their pull spec inside the cluster. A build pod in the catalog project can pull them.

FROM image-registry.openshift-image-registry.svc:5000/catalog/eap81-builder:latest AS builder
COPY --chown=jboss:root . /tmp/src
USER jboss
RUN /usr/local/s2i/assemble

FROM image-registry.openshift-image-registry.svc:5000/catalog/eap81-runtime:latest
COPY --from=builder --chown=jboss:root $JBOSS_HOME $JBOSS_HOME

.dockerignore contains target/ so a local provisioned server is not uploaded.

oc new-build --binary --strategy=docker --name=catalog-eap
oc start-build catalog-eap --from-dir=. --follow
oc get imagestream catalog-eap

oc new-build creates the ImageStream catalog-eap and a BuildConfig whose output tag is catalog-eap:latest. The docker strategy runs Buildah in the build pod. The container builds lab is that mechanism on its own. The EAP 8 Helm chart (jboss-eap/eap8) builds the same assemble as an S2I BuildConfig and deploys the same ImageStreamTag.

Step 3: Deployment, probes, Route

deploy/catalog-eap.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: catalog-eap
  annotations:
    image.openshift.io/triggers: >-
      [{"from":{"kind":"ImageStreamTag","name":"catalog-eap:latest"},"fieldPath":"spec.template.spec.containers[?(@.name==\"catalog-eap\")].image"}]
spec:
  replicas: 1
  selector:
    matchLabels: { app: catalog-eap }
  template:
    metadata:
      labels: { app: catalog-eap }
    spec:
      containers:
        - name: catalog-eap
          image: image-registry.openshift-image-registry.svc:5000/catalog/catalog-eap:latest
          ports:
            - { name: http, containerPort: 8080 }
            - { name: admin, containerPort: 9990 }
          startupProbe:
            httpGet: { path: /health/live, port: admin }
            failureThreshold: 60
            periodSeconds: 2
          readinessProbe:
            httpGet: { path: /health/ready, port: admin }
            periodSeconds: 10
          livenessProbe:
            httpGet: { path: /health/live, port: admin }
            periodSeconds: 10
          resources:
            requests: { cpu: 200m, memory: 512Mi }
            limits: { memory: 1Gi }
---
apiVersion: v1
kind: Service
metadata: { name: catalog-eap }
spec:
  selector: { app: catalog-eap }
  ports: [{ port: 80, targetPort: http }]
---
apiVersion: route.openshift.io/v1
kind: Route
metadata: { name: catalog-eap }
spec:
  to: { kind: Service, name: catalog-eap }
  tls: { termination: edge, insecureEdgeTerminationPolicy: Redirect }

The annotation is the Deployment form of an image-change trigger. When catalog-eap:latest moves, OpenShift rolls the pod. There is no CPU limit, for the same reason as the Spring Boot lab: a limit mostly throttles the garbage collector. The memory limit is 1Gi because this process is a server, not a single fat jar.

The Route publishes port 8080 only. Port 9990 stays on the pod. /health/live is the Helm chart's default liveness path. It stays UP while the process is up, including when a deployment failed, so a bad WAR makes the pod unready and does not restart it. Point the startup probe at /health/ready if a failed deployment should restart the pod.

A DeploymentConfig is the older object. Templates from EAP 7 and the Jenkins samples still use one. It carries the trigger itself, and you do not apply it next to the Deployment above:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata: { name: catalog-eap }
spec:
  replicas: 1
  selector: { app: catalog-eap }
  template:
    metadata:
      labels: { app: catalog-eap }
    spec:
      containers:
        - name: catalog-eap
          image: catalog-eap:latest
          ports: [{ containerPort: 8080 }]
  triggers:
    - type: ConfigChange
    - type: ImageChange
      imageChangeParams:
        automatic: true
        containerNames: [catalog-eap]
        from: { kind: ImageStreamTag, name: catalog-eap:latest }

New manifests in this series are Deployments.

oc apply -f deploy/catalog-eap.yaml
oc rollout status deployment/catalog-eap
curl -sk "https://$(oc get route catalog-eap -o jsonpath='{.spec.host}')/catalog/GPU-NODE"
# {"sku":"GPU-NODE","name":"GPU node"}
oc port-forward deploy/catalog-eap 9990:9990

In another terminal, curl -s localhost:9990/health/ready returns JSON with "status":"UP". Stop the port-forward with Ctrl-C. After a code change: oc start-build catalog-eap --from-dir=. --follow. The trigger rolls the Deployment when the tag updates.

WildFly

Build the same WAR on WildFly by editing the openshift profile: plugin org.wildfly.plugins:wildfly-maven-plugin, feature packs org.wildfly:wildfly-galleon-pack and org.wildfly.cloud:wildfly-cloud-galleon-pack, and the channel manifest for the WildFly release you are building. Those artifacts resolve from Maven Central, so the Red Hat repository can come out of the pom. Import quay.io/wildfly/wildfly-s2i:latest as the builder and quay.io/wildfly/wildfly-runtime:latest as the runtime, and point the Dockerfile at those ImageStreams. Probes stay on port 9990. The Deployment YAML does not change.

Troubleshooting

Symptom Likely cause Fix
Assemble cannot resolve org.jboss.eap Plugin version or channel not in the GA repository Use the 2.0 plugin the repository currently lists; confirm eap-8.1
ErrImagePull on eap81-builder No entitlement for registry.redhat.io Fix the cluster pull secret, or mirror the image
Pod stays unready, logs show a deployment error WAR failed, and /health/live will not restart it Read oc logs deploy/catalog-eap; fix the WAR and rebuild
Route returns 404 for /catalog WAR context is not / runtime-name must be ROOT.war; check the server log for the context

Clean up

oc delete project catalog

What's next

Open Liberty and Tomcat are the other two servers in this set. Container builds is Buildah, S2I, and the registry this ImageStream landed in. Spring Boot is the same SKUs as an Inventory API.