Bookmark this page

Guided Exercise: Triggering Builds

Configure the triggering of automatic builds based on events.

In this exercise you have two versions of the same container image: v1 and v2, and each one ouputs a greeting with its version. After deploying an application with v1, you will set up a trigger to deploy a new version of the application upon changing the image version referenced in its image stream.

Outcomes

  • Deploy an application by using a container image.

  • Trigger a new build for the application when the container image changes.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

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

Instructions

  1. Log in to Red Hat OpenShift and use the builds-triggers project.

    1. Log in to OpenShift as the developer user:

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

      [student@workstation ~]$ oc project builds-triggers
      Already on project "builds-triggers" on server "https://api.ocp4.example.com:6443"
  2. Create an application from a container image.

    1. Create an application called hello from the http://registry.ocp4.example.com:8443/redhattraining/ocpdev-builds-triggers-hello:latest image:

      [student@workstation ~]$ oc new-app --name hello \
        --image=registry.ocp4.example.com:8443/redhattraining/\
      ocpdev-builds-triggers-hello:latest
      ...output omitted...
          deployment.apps "hello" created
          service "hello" created
      ...output omitted...
    2. Expose the application service:

      [student@workstation ~]$ oc expose service/hello
      route.route.openshift.io/hello exposed
    3. Get the application's route:

      [student@workstation ~]$ oc get route
      NAME    HOST/PORT ...
      hello   hello-builds-triggers.apps.ocp4.example.com ...
    4. Use the application's URL to test that the application v1 version is working:

      [student@workstation ~]$ curl hello-builds-triggers.apps.ocp4.example.com
      ...output omitted...
          <h1>Hello, world from v1!</h1>
      ...output omitted...
  3. Set the trigger on the deployment to build when the hello:latest image stream changes.

    1. Set the trigger to redeploy the application when the image stream reference changes:

      [student@workstation ~]$ oc set triggers deploy/hello \
        --from-image=hello:latest -c hello
    2. Verify that the trigger was created:

      [student@workstation ~]$ oc set triggers deploy/hello
      NAME               TYPE    VALUE                 AUTO
      deployments/hello  config                        true
      deployments/hello  image   hello:latest (hello)  true
  4. Tag the latest version of the Image Stream to the v2 version of the container image, and verify the change.

    1. Tag the latest version of the Image Stream to the v2 version:

      [student@workstation ~]$ oc tag \
        registry.ocp4.example.com:8443/redhattraining/ocpdev-builds-triggers-hello:v2 \
        hello:latest
      Tag hello:latest set to registry.ocp4.example.com:8443/redhattraining/ocpdev...
    2. Verify that the hello:latest image stream points to the v2 version.

      [student@workstation ~]$ oc describe is
      ...output omitted...
      latest
        tagged from registry.ocp4.example.com:8443/redhattraining/ocpdev-builds...
      ...output omitted...
    3. Verify that the application replies with the new version's output:

      [student@workstation ~]$ curl hello-builds-triggers.apps.ocp4.example.com
      ...output omitted...
          <h1>Hello, world from v2!</h1>
      ...output omitted...

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-triggers

Revision: do288-4.12-0d49506