-
Notifications
You must be signed in to change notification settings - Fork 0
/
nationalparks-java-pipeline-codechanges-gogs.html
410 lines (335 loc) · 15.3 KB
/
nationalparks-java-pipeline-codechanges-gogs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<script src="jquery/jquery.min.js"></script>
<script src="popper/popper.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="requirejs/require.js"></script>
<script>var workshop_base_url = "/user/user3/workshop";</script>
<link rel="stylesheet" href="asciidoctor/css/asciidoctor.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="fontawesome/css/all.min.css">
<link rel="stylesheet" href="css/workshop.css">
<link rel="stylesheet" href="css/workshop-asciidoc.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-135921114-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "UA-135921114-11");
</script>
</head>
</body>
<!-- Header -->
<header class="header">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<a href="" class="logo">Starter Labs (Java)</a>
</div>
</div>
</div>
</header>
<!-- Main -->
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 d-sm-block d-none">
<!-- Table of Contents -->
<ul class="menu">
<li class="category">
<ul class="modules">
<h5 class="category-title">Workshop Modules</h5>
<li class="page"><a href="common-workshop-summary.html">Workshop Summary</a></li>
<li class="page"><a href="common-environment.html">Environment Overview</a></li>
<li class="page"><a href="common-using-homeroom.html">Using Homeroom</a></li>
<li class="page"><a href="common-parksmap-architecture.html">Architecture Overview of the ParksMap Application</a></li>
<li class="page"><a href="common-explore.html">Exploring the CLI and Web Console</a></li>
<li class="page"><a href="parksmap-container-image.html">Deploying Your First Container Image</a></li>
<li class="page"><a href="parksmap-scaling.html">Scaling and Self Healing</a></li>
<li class="page"><a href="parksmap-routes.html">Exposing Your Application to the Outside World</a></li>
<li class="page"><a href="parksmap-logging.html">Exploring OpenShift's Logging Capabilities</a></li>
<li class="page"><a href="parksmap-permissions.html">Role-Based Access Control</a></li>
<li class="page"><a href="parksmap-rsh.html">Remote Access to Your Application</a></li>
<li class="page"><a href="nationalparks-java.html">Deploying Java Code</a></li>
<li class="page"><a href="nationalparks-java-databases.html">Adding a Database (MongoDB)</a></li>
<li class="page"><a href="nationalparks-java-application-health.html">Application Health</a></li>
<li class="page"><a href="nationalparks-java-pipeline.html">Automate Build and Deployment with Pipelines</a></li>
<li class="page active"><a href="nationalparks-java-pipeline-codechanges-gogs.html">Automation for Your Application on Code Changes</a></li>
<li class="page"><a href="mlbparks-templates.html">Using Application Templates</a></li>
<li class="page"><a href="mlbparks-binary-build.html">Binary Builds for Day to Day Development</a></li>
<li class="page"><a href="common-further-resources.html">Further Resources</a></li>
<li class="page"><a href="common-workshop-links.html">Workshop Links</a></li>
</ul>
</li>
</ul>
</div>
<div class="col-sm-9">
<section class="page-content">
<!-- Top Navigation -->
<div class="btn-group btn-group-xs float-right">
<button type="button" onclick="location.href='nationalparks-java-pipeline';" class="btn btn-xs btn-transparent" aria-label="Prev">
<span class="fas fa-arrow-left" aria-hidden="true"></span>
</button>
<button type="button" onclick="location.href='';" class="btn btn-xs btn-transparent" aria-label="Home">
<span class="fas fa-home" aria-hidden="true"></span>
</button>
<button type="button" onclick="location.href='mlbparks-templates';" class="btn btn-xs btn-transparent" aria-label="Next">
<span class="fas fa-arrow-right" aria-hidden="true"></span>
</button>
</div>
<!-- Title -->
<h1 class="title">Automation for Your Application on Code Changes</h1>
<!-- Content -->
<div class="sect1">
<h2 id="_background_web_hooks">Background: Web Hooks</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Most Git repository servers support the concept of web hooks — calling to an
external source via HTTP(S) when a change in the code repository happens.
OpenShift provides an API endpoint that supports receiving hooks from
remote systems in order to trigger builds. By pointing the code repository’s
hook at the OpenShift Pipelines resources, automated code/build/deploy pipelines can be
achieved.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_adding_triggers_to_your_pipeline">Adding Triggers to your Pipeline</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Tekton <strong>Triggers</strong> enable us to configure Pipelines to respond to external events (Git push events, pull requests etc) such as Web Hooks.</p>
</div>
<div class="paragraph">
<p>Adding triggering support requires the creation of a <code>TriggerTemplate</code>, <code>TriggerBinding</code>, and an <code>EventListener</code> in our project.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/devops-pipeline-triggers.png" alt="Triggers">
</div>
</div>
<div class="paragraph">
<p>Let’s see each component in detail:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><strong>TriggerTemplate</strong>: a trigger template is a template for newly created resources. It supports parameters to create specific <code>PipelineResources</code> and <code>PipelineRuns</code>.</p>
</li>
<li>
<p><strong>TriggerBinding</strong>: validates events and extracts payload fields</p>
</li>
<li>
<p><strong>EventListener</strong>: connects <code>TriggerBindings</code> and <code>TriggerTemplates</code> into an addressable endpoint (the event sink). It uses the extracted event parameters from each TriggerBinding (and any supplied static parameters) to create the resources specified in the corresponding TriggerTemplate. It also optionally allows an external service to pre-process the event payload via the interceptor field.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Now let’s create them all together for our Pipeline:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-shell" data-lang="shell">oc create -f http://gogs-labs.apps.cluster-test-efcf.test-efcf.example.opentlc.com/user3/nationalparks/raw/master/pipeline/nationalparks-triggers-all.yaml -n user3</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will create a new Pod with a Route that we can use to setup our Webhook on Gogs to trigger the automatic start of the Pipeline.</p>
</div>
<div class="paragraph">
<p>From left side menu, click on <strong>Topology</strong> to verify if a new Deployment <strong>el-nationalparks</strong> for the <code>EventListener</code> has ben created:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/devops-pipeline-triggers-eventlistener.png" alt="EventListener created">
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_exercise_configuring_gogs_web_hooks">Exercise: Configuring Gogs Web Hooks</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Click on the Deployment, go into <strong>Routes</strong> section and and copy the <strong>el-nationparks</strong> Route URL.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/devops-pipeline-triggers-route.png" alt="EventListener created">
</div>
</div>
<div class="paragraph">
<p>Once you have the URL copied to your clipboard, navigate to the code repository that you have on Gogs:</p>
</div>
<div class="paragraph">
<p><a href="http://gogs-labs.apps.cluster-test-efcf.test-efcf.example.opentlc.com/user3/nationalparks">Gogs Repository</a></p>
</div>
<div class="paragraph">
<p>Your Gogs credentials are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">username: user3
password: gogs</code></pre>
</div>
</div>
<div class="paragraph">
<p>Click the Settings link on the top right of the screen:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/nationalparks-codechanges-gogs-settings.png" alt="Webhook">
</div>
</div>
<div class="paragraph">
<p>Click on <strong>Webhooks</strong>, then the <strong>Add Webhook</strong> button, and finally select <strong>Gogs</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/nationalparks-codechanges-gogs-add-webhook.png" alt="Webhook">
</div>
</div>
<div class="paragraph">
<p>In the next screen, paste your link into the "Payload URL" field. You can leave the
secret token field blank — the secret is already in the URL and does not need
to be in the payload.</p>
</div>
<div class="paragraph">
<p>Change the <code>Content Type</code> to <code>application/json</code>.</p>
</div>
<div class="paragraph">
<p>Finally, click on <strong>Add Webhook</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/nationalparks-codechanges-gogs-config-webhook.png" alt="Webhook">
</div>
</div>
<div class="paragraph">
<p>Boom! From now on, every time you commit new source code to your Gogs
repository, a new build and deploy will occur inside of OpenShift. Let’s try
this out.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_exercise_using_gogs_web_hooks">Exercise: Using Gogs Web Hooks</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Click the <strong>Files</strong> tab in Gogs. This is Gogs’s repository view.</p>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<div class="title">Caution</div>
</td>
<td class="content">
Make sure that the drop-down menu at the upper right is set for
the <strong><code>master</code></strong> branch. Navigate to the
following path:
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">src/main/java/com/openshift/evg/roadshow/parks/rest/</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then click on the <code>BackendController.java</code> file.</p>
</div>
<div class="paragraph">
<p>Once you have the file on the screen, click the edit button in the top right
hand corner as shown here:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/nationalparks-codechanges-gogs-change-code.png" alt="Webhook">
</div>
</div>
<div class="paragraph">
<p>Change line number 20:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">return new Backend("nationalparks","National Parks", new Coordinates("47.039304", "14.505178"), 4);</code></pre>
</div>
</div>
<div class="paragraph">
<p>To</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">return new Backend("nationalparks","Amazing National Parks", new Coordinates("47.039304", "14.505178"), 4);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Click on Commit changes at the bottom of the screen. Feel free to enter a commit
message.</p>
</div>
<div class="paragraph">
<p>Once you have committed your changes, a new <strong>PipelineRun</strong> should almost instantaneously be
triggered in OpenShift. Click <strong>Pipeline</strong> in the left navigation menu then <code>nationalparks-pipeline</code>. You should see a new one running:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/nationalparks-codechanges-pipeline-running.png" alt="Webhook">
</div>
</div>
<div class="paragraph">
<p>or run the following command to verify:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc get PipelineRun</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once the build and deploy has finished, verify your new image was automatically deployed by viewing the application in your browser:</p>
</div>
<div class="paragraph">
<p><a href="http://nationalparks-user3.apps.cluster-test-efcf.test-efcf.example.opentlc.com/ws/info/">National Parks Info Page</a></p>
</div>
<div class="paragraph">
<p>You should now see the new name you have set in the JSON string returned.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
To see this in the map’s legend itself, you will need to scale down your parksmap to 0, then back up to 1 to force the app to refresh its cache.
</td>
</tr>
</table>
</div>
</div>
</div>
<!-- Bottom Navigation -->
<div class="page-meta clearfix">
<input type="button" class="btn btn-lg btn-primary float-right" onclick="location.href='mlbparks-templates';" value="Continue" />
</div>
</section>
</div>
</div>
</div>
<!-- Footer -->
<footer class="footer">
</footer>
<!-- Javascript-->
<script src="js/workshop.js"></script>
<script src="js/workshop-asciidoc.js"></script>
</body>
</html>