Skip to content

Commit 4255752

Browse files
authored
Merge pull request #75631 from EricPonvelle/OSDOCS-8399_ConfigMap-S2I-Webhooks
OSDOCS#8399: Migrated the ConfigMap and S2I webhook tutorials from the ROSA Workshop
2 parents 1646726 + da60817 commit 4255752

File tree

7 files changed

+176
-0
lines changed

7 files changed

+176
-0
lines changed

_topic_maps/_topic_map_rosa.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ Topics:
198198
File: cloud-experts-deploying-application-networking
199199
- Name: Storage
200200
File: cloud-experts-deploying-application-storage
201+
- Name: ConfigMap, secrets, and environment variables
202+
File: cloud-experts-deploying-configmaps-secrets-env-var
203+
- Name: Using Source-to-Image (S2I) webhooks for automated deployment
204+
File: cloud-experts-deploying-s2i-webhook-cicd
201205
---
202206
Name: Getting started
203207
Dir: rosa_getting_started
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
:_mod-docs-content-type: ASSEMBLY
2+
[id="cloud-experts-deploying-configmaps-secrets-envvar"]
3+
= Tutorial: ConfigMaps, secrets, and environment variables
4+
include::_attributes/attributes-openshift-dedicated.adoc[]
5+
:context: cloud-experts-deploying-configmaps-secrets-envvar
6+
7+
toc::[]
8+
9+
//rosaworkshop.io content metadata
10+
//Brought into ROSA product docs 05-07-2024
11+
12+
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.
13+
14+
== Configuration using ConfigMaps
15+
Config maps allow you to decouple configuration artifacts from container image content to keep containerized applications portable.
16+
17+
.Procedure
18+
* 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:
19+
+
20+
.Example output
21+
[source,text]
22+
----
23+
kind: ConfigMap
24+
apiVersion: v1
25+
metadata:
26+
name: ostoy-configmap-files
27+
data:
28+
config.json: '{ "default": "123" }'
29+
----
30+
31+
== Configuration using secrets
32+
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.
33+
34+
.Procedure
35+
36+
* 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:
37+
+
38+
.Example output
39+
[source,text]
40+
----
41+
USERNAME=my_user
42+
PASSWORD=VVNFUk5BTUU9bXlfdXNlcgpQQVNTV09SRD1AT3RCbCVYQXAhIzYzMlk1RndDQE1UUWsKU01UUD1sb2NhbGhvc3QKU01UUF9QT1JUPTI1
43+
SMTP=localhost
44+
SMTP_PORT=25
45+
----
46+
47+
== Configuration using environment variables
48+
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.
49+
50+
.Procedure
51+
52+
* 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:
53+
+
54+
.Example output
55+
[source,text]
56+
----
57+
{
58+
"npm_config_local_prefix": "/opt/app-root/src",
59+
"STI_SCRIPTS_PATH": "/usr/libexec/s2i",
60+
"npm_package_version": "1.7.0",
61+
"APP_ROOT": "/opt/app-root",
62+
"NPM_CONFIG_PREFIX": "/opt/app-root/src/.npm-global",
63+
"OSTOY_MICROSERVICE_PORT_8080_TCP_PORT": "8080",
64+
"NODE": "/usr/bin/node",
65+
"LD_PRELOAD": "libnss_wrapper.so",
66+
"KUBERNETES_SERVICE_HOST": "172.30.0.1",
67+
"OSTOY_MICROSERVICE_PORT": "tcp://172.30.60.255:8080",
68+
"OSTOY_PORT": "tcp://172.30.152.25:8080",
69+
"npm_package_name": "ostoy",
70+
"OSTOY_SERVICE_PORT_8080_TCP": "8080",
71+
"_": "/usr/bin/node"
72+
"ENV_TOY_CONFIGMAP": "ostoy-configmap -env"
73+
}
74+
----
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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]

images/ostoy-builddone.png

56.5 KB
Loading

images/ostoy-gray.png

31.6 KB
Loading

images/ostoy-webhook.png

55.6 KB
Loading

images/ostoy-webhookfinish.png

82.2 KB
Loading

0 commit comments

Comments
 (0)