Bookmark this page

Guided Exercise: Managing Application Builds

Configure and manage Red Hat OpenShift builds.

Outcomes

  • Use the CLI to manage builds on OpenShift.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start builds-applications

Instructions

  1. Inspect the source code for the sample application.

    1. Navigate to the ~/DO288/DO288-apps/apps/builds-applications/vertx-site directory.

      [student@workstation ~]$ cd ~/DO288/DO288-apps/apps/builds-applications/vertx-site
      ...no output expected...
    2. Open the pom.xml file. Notice the maven-shade-plugin configuration:

      ...output omitted...
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <version>${maven-shade-plugin.version}</version>
        <executions>
      ...output omitted...
        <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
      ...output omitted...

      The build process creates the vertx-site-1.0.0-SNAPSHOT-fat.jar shaded JAR file, which you can execute by using the java -jar command.

    3. Explore the src/main/java/com/redhat/vertx_site/MainVerticle.java file.

      The application listens on port 8080 and returns HTML text.

  2. Log in to Red Hat OpenShift and use the builds-applications project.

    1. Log in to OpenShift as the developer user.

      [student@workstation vertx-site]$ oc login -u developer -p developer \
      https://api.ocp4.example.com:6443
      Login successful.
      ...output omitted...
    2. Ensure that you use the builds-applications project.

      [student@workstation vertx-site]$ oc project builds-applications
      Already on project "builds-applications" on server "https://api.ocp4.example.com:6443".
  3. Create an application build.

    1. Build the vertx-site application from source code in Git.

      Use the following parameters for the build:

      • Application name: vertx-site

      • Build environment variable: MAVEN_MIRROR_URL=http://nexus-infra.apps.ocp4.example.com/java

      • Environment variable: JAVA_APP_JAR=vertx-site-1.0.0-SNAPSHOT-fat.jar

      • Image stream: redhat-openjdk18-openshift:1.8

      • Build directory: apps/builds-applications/vertx-site

      • Source code: https://git.ocp4.example.com/developer/DO288-apps

      You can execute the oc-new-app.sh script in the current vertx-site directory, or execute the command manually:

      [student@workstation vertx-site]$ oc new-app --name vertx-site \
      --build-env \
      MAVEN_MIRROR_URL=http://nexus-infra.apps.ocp4.example.com/java \
      --env JAVA_APP_JAR=vertx-site-1.0.0-SNAPSHOT-fat.jar \
      -i redhat-openjdk18-openshift:1.8 \
      --context-dir apps/builds-applications/vertx-site \
      https://git.ocp4.example.com/developer/DO288-apps
      --> Found image 11c20bc (23 months old) in image stream ...output omitted...
    2. See the build logs.

      [student@workstation vertx-site]$ oc logs -f buildconfig/vertx-site
      Cloning "https://git.ocp4.example.com/developer/DO288-apps" ...
      ...output omitted...
      [INFO] Downloading from mirror.default: http://nexus-infra.apps.ocp4.example.com/java/io/vertx/vertx-stack-depchain/4.4.4/vertx-stack-depchain-4.4.4.pom
      [ERROR] [ERROR] Some problems were encountered while processing the POMs:
      [ERROR] Non-resolvable import POM: Could not find artifact io.vertx:vertx-stack-depchain:pom:4.4.4 in mirror.default (http://nexus-infra.apps.ocp4.example.com/java) @ line 28, column 19
      ...output omitted...

      The build failed because it could not download application dependencies.

    3. See the build status.

      [student@workstation vertx-site]$ oc get build
      NAME           TYPE     FROM          STATUS ...
      vertx-site-1   Source   Git@8e8b86d   Failed (GenericBuildFailed) ...
    4. Verify the correct classroom Maven repository URL.

      [student@workstation vertx-site]$ cat ~/.m2/settings.xml
      ...output omitted...
      <url>http://nexus-infra.apps.ocp4.example.com/repository/java</url>
      ...output omitted...

      The build environment variable is missing the /repository/ part of the Maven repository URL.

  4. Correct the application build by using the correct MAVEN_MIRROR_URL build variable.

    1. Delete OpenShift objects in the current project.

      [student@workstation vertx-site]$ oc delete all --all
      service "vertx-site" deleted
      deployment.apps "vertx-site" deleted
      ...output omitted...
    2. Re-execute the previous oc new-app command with the correct Maven repository URL.

      [student@workstation vertx-site]$ oc new-app --name vertx-site \
      --build-env \
      MAVEN_MIRROR_URL=http://nexus-infra.apps.ocp4.example.com/repository/java \
      --env JAVA_APP_JAR=vertx-site-1.0.0-SNAPSHOT-fat.jar \
      -i redhat-openjdk18-openshift:1.8 \
      --context-dir apps/builds-applications/vertx-site \
      https://git.ocp4.example.com/developer/DO288-apps
      --> Found image 11c20bc (23 months old) in image stream ...output omitted...
    3. Wait for the build object to finish.

      [student@workstation vertx-site]$ oc wait --for=condition=complete \
      --timeout=600s build/vertx-site-1
      build.build.openshift.io/vertx-site-1 condition met
    4. Verify the application pods.

      [student@workstation vertx-site]$ oc get po
      NAME                         READY   STATUS      RESTARTS      AGE
      vertx-site-1-build            0/1     Completed   0          65s
      vertx-site-7b9db94ffc-9bdkt   1/1     Running     0          29s
    5. Expose the application by creating a route.

      [student@workstation vertx-site]$ oc expose svc vertx-site
      route.route.openshift.io/vertx-site exposed
    6. Verify that the application is accessible:

      [student@workstation vertx-site] curl \
      vertx-site-builds-applications.apps.ocp4.example.com
      <html><body><h1>Welcome to your Vert.x v1.0 application!</h1></body></html>
  5. Modify and rebuild the application.

    1. Modify the handleRoot method in the src/main/java/com/redhat/vertx_site/MainVerticle.java file.

      private void handleRoot(RoutingContext routingContext) {
          HttpServerResponse response = routingContext.response();
      
          // Set the content type header
          response.putHeader("Content-Type", "text/html");
      
          // Send HTML content as the response
          response.end("<html><body><h1>Welcome to your Vert.x v2.0 application!</h1></body></html>");
      }
    2. Commit the changes in the git repository.

      [student@workstation vertx-site]$ git commit -am "Modify the application version"
      [master c46b365] Modify the application
       Committer: Student User <student@workstation.lab.example.com>
      ...output omitted...
    3. Push the changes to the remote git server. Use the developer user with the developer password.

      [student@workstation vertx-site]$ git push
      Username for 'https://git.ocp4.example.com': developer
      Password for 'https://developer@git.ocp4.example.com': developer
      warning: redirecting to https://git.ocp4.example.com/developer/DO288-apps.git/
      Enumerating objects: 24, done.
      Counting objects: 100% (24/24), done.
      Delta compression using up to 2 threads
      Compressing objects: 100% (11/11), done.
      Writing objects: 100% (23/23), 3.74 KiB | 1.87 MiB/s, done.
      Total 23 (delta 2), reused 0 (delta 0), pack-reused 0
      To https://git.ocp4.example.com/developer/DO288-apps
         b3c0f36..22ed9d5  master -> master

      Note

      Git might prompt for credentials by opening a desktop window. If you prefer to enter the credentials in the terminal, then close the window.

    4. Rebuild the application and follow the build logs.

      [student@workstation vertx-site]$ oc start-build --follow bc/vertx-site
      build.build.openshift.io/vertx-site-2 started
      Adding cluster TLS certificate authority to trust store
      ...output omitted...
    5. Verify application functionality by opening the vertx-site-builds-applications.apps.ocp4.example.com URL in a web browser.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish builds-applications

Revision: do288-4.12-0d49506