Chapter 2. Deploying a container image for a Quarkus native application in a continuous integration as a serverless application

You can separate the native build, container build, and deployment steps when deploying a native serverless application. The following procedure demonstrates how to deploy a container image for a Quarkus native application in a continuous integration (CI) as a serverless application.

Prerequisites

  • OpenShift Serverless operator is installed.
  • OpenShift Knative Serving is installed.
  • For native compilation, a container environment like Podman or Docker is required.
  • The kn CLI tool is installed.

Procedure

  1. Change to the directory that contains your Quarkus project.
  2. Build a Linux executable using one of the following methods:

    1. For Docker use:

      ./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3
    2. For Podman use:

      ./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3
  3. Open the src/main/docker/Dockerfile.native file and set the <image_name> and <version> parameters:

    1. For Docker use:

      docker build -f src/main/docker/Dockerfile.native -t <image_name>:<version> .
    2. For Podman use:

      podman build -f src/main/docker/Dockerfile.native -t <image_name>:<version>.
  4. Push the container to a repository that your CI environment and your OpenShift environment can access, where <registry> is your registry URL:

    1. For Docker use:

      docker tag <image_name>:<version> <registry>/<image_name>:<version>
      docker push <registry>/<image_name>:<version>
    2. For Podman use:

      podman tag <image_name>:<version> <registry>/<image_name>:<version>
      podman push <registry>/<image_name>:<version>
  5. Log in to the OpenShift CLI (oc):

    oc login
  6. To create a new OpenShift project, enter the following command where <project_name> is the name of your new project:

    oc new-project <project_name>
  7. To deploy your container as a serverless application using the OpenShift Serverless CLI (kn), enter the following command where <service_name> is the name for your service:

    kn service create <service_name> --image REPOSITORY/<image_name>:<version>
  8. To verify that the service is ready, enter the following command.

    kn service list <service_name>

    The output in the column called "READY" reads true if the service is ready.

    Note

    The kn service command returns true when the necessary components are created, not when the image is pulled down and ready.