Build and deploy a Quarkus application to OpenShift in minutes

This exercise, created by Ian Lawson, demonstrates how you can go from initial app idea to prototype code in as little as five minutes using Quarkus, Podman Desktop, and the no-cost Developer Sandbox for Red Hat OpenShift. We'll scaffold a Quarkus application, build a container image locally using Podman Desktop, and then see how to install, run, and test the application in the Developer Sandbox from the command line.

In order to get full benefit from taking this lesson, you need:

  • Podman Desktop
  • Access to the Developer Sandbox

In this lesson, you will:

  • Build and test an image
  • Access Developer Sandbox
  • Use Podman Desktop

Build the image

For this step, you could use Podman at the command line, but we're going to use Podman Desktop to show how easy it is.

  1. Fire up the Podman Desktop application, go to the Images tab, and select Build Image. This will give you a simple wizard to enter the information needed to do the image build.
  2. We will use the scaffolded Containerfile and the generated binary artifacts. Click Select Containerfile to build.
  3. Follow the directory structure from your root directory where the pom.xml is and where you unzipped the source, down through the src/main/docker. Click the Dockerfile.jvm file.

    Info alert: Dockerfile and Containerfile are interchangeable terms; both refer to a file that lists the steps to take to build an image.

  4. There's a little gotcha here: Because the Containerfile was in a subdirectory, we have to give the Podman application a different context directory to look for the components.
  5. The Containerfile makes a direct reference to a target subdirectory, and because the Containerfile was down in the src/xxx directory, it will set the context directory there by default.
  6. Change the Build Context Directory to your root directory. In other words, remove the /src/main/docker bit.
  7. Change the name to something simple and memorable, and add a tag that isn't :latest. See Figure 2.

    Info alert: It's bad practice to use the :latest tag, as any builds you do overwrite any previous image with the :latest tag.

     
    Building the image wizard in Podman Desktop.
    Figure 2: Building the image wizard in Podman Desktop.
  8. Now select Build. If all goes well, it will complete pretty quickly.
  9. If you then navigate to the Images tab, you should see a generated image (Figure 3).
    The image list in Podman Desktop.
    Figure 3: The image list in Podman Desktop.

Test the image

Here is how you can test your image.

  1. From the Images tab in Podman Desktop, locate the image you just created, and click the Run icon on the far right to start a container using that image.
  2. In the wizard, leave everything as default because we just want to test our endpoint quickly.
  3. Click Start Container. Podman Desktop should switch to the Containers tab, and you will see a container running (with an improbable name).
  4. Pop back to a terminal window and enter:
    curl http://localhost:8080/hello/subdir
  5. You should see the system time and the code change you made earlier reported as a response. The image works!

Set up the Developer Sandbox interaction

Now comes the fun stuff.

  1. To start, we need to log into the Developer Sandbox. When you log in, you will be presented with the Developer viewpoint and offered a tour. If you have time, take the tour—it's very much worth it.
  2. When you're ready to proceed, click the drop-down menu in the upper-right corner of the window where your username is displayed.
  3. Select Copy Login Command. This opens a new window where you are given the command to log onto the Developer Sandbox via the oc CLI.
  4. Click Display Token, then copy the oc login command so you can paste and execute it in your terminal window. This command uses the oc tool, which was installed as part of the prerequisites, to log you onto the Developer Sandbox from your terminal.
  5. You can now interact with your project (which will be [username]-dev) directly, which is how we'll install and run the application we just created an image for.

Connect Podman to the Developer Sandbox

To install and run the application, we are going to log Podman onto the Developer Sandbox itself. This lets us use the Developer Sandbox integrated registry, which is how OpenShift controls and manages all images on the system directly.

A small caveat: The Developer Sandbox is actually a number of OpenShift clusters, and when you set up your account, you get assigned to one of them. In order to log Podman onto the appropriate cluster, you need to determine which cluster you're assigned to.

  1. At the terminal, type:
    oc whoami --show-server=true
  2. This command, which we will also use to get the token to log on to the registry, gives us information about who we are and where we are logged onto. The output of that command will look a little like this:
    https://api.sandbox-m3.1530.p1.openshiftapps.com:6443
  3. This is the RESTful API endpoint for our cluster. Yours might look slightly different.
  4. We are now going to use a neat little part of the oc whoami command to log us directly into the registry. This is the command we are going to use, but we need to change the target registry depending on the output of your oc whoami --show-server=true:
    podman login -u testuser -p $(oc whoami -t) default-route-openshift-image-registry.apps.sandbox-m3.1530.p1.openshiftapps.com

    Info alert: Important: Replace the registry route with the output of your oc whoami --show-server=true without the https and port number.

  5. If it all works, Podman will return a Login Succeeded! message.

Congratulations. At this point, you can push images directly from your local system into the Developer Sandbox registry. Now it's time to run the application.

Previous resource
Bootstrap Quarkus and build an image
Next resource
Run your Quarkus application