This is a guide about deploying a Quarkus REST service in IBM Cloud Code Engine

Create a simple Quarkus REST service

First we create a sample Quarkus maven project :

mvn io.quarkus.platform:quarkus-maven-plugin:2.15.3.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=rest-json-quickstart \
    -Dextensions='resteasy-reactive-jackson' \
    -DnoCode
cd rest-json-quickstart

First, let’s create a Fruit domain model :

package org.acme.rest.json;

public class Fruit {

    public String name;
    public String description;

    public Fruit() {
    }

    public Fruit(String name, String description) {
        this.name = name;
        this.description = description;
    }
}

Next, let’s create the REST API for it:

package org.acme.rest.json;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

@Path("/fruits")
public class FruitResource {

    private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));

    public FruitResource() {
        fruits.add(new Fruit("Apple", "Winter fruit"));
        fruits.add(new Fruit("Pineapple", "Tropical fruit"));
    }

    @GET
    public Set<Fruit> list() {
        return fruits;
    }

    @POST
    public Set<Fruit> add(Fruit fruit) {
        fruits.add(fruit);
        return fruits;
    }

    @DELETE
    public Set<Fruit> delete(Fruit fruit) {
        fruits.removeIf(existingFruit -> existingFruit.name.contentEquals(fruit.name));
        return fruits;
    }
}

In order to test start Quarkus with:

mvn quarkus:dev

Then use curl to call the REST service:

curl http://localhost:8080/fruits -H 'Content-Type: application/json' 

Enable Uber-JAR creation

In order to get it running on IBM Cloud Code Engine we need a Uber-JAR and run on Java 11.

The best way to do that is to add the next settings in application.properties file:

quarkus.package.type=uber-jar

And then edit pom.xml and edit the target and runtime version:

    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>

Commit the project to GIT(HUB)

The next part is to commit the project to a (public) GIT instance, like GITHUB.

For GitHub, create a new repository, required commands in the project folder:

The commands should look something like this:

git init -b main
git add .
git commit -m "intial commit"
git remote add origin https://github.com/<username>/<project-name>.git
git push -u origin main

IBM Cloud part

Login to IBM Cloud and create a project in Code Engine.

1_code_engine_project_creation

Then go to the project and create a new application:

Give the application a name, the choose the application source to be source code and not container image , and enter the github repository url from above:

2_ibm_cloud_new_app_part_1

In Specify build details, select the Cloud Native Buildpack.

3_ibm_cloud_build_details

The create the application, and if all is ok, in the next 5 minutes the application should be up.

If everything is ok, then the build status should be Succeeded and the application status should be ready and revision status is also ready.

4_ibm_cloud_success

In order to get the application url, we click on the Test Aplication link and then on Application URL

Test the application

curl https://application-6a.xky0lxsu3gj.eu-de.codeengine.appdomain.cloud/fruits -H 'Content-Type: application/json' 

The result should be something like:

[{"name":"Apple","description":"Winter fruit"},{"name":"Pineapple","description":"Tropical fruit"}]