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
Log in to Red Hat OpenShift and use the builds-triggers project.
Log in to OpenShift as the developer user:
[student@workstation ~]$oc login -u developer -p developer \https://api.ocp4.example.com:6443Login successful. ...output omitted...
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"Create an application from a container image.
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...
Expose the application service:
[student@workstation ~]$ oc expose service/hello
route.route.openshift.io/hello exposedGet the application's route:
[student@workstation ~]$ oc get route
NAME HOST/PORT ...
hello hello-builds-triggers.apps.ocp4.example.com ...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 fromv1!</h1> ...output omitted...
Set the trigger on the deployment to build when the hello:latest image stream changes.
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
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) trueTag the latest version of the Image Stream to the v2 version of the container image, and verify the change.
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:latestTag hello:latest set to registry.ocp4.example.com:8443/redhattraining/ocpdev...
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...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 fromv2!</h1> ...output omitted...