-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlbparks-templates.html
418 lines (340 loc) · 15.7 KB
/
mlbparks-templates.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
411
412
413
414
415
416
417
418
<!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"><a href="nationalparks-java-pipeline-codechanges-gogs.html">Automation for Your Application on Code Changes</a></li>
<li class="page active"><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-codechanges-gogs';" 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-binary-build';" 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">Using Application Templates</h1>
<!-- Content -->
<div class="paragraph">
<p>In this lab, we’re going to deploy a complete backend application, consisting of
a REST API backend and a MongoDB database. The complete application will already
be wired together and described as a backend for the map visualization tool, so
that once the application is built and deployed, you will be able to see the new
map.</p>
</div>
<div class="imageblock text-center">
<div class="content">
<img src="images/roadshow-app-architecture-mlbparks.png" alt="Application architecture" width="800">
</div>
</div>
<div class="paragraph">
<p>Let’s combine all of the exercises we have performed in the last several labs by
using a <strong>Template</strong> that we can instantiate with a single command. While we
could have used templates to deploy everything in the workshop today, remember
that it is important for you to understand how to create, deploy, and wire
resources together.</p>
</div>
<div class="sect1">
<h2 id="_exercise_instantiate_a_template">Exercise: Instantiate a Template</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The front end application we’ve been working with this whole time will display
as many back end services' data as are created. Adding more stuff with the right
<strong>Label</strong> will make more stuff show up on the map.</p>
</div>
<div class="paragraph">
<p>Now you will deploy a map of Major League Baseball stadiums in the US by using a
template. It is pre-configured to build the back end Java application, and
deploy the MongoDB database. It also uses a <strong>Hook</strong> to call the <code>/ws/data/load</code>
endpoint to cause the data to be loaded into the database from a JSON file in
the source code repository. Execute the following command:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc create -f https://raw.githubusercontent.com/openshift-roadshow/mlbparks/master/ose3/application-template-eap.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>What just happened? What did you just <code>create</code>? The item that we passed to the <code>create</code>
command is a <strong>Template</strong>. <code>create</code> simply makes the template available in
your <strong>Project</strong>. You can see this with the following command:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc get template</code></pre>
</div>
</div>
<div class="paragraph">
<p>You will see output like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">mlbparks Application template MLBParks backend running on Wildfly and using mongodb 12 (2 blank) 8</code></pre>
</div>
</div>
<div class="paragraph">
<p>Run the following command to instantiate the template:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc new-app mlbparks -p APPLICATION_NAME=mlbparks</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<div class="title">Tip</div>
</td>
<td class="content">
<div class="paragraph">
<p>The template can also use maven for the build. In case you want to try this option
provide the <strong>MAVEN_MIRROR_URL</strong> parameter with the location of the internal nexus
repository:</p>
</div>
<div class="listingblock copypaste">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc new-app mlbparks --name=mlbparks -p MAVEN_MIRROR_URL=http://nexus.labs.svc.cluster.local:8081/repository/maven-all-public</code></pre>
</div>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You will see some output similar to this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">--> Deploying template "user1/mlbparks" to project user1
MLBparks
---------
Application template MLBParks backend running on Wildfly and using mongodb
* With parameters:
* Application Name=mlbparks
* Application route=
* Mongodb App=mongodb-mlbparks
* Git source repository=https://github.com/openshift-roadshow/mlbparks.git
* Git branch/tag reference=master
* Maven mirror url=
* Database name=mongodb
* Database user name=userW3n # generated
* Database user password=4PmSfXWL # generated
* Database admin password=cBQ4RGJf # generated
* GitHub Trigger=TOR1p3wO # generated
* Generic Trigger=NUlqyK54 # generated
--> Creating resources ...
configmap "mlbparks" created
service "mongodb-mlbparks" created
deploymentconfig.apps.openshift.io "mongodb-mlbparks" created
imagestream.image.openshift.io "mlbparks" created
buildconfig.build.openshift.io "mlbparks" created
deploymentconfig.apps.openshift.io "mlbparks" created
service "mlbparks" created
route.route.openshift.io "mlbparks" created
--> Success
Build scheduled, use 'oc logs -f bc/mlbparks' to track its progress.
Access your application via route 'mlbparks-user5.apps.cluster-1d43.1d43.openshiftworkshop.com'
Run 'oc status' to view your app.</code></pre>
</div>
</div>
<div class="paragraph">
<p>OpenShift will now:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Configure and start a build</p>
<div class="ulist">
<ul>
<li>
<p>Using the supplied Maven mirror URL (if you have specified the parameter)</p>
</li>
<li>
<p>From the supplied source code repository</p>
</li>
</ul>
</div>
</li>
<li>
<p>Configure and deploy MongoDB</p>
<div class="ulist">
<ul>
<li>
<p>Using auto-generated user, password, and database name</p>
</li>
</ul>
</div>
</li>
<li>
<p>Configure environment variables for the app to connect to the DB</p>
</li>
<li>
<p>Create the correct services</p>
</li>
<li>
<p>Label the app service with <code>type=parksmap-backend</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>All with one command!</p>
</div>
<div class="paragraph">
<p>When the build is complete, visit the parks map. Does it work? Think about how
this could be used in your environment. For example, a template could define a
large set of resources that make up a "reference application", complete with
several app servers, databases, and more. You could deploy the entire set of
resources with one command, and then hack on them to develop new features,
microservices, fix bugs, and more.</p>
</div>
<div class="paragraph">
<p>In Topology view, you can drag <code>mlbparks</code> and <code>mongodb-mlbparks</code> into the <code>workshop</code> application grouping.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/mlbparks-templates-complete-overview.png" alt="Complete overview">
</div>
</div>
<div class="paragraph">
<p>In addition to being able to instantiate templates from the command line as we did above, templates can also be instantiated from the Developer Perspective in the web console. Click <strong>+Add</strong>, then <strong>From Catalog</strong> and search for <code>mlb</code>. You should see a result for <code>MLBparks</code>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/mlbparks-templates-dev-catalog.png" alt="Template in Developer Catalog">
</div>
</div>
<div class="paragraph">
<p>If you click on <code>MLBparks</code> and then click the <strong>Instantiate Template</strong> button, you’ll see a form that guides you through the different required and optional parameters needed to instantiate this template.</p>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<div class="title">Caution</div>
</td>
<td class="content">
Do not actually instantiate the template from the web console now, since you have already done so via the command line.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>As a final exercise, look at the template that was used to create the
resources for our <strong>mlbparks</strong> application.</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc get template mlbparks -o yaml</code></pre>
</div>
</div>
<div class="paragraph">
<p>But as always, you can use the OpenShift web console to do the same. In the Developer Perspective, click <strong>Advanced → Search</strong> in the left navigation, then select <strong>Template</strong> from the dropdown, and click <strong>mlbparks</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/mlbparks-templates-yaml-menu.png" alt="Complete overview">
</div>
</div>
<div class="paragraph">
<p>On the next page, click <strong>YAML</strong> to see/edit the YAML from here.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/mlbparks-templates-yaml-edit.png" alt="Template YAML edit">
</div>
</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-binary-build';" 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>