diff --git a/_topic_maps/_topic_map_rosa.yml b/_topic_maps/_topic_map_rosa.yml index a32b9b8509..00ae841655 100644 --- a/_topic_maps/_topic_map_rosa.yml +++ b/_topic_maps/_topic_map_rosa.yml @@ -198,6 +198,10 @@ Topics: File: cloud-experts-deploying-application-networking - Name: Storage File: cloud-experts-deploying-application-storage + - Name: ConfigMap, secrets, and environment variables + File: cloud-experts-deploying-configmaps-secrets-env-var + - Name: Using Source-to-Image (S2I) webhooks for automated deployment + File: cloud-experts-deploying-s2i-webhook-cicd --- Name: Getting started Dir: rosa_getting_started diff --git a/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-configmaps-secrets-env-var.adoc b/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-configmaps-secrets-env-var.adoc new file mode 100644 index 0000000000..e0430e4121 --- /dev/null +++ b/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-configmaps-secrets-env-var.adoc @@ -0,0 +1,74 @@ +:_mod-docs-content-type: ASSEMBLY +[id="cloud-experts-deploying-configmaps-secrets-envvar"] += Tutorial: ConfigMaps, secrets, and environment variables +include::_attributes/attributes-openshift-dedicated.adoc[] +:context: cloud-experts-deploying-configmaps-secrets-envvar + +toc::[] + +//rosaworkshop.io content metadata +//Brought into ROSA product docs 05-07-2024 + +This tutorial shows how to configure the OSToy application by using xref:../../nodes/pods/nodes-pods-configmaps.adoc[config maps], link:https://docs.openshift.com/container-platform/latest/cicd/builds/creating-build-inputs.html#builds-input-secrets-configmaps_creating-build-inputs[secrets], and link:https://docs.openshift.com/container-platform/3.11/dev_guide/environment_variables.html[environment variables]. For more information, see these linked topics. + +== Configuration using ConfigMaps +Config maps allow you to decouple configuration artifacts from container image content to keep containerized applications portable. + +.Procedure +* In the OSToy app, in the left menu, click *Config Maps*, displaying the contents of the config map available to the OSToy application. The code snippet shows an example of a config map configuration: ++ +.Example output +[source,text] +---- +kind: ConfigMap +apiVersion: v1 +metadata: + name: ostoy-configmap-files +data: + config.json: '{ "default": "123" }' +---- + +== Configuration using secrets +Kubernetes `Secret` objects allow you to store and manage sensitive information, such as passwords, OAuth tokens, and SSH keys. Putting this information in a secret is safer and more flexible than putting it in plain text into a pod definition or a container image. + +.Procedure + +* In the OSToy app, in the left menu, click *Secrets*, displaying the contents of the secrets available to the OSToy application. The code snippet shows an example of a secret configuration: ++ +.Example output +[source,text] +---- +USERNAME=my_user +PASSWORD=VVNFUk5BTUU9bXlfdXNlcgpQQVNTV09SRD1AT3RCbCVYQXAhIzYzMlk1RndDQE1UUWsKU01UUD1sb2NhbGhvc3QKU01UUF9QT1JUPTI1 +SMTP=localhost +SMTP_PORT=25 +---- + +== Configuration using environment variables +Using environment variables is an easy way to change application behavior without requiring code changes. It allows different deployments of the same application to potentially behave differently based on the environment variables. {product-title} makes it simple to set, view, and update environment variables for pods or deployments. + +.Procedure + +* In the OSToy app, in the left menu, click *ENV Variables*, displaying the environment variables available to the OSToy application. The code snippet shows an example of an environmental variable configuration: ++ +.Example output +[source,text] +---- +{ + "npm_config_local_prefix": "/opt/app-root/src", + "STI_SCRIPTS_PATH": "/usr/libexec/s2i", + "npm_package_version": "1.7.0", + "APP_ROOT": "/opt/app-root", + "NPM_CONFIG_PREFIX": "/opt/app-root/src/.npm-global", + "OSTOY_MICROSERVICE_PORT_8080_TCP_PORT": "8080", + "NODE": "/usr/bin/node", + "LD_PRELOAD": "libnss_wrapper.so", + "KUBERNETES_SERVICE_HOST": "172.30.0.1", + "OSTOY_MICROSERVICE_PORT": "tcp://172.30.60.255:8080", + "OSTOY_PORT": "tcp://172.30.152.25:8080", + "npm_package_name": "ostoy", + "OSTOY_SERVICE_PORT_8080_TCP": "8080", + "_": "/usr/bin/node" + "ENV_TOY_CONFIGMAP": "ostoy-configmap -env" +} +---- \ No newline at end of file diff --git a/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-s2i-webhook-cicd.adoc b/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-s2i-webhook-cicd.adoc new file mode 100644 index 0000000000..d00e3dcd4c --- /dev/null +++ b/cloud_experts_tutorials/cloud-experts-deploying-application/cloud-experts-deploying-s2i-webhook-cicd.adoc @@ -0,0 +1,98 @@ +:_mod-docs-content-type: ASSEMBLY +[id="cloud-experts-deploying-s2i-webhook-cicd"] += Tutorial: Using Source-to-Image (S2I) webhooks for automated deployment +include::_attributes/attributes-openshift-dedicated.adoc[] +:context: cloud-experts-deploying-s2i-webhook-cicd +:source-highlighter: coderay + +toc::[] + +//rosaworkshop.io content metadata +//Brought into ROSA product docs 05-07-2024 + +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]. + +.Procedure + +. To get the GitHub webhook trigger secret, in your terminal, run the following command: ++ +[source,terminal] +---- +$ oc get bc/ostoy-microservice -o=jsonpath='{.spec.triggers..github.secret}' +---- ++ +.Example output +[source,terminal] +---- +`o_3x9M1qoI2Wj_cz1WiK` +---- ++ +[IMPORTANT] +==== +You need to use this secret in a later step in this process. +==== + +. To get the GitHub webhook trigger URL from the OSToy's buildconfig, run the following command: ++ +[source,terminal] +---- +$ oc describe bc/ostoy-microservice +---- ++ +.Example output +[source,terminal] +---- +[...] +Webhook GitHub: + URL: https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy/webhooks//github +[...] +---- + +. In the GitHub webhook URL, replace the `` text with the secret you retrieved. Your URL will resemble the following example output: ++ +.Example output +[source,text] +---- +https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy-microservice/webhooks/o_3x9M1qoI2Wj_czR1WiK/github +---- + +. Setup the webhook URL in GitHub repository. +.. In your repository, click *Settings > Webhooks > Add webhook*. ++ +image::ostoy-webhook.png[Add Webhook] ++ +.. Paste the GitHub webhook URL with the `Secret` included into the "Payload URL" field. +.. Change the "Content type" to `application/json`. +.. Click the *Add webhook* button. ++ +image::ostoy-webhookfinish.png[Finish Add Webhook] ++ +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. + +. 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. ++ +.. Go to the source code in your repository link:[https://github.com//ostoy/blob/master/microservice/app.js]. +.. Edit the file. +.. Comment out line 8 (containing `let randomColor = getRandomColor();`). +.. Uncomment line 9 (containing `let randomColor = getRandomGrayScaleColor();`). ++ + +[source,javascript,highlight='2-3'] +---- +7 app.get('/', function(request, response) { +8 //let randomColor = getRandomColor(); // <-- comment this +9 let randomColor = getRandomGrayScaleColor(); // <-- uncomment this +10 +11 response.writeHead(200, {'Content-Type': 'application/json'}); +---- ++ +.. Enter a message for the update, such as "changed box to grayscale colors". +.. Click *Commit* at the bottom to commit the changes to the main branch. + +. 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. ++ +image::ostoy-builddone.png[Build Run] + +. 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. ++ +image::ostoy-gray.png[Gray] \ No newline at end of file diff --git a/images/ostoy-builddone.png b/images/ostoy-builddone.png new file mode 100644 index 0000000000..fb1fd5859b Binary files /dev/null and b/images/ostoy-builddone.png differ diff --git a/images/ostoy-gray.png b/images/ostoy-gray.png new file mode 100644 index 0000000000..55af5c5388 Binary files /dev/null and b/images/ostoy-gray.png differ diff --git a/images/ostoy-webhook.png b/images/ostoy-webhook.png new file mode 100644 index 0000000000..a188da273f Binary files /dev/null and b/images/ostoy-webhook.png differ diff --git a/images/ostoy-webhookfinish.png b/images/ostoy-webhookfinish.png new file mode 100644 index 0000000000..70f54ce671 Binary files /dev/null and b/images/ostoy-webhookfinish.png differ