|
| 1 | +:_mod-docs-content-type: ASSEMBLY |
| 2 | +[id="cloud-experts-deploying-s2i-webhook-cicd"] |
| 3 | += Tutorial: Using Source-to-Image (S2I) webhooks for automated deployment |
| 4 | +include::_attributes/attributes-openshift-dedicated.adoc[] |
| 5 | +:context: cloud-experts-deploying-s2i-webhook-cicd |
| 6 | +:source-highlighter: coderay |
| 7 | + |
| 8 | +toc::[] |
| 9 | + |
| 10 | +//rosaworkshop.io content metadata |
| 11 | +//Brought into ROSA product docs 05-07-2024 |
| 12 | + |
| 13 | +Automatically trigger a build and deploy anytime you change the source code by using a webhook. For more information about this process, see link:https://docs.openshift.com/container-platform/latest/cicd/builds/triggering-builds-build-hooks.html[Triggering Builds]. |
| 14 | + |
| 15 | +.Procedure |
| 16 | + |
| 17 | +. To get the GitHub webhook trigger secret, in your terminal, run the following command: |
| 18 | ++ |
| 19 | +[source,terminal] |
| 20 | +---- |
| 21 | +$ oc get bc/ostoy-microservice -o=jsonpath='{.spec.triggers..github.secret}' |
| 22 | +---- |
| 23 | ++ |
| 24 | +.Example output |
| 25 | +[source,terminal] |
| 26 | +---- |
| 27 | +`o_3x9M1qoI2Wj_cz1WiK` |
| 28 | +---- |
| 29 | ++ |
| 30 | +[IMPORTANT] |
| 31 | +==== |
| 32 | +You need to use this secret in a later step in this process. |
| 33 | +==== |
| 34 | + |
| 35 | +. To get the GitHub webhook trigger URL from the OSToy's buildconfig, run the following command: |
| 36 | ++ |
| 37 | +[source,terminal] |
| 38 | +---- |
| 39 | +$ oc describe bc/ostoy-microservice |
| 40 | +---- |
| 41 | ++ |
| 42 | +.Example output |
| 43 | +[source,terminal] |
| 44 | +---- |
| 45 | +[...] |
| 46 | +Webhook GitHub: |
| 47 | + URL: https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy/webhooks/<secret>/github |
| 48 | +[...] |
| 49 | +---- |
| 50 | + |
| 51 | +. In the GitHub webhook URL, replace the `<secret>` text with the secret you retrieved. Your URL will resemble the following example output: |
| 52 | ++ |
| 53 | +.Example output |
| 54 | +[source,text] |
| 55 | +---- |
| 56 | +https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy-microservice/webhooks/o_3x9M1qoI2Wj_czR1WiK/github |
| 57 | +---- |
| 58 | + |
| 59 | +. Setup the webhook URL in GitHub repository. |
| 60 | +.. In your repository, click *Settings > Webhooks > Add webhook*. |
| 61 | ++ |
| 62 | +image::ostoy-webhook.png[Add Webhook] |
| 63 | ++ |
| 64 | +.. Paste the GitHub webhook URL with the `Secret` included into the "Payload URL" field. |
| 65 | +.. Change the "Content type" to `application/json`. |
| 66 | +.. Click the *Add webhook* button. |
| 67 | ++ |
| 68 | +image::ostoy-webhookfinish.png[Finish Add Webhook] |
| 69 | ++ |
| 70 | +You should see a message from GitHub stating that your webhook was successfully configured. Now, whenever you push a change to your GitHub repository, a new build automatically starts, and upon a successful build, a new deployment starts. |
| 71 | + |
| 72 | +. Now, make a change in the source code. Any changes automatically trigger a build and deployment. In this example, the colors that denote the status of your OSToy app are selected randomly. To test the configuration, change the box to only display grayscale. |
| 73 | ++ |
| 74 | +.. Go to the source code in your repository link:[https://github.com/<username>/ostoy/blob/master/microservice/app.js]. |
| 75 | +.. Edit the file. |
| 76 | +.. Comment out line 8 (containing `let randomColor = getRandomColor();`). |
| 77 | +.. Uncomment line 9 (containing `let randomColor = getRandomGrayScaleColor();`). |
| 78 | ++ |
| 79 | + |
| 80 | +[source,javascript,highlight='2-3'] |
| 81 | +---- |
| 82 | +7 app.get('/', function(request, response) { |
| 83 | +8 //let randomColor = getRandomColor(); // <-- comment this |
| 84 | +9 let randomColor = getRandomGrayScaleColor(); // <-- uncomment this |
| 85 | +10 |
| 86 | +11 response.writeHead(200, {'Content-Type': 'application/json'}); |
| 87 | +---- |
| 88 | ++ |
| 89 | +.. Enter a message for the update, such as "changed box to grayscale colors". |
| 90 | +.. Click *Commit* at the bottom to commit the changes to the main branch. |
| 91 | + |
| 92 | +. In your cluster's web UI, click *Builds > Builds* to determine the status of the build. After this build is completed, the deployment begins. You can also check the status by running `oc status` in your terminal. |
| 93 | ++ |
| 94 | +image::ostoy-builddone.png[Build Run] |
| 95 | + |
| 96 | +. After the deployment has finished, return to the OSToy application in your browser. Access the *Networking* menu item on the left. The box color is now limited to grayscale colors only. |
| 97 | ++ |
| 98 | +image::ostoy-gray.png[Gray] |
0 commit comments