-
Notifications
You must be signed in to change notification settings - Fork 115
/
index.html
1306 lines (1120 loc) · 48.8 KB
/
index.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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Continuous Deployment: Workshop</title>
<meta name="author" content="Viktor Farcic">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="../lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section id="cover">
<h5>Continuous</h5>
<h4>Integration</h4>
<h3>Delivery</h3>
<h2>Deployment</h2>
<h1>Workshop</h1>
<p>
<small>
Created by <a href="http://technologyconversations.com/about/">Viktor Farcic</a>
for <a href="http://technologyconversations.com">Technology Conversations</a> / <a href="http://twitter.com/vfarcic">@vfarcic</a>
</small>
</p>
</section>
<section id="aboutMe">
<h2>Viktor Farcic</h2>
<ul>
<img src="img/viktor.jpg" style="float: right; width: 25%; height: 25%;"/>
<li>Software Architect at <a href="http://defie.co">Defie</a></li>
<li>Never developed in Fortran</li>
<li>Passionate about TDD, BDD and Continuous Integration, Delivery and Deployment</li>
<li>Blogger in <a href="http://technologyconversations.com/">TechnologyConversations.com</a></li>
<li>Java Test-Driven Development: Mastering TDD Through Katas</li>
</ul>
</section>
<section>
<section id="requirements">
<h2>High Level Requirements</h2>
<h3>Book Shop application</h3>
<ul>
<li>Any device (desktop, tables and mobiles)</li>
<li>Search, see details and purchase</li>
<li>Registration required for purchase</li>
<li>Administration</li>
</ul>
</section>
</section>
<section>
<section id="design">
<h2>High Level Design</h2>
<ul>
<li>VMs with Vagrant</li>
<li>Provisioning with Ansible</li>
<li>Microservices</li>
<li>Front-end decoupled from back-end</li>
<li>Tested, built, deployed and tested again with containers</li>
<li>Zero-downtime with reverse proxy</li>
<li>CD with Jenkins</li>
</ul>
</section>
</section>
<section>
<section id="env">
<h1>Environments</h1>
<img src="img/servers.jpg">
</section>
<section id="envVm">
<h4>Environments</h4>
<h2>Virtual Machines</h2>
<ul>
<li>Create</li>
<li>Provision</li>
<li>Destroy</li>
</ul>
<img src="img/vagrant.png" style="background-color: black; width: 50%; height: 50%; float: right;">
<ul>
<li><a href="https://www.virtualbox.org/">https://www.virtualbox.org/</a></li>
<li><a href="https://www.vagrantup.com/">https://www.vagrantup.com/</a></li>
<li><code>vagrant plugin install vagrant-cachier</code></li>
</ul>
</section>
<section id="envProv">
<h4>Environments</h4>
<h2>Provisioning</h2>
<img src="img/ansible.png" style="background-color: white; width: 35%; height: 35%; float: right;">
<ul>
<li>SSH based</li>
<li>Client only</li>
<li>YAML configuration</li>
<li>Push</li>
</ul>
</section>
<section id="envDevCode">
<h4>Environments</h4>
<h2>Development</h2>
<h4><a href="https://github.com/vfarcic/books-service">vfarcic/books-service repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/books-service/blob/master/Vagrantfile">Vagrantfile</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/bootstrap.sh">bootstrap.sh</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/ansible/dev.yml">dev.yml</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/ansible/roles/java/tasks/main.yml">roles/java/tasks/main.yml</a></li>
</ul>
</section>
<section id="envDevComm">
<h4>Environments</h4>
<h2>Development</h2>
<pre><code data-trim contenteditable>
git clone https://github.com/vfarcic/books-service.git
cd books-service
vagrant up dev
vagrant ssh dev
scala -version
sudo docker ps -a
exit
vagrant halt dev
</code></pre>
</section>
<section id="envCdCode">
<h4>Environments</h4>
<h2>Continuous Deployment</h2>
<h4><a href="https://github.com/vfarcic/cd-workshop">vfarcic/cd-workshop repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/Vagrantfile">Vagrantfile</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/bootstrap.sh">bootstrap.sh</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/cd.yml">cd.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/jenkins/tasks/main.yml">jenkins/tasks/main.yml</a></li>
</ul>
</section>
<section id="envCdComm">
<h4>Environments</h4>
<h2>Continuous Deployment</h2>
<pre><code data-trim contenteditable>
cd ~
git clone https://github.com/vfarcic/cd-workshop.git
cd cd-workshop
vagrant up cd
vagrant ssh cd
sudo docker ps -a
exit
</code></pre>
Open <a href="http://localhost:8080/">http://localhost:8080/</a>
</section>
<section id="envProdCode">
<h4>Environments</h4>
<h2>Production</h2>
<h4><a href="https://github.com/vfarcic/cd-workshop">vfarcic/cd-workshop repo</a></h4>
<ul>
<li>VM: <a href="https://github.com/vfarcic/cd-workshop/blob/master/Vagrantfile">Vagrantfile</a></li>
</ul>
</section>
<section id="env-prod-comm">
<h4>Environments</h4>
<h2>Production</h2>
<pre><code data-trim contenteditable>
vagrant up prod
vagrant ssh prod
ssh-keygen # Enter to all questions
exit
vagrant ssh cd
ssh-keygen # Enter to all questions
ssh-copy-id 192.168.50.92 # Pass: vagrant
</code></pre>
</section>
<section id="envBenefits">
<h4>VM and Provisioning</h4>
<h2>Benefits</h2>
<ul>
<li>Version control</li>
<li>Repeatable</li>
<li>Reliable</li>
<li>Automated</li>
<li>Fast</li>
<li>Easy to integrate with CD servers</li>
</ul>
</section>
</section>
<section>
<section id="microservicesAndFrontEnd">
<h2>Microservices and front-end</h2>
<img src="img/workshop_microservices.png">
</section>
<section id="microservicesCode">
<h2>Microservices</h2>
<h3><a href="https://github.com/vfarcic/books-service">books-service repo</a></h3>
<ul>
<li>Unit/Functional Tests: <a href="https://github.com/vfarcic/books-service/blob/master/src/test/scala/com/technologyconversations/api/ServiceSpec.scala">ServiceSpec.scala</a></li>
<li>Code: <a href="https://github.com/vfarcic/books-service/blob/master/src/main/scala/com/technologyconversations/api/ServiceActor.scala">ServiceActor.scala</a></li>
</ul>
</section>
<section id="microservicesBenefits">
<h2>Microservices</h2>
<h3>Benefits</h3>
<ul>
<li>Simple and easy to understand</li>
<li>Decoupled</li>
<li>Easy to scale</li>
<li>Easy to test</li>
<li>No long-term commitment</li>
<li>Frequent deployment</li>
<li>Innovation</li>
</ul>
</section>
</section>
<section>
<section id="containers">
<h1>Containers</h1>
<img src="img/containers.jpg">
</section>
<section id="containersBenefits">
<h4>Containers</h4>
<h2>Docker</h2>
<img src="img/docker.png" style="background-color: white; width: 50%; height: 50%; float: right;">
<ul>
<li>Portable</li>
<li>Low resource usage</li>
<li>Scalable</li>
<li>Isolation</li>
<li>Self-sufficient</li>
<li>Immutable</li>
</ul>
</section>
<section id="containersTestsCode">
<h4>Containers</h4>
<h2>Tests</h2>
<h4><a href="https://github.com/vfarcic/books-service">vfarcic/books-service repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/books-service/blob/master/Dockerfile.test">Dockerfile.test</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/run_tests.sh">run_tests.sh</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/src/test/scala/com/technologyconversations/api/ServiceSpec.scala">Unit/functional tests</a></li>
</ul>
</section>
<section id="containers-tests-comm">
<h4>Containers</h4>
<h2>Tests</h2>
<pre><code data-trim contenteditable>
git clone https://github.com/vfarcic/books-service.git
cd books-service
sudo ./build_tests.sh
sudo docker images | grep vfarcic/books-service-tests
sudo docker run -t --rm \
-v $PWD/target/scala-2.10:/source/target/scala-2.10 \
-v /data/.ivy2:/root/.ivy2/cache \
vfarcic/books-service-tests
ll target/scala-2.10/books-service-assembly-1.0.jar
</code></pre>
</section>
<section id="containersbuildexercise" data-background="gray">
<h4>Containers</h4>
<h2>Create Docker Image Exercise</h2>
<pre><code data-trim contenteditable>
cd ~
git clone https://github.com/vfarcic/books-fe.git
cd books-fe
clear && cat create_docker.md
</code></pre>
<a href="https://github.com/vfarcic/books-fe/blob/master/create_docker.md">Instructions</a>
<aside class="notes">
<a href="https://github.com/vfarcic/books-fe/blob/master/Dockerfile">Dockerfile</a>
<pre><code>
sudo docker build -t books-fe .
</code></pre>
</aside>
</section>
<section id="containersAppCode">
<h4>Containers</h4>
<h2>Application</h2>
<h4><a href="https://github.com/vfarcic/books-service">vfarcic/books-service repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/books-service/blob/master/Dockerfile">Dockerfile</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/run.sh">run.sh</a></li>
</ul>
</section>
<section id="containersAppComm">
<h4>Containers</h4>
<h2>Application</h2>
<pre><code data-trim contenteditable>
cd ~/books-service
sudo docker build -t vfarcic/books-service .
sudo docker run -d --name books-service \
-p 9001:8080 \
-v /data/books-service/db:/data/db \
vfarcic/books-service
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl http://localhost:9001/api/v1/books | python -mjson.tool
curl http://localhost:9001/api/v1/books/_id/1 | python -mjson.tool
sudo docker rm -f books-service
sudo docker ps -a
</code></pre>
</section>
<section id="containersrunexercise" data-background="gray">
<h4>Containers</h4>
<h2>Run Docker Image with Mock Server Exercise</h2>
Run <strong>books-fe</strong> image using following parameters.
<ul>
<li>Use <strong>-d</strong> to detach from the process</li>
<li>Set env var <strong>MODE</strong> to <strong>mock_server</strong></li>
<li>Set env var <strong>MOCK_PORT</strong> to <strong>9002</strong></li>
<li>Expose port <strong>8080</strong> as <strong>9001</strong></li>
<li>Expose port <strong>9002</strong> as <strong>9002</strong></li>
<li>Image is called <strong>books-fe</strong></li>
</ul>
<div>
Open <a href="http://192.168.50.91:9001">http://192.168.50.91:9001</a> to confirm and then kill the Docker process
</div>
<aside class="notes">
<pre><code>
sudo docker run -d \
--name books-fe-mock \
-e MODE=mock_server \
-e MOCK_PORT=9002 \
-p 9001:8080 \
-p 9002:9002 \
books-fe
</code></pre>
</aside>
</section>
<section id="containersBddCode">
<h4>Containers</h4>
<h2>Functional Tests with BDD</h2>
<h4><a href="https://github.com/vfarcic/books-fe">vfarcic/books-fe repo</a></h4>
<ul>
<li><a href="http://bddassistant.com/">BDD Assistant</a></li>
<li><a href="https://registry.hub.docker.com/u/vfarcic/bdd-runner-phantomjs/">bdd-runner-phantomjs</a></li>
<li><a href="https://github.com/vfarcic/books-fe/blob/master/stories/functional/functional.story">functional.story</a></li>
</ul>
</section>
<section id="containersBddComm">
<h4>Containers</h4>
<h2>Functional Tests with BDD</h2>
<pre><code>
cd ~/books-fe
sudo docker run -t --rm \
-v $PWD/stories:/opt/bdd/data/stories \
vfarcic/bdd-runner-phantomjs \
-P url=http://172.17.42.1:9001 \
-P widthHeight=1024,768 \
--story_path data/stories/functional/**
sudo docker rm -f books-fe-mock
</code></pre>
</section>
<section id="containersRegistryCode">
<h4>Containers</h4>
<h2>Registry</h2>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/cd.yml">cd.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/registry/tasks/main.yml">roles/registry/tasks/main.yml</a></li>
</ul>
</section>
<section id="containersRegistryComm">
<h4>Containers</h4>
<h2>Registry</h2>
<pre><code data-trim contenteditable>
sudo docker tag -f vfarcic/books-service-tests \
192.168.50.91:5000/books-service-tests
sudo docker tag -f vfarcic/books-service \
192.168.50.91:5000/books-service
sudo docker images | grep books-service
sudo docker push \
192.168.50.91:5000/books-service-tests
sudo docker push \
192.168.50.91:5000/books-service
curl http://localhost:5000/v1/search?q=books-service | python -mjson.tool
</code></pre>
</section>
<section id="containersregistryexercise" data-background="gray">
<h4>Containers</h4>
<h2>Push to Registry Exercise</h2>
Push <strong>books-fe</strong> image to the registry.
<aside class="notes">
<pre><code>
sudo docker tag -f books-fe \
192.168.50.91:5000/books-fe
sudo docker push \
192.168.50.91:5000/books-fe
curl http://localhost:5000/v1/search?q=books-fe \
| python -mjson.tool
</code></pre>
</aside>
</section>
<section id="containersAppProdCode">
<h4>Containers</h4>
<h2>Application in production</h2>
<h4><a href="https://github.com/vfarcic/books-service">vfarcic/books-service repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/docker.yml">docker.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/docker/tasks/main.yml">roles/docker/tasks/main.yml</a></li>
</ul>
</section>
<section id="containersAppProdComm">
<h4>Containers</h4>
<h2>Application in Production</h2>
<pre><code data-trim contenteditable>
ansible-playbook /vagrant/ansible/docker.yml \
-i /vagrant/ansible/hosts/prod
exit
vagrant ssh prod
sudo docker run -d --name books-service \
-p 9001:8080 \
-v /data/books-service/db:/data/db \
192.168.50.91:5000/books-service
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl -H 'Content-Type: application/json' -X PUT -d \
'{"_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club"}' \
http://localhost:9001/api/v1/books | python -mjson.tool
curl http://localhost:9001/api/v1/books | python -mjson.tool
</code></pre>
</section>
<section id="containersappproductionexercise" data-background="gray">
<h4>Containers</h4>
<h2>Application in Production Exercise</h2>
Run <strong>books-fe</strong> image using following parameters.
<ul>
<li>Use <strong>-d</strong> to detach from the process</li>
<li>Expose port <strong>8080</strong> as <strong>9011</strong></li>
<li>Image is called <strong>192.168.50.91:5000/books-fe</strong></li>
</ul>
<div>
Open <a href="http://192.168.50.92:9011">http://192.168.50.92:9011</a> to confirm
</div>
<aside class="notes">
<pre><code>
sudo docker run \
-d --name books-fe \
-p 9011:8080 \
192.168.50.91:5000/books-fe
sudo docker ps -a
</code></pre>
</aside>
</section>
<section id="containersNginxCode">
<h4>Containers</h4>
<h2>nginx</h2>
<h4><a href="https://github.com/vfarcic/cd-workshop">vfarcic/cd-workshop repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/nginx_with_books/tasks/main.yml">roles/nginx_with_books/tasks/main.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/nginx_with_books/defaults/main.yml">roles/nginx_with_books/defaults/main.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/nginx_with_books/templates/services.conf.j2">roles/nginx_with_books/templates/services.conf.j2</a></li>
</ul>
</section>
<section id="containersNginxComm">
<h4>Containers</h4>
<h2>nginx</h2>
<pre><code data-trim contenteditable>
exit
vagrant ssh cd
curl -H 'Content-Type: application/json' \
http://192.168.50.92:9001/api/v1/books | python -mjson.tool
curl -H 'Content-Type: application/json' \
http://192.168.50.92/api/v1/books | python -mjson.tool
ansible-playbook /vagrant/ansible/nginx_with_books.yml \
-i /vagrant/ansible/hosts/prod
curl -H 'Content-Type: application/json' \
http://192.168.50.92/api/v1/books | python -mjson.tool
</code></pre>
</section>
<section id="containersnginxexercise" data-background="gray">
<h4>Containers</h4>
<h2>nginx Exercise</h2>
<ul>
<li>Template is located in <strong>/vagrant/ansible/roles/nginx_with_books/templates/services.conf.j2</strong></li>
<li>Modify template to proxy <strong>/</strong> to <strong>http://172.17.42.1:9011</strong>.</li>
<li>Rerun Ansible playbook <strong>/vagrant/ansible/nginx_with_books.yml</strong></li>
</ul>
<div>
Open <a href="http://192.168.50.92">http://192.168.50.92</a> to confirm
</div>
<aside class="notes">
<pre><code>
location / {
proxy_pass http://172.17.42.1:9011/;
}
</code></pre>
<pre><code>
ansible-playbook \
/vagrant/ansible/nginx_with_books.yml \
-i /vagrant/ansible/hosts/prod
</code></pre>
</aside>
</section>
<section id="containersPDITCode">
<h4>Containers</h4>
<h2>Post Deployment Integration Tests</h2>
<h4><a href="https://github.com/vfarcic/books-service">vfarcic/books-service repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/books-service/blob/master/src/test/scala/com/technologyconversations/api/ServiceInteg.scala">ServiceInteg.scala</a></li>
<li><a href="https://github.com/vfarcic/books-service/blob/master/run_tests.sh">run_tests.sh</a></li>
</ul>
</section>
<section id="containersPDITComm">
<h4>Containers</h4>
<h2>Post Deployment Integration Tests</h2>
<pre><code data-trim contenteditable>
sudo docker run -t --rm \
-e "TEST_TYPE=integ" \
-e "DOMAIN=http://192.168.50.92" \
-v /data/.ivy2:/root/.ivy2/cache \
192.168.50.91:5000/books-service-tests
</code></pre>
</section>
<section id="containerspditexercise" data-background="gray">
<h4>Containers</h4>
<h2>Post Deployment Integration Tests Exercise</h2>
Run container with integration tests from the <strong>~/books-fe</strong> directory
<ul>
<small>
<li>Use <strong>-t</strong> to see terminal output and <strong>--rm</strong> to remove when finished</li>
<li>Share container volume <strong>/opt/bdd/data/stories</strong> with <strong>$PWD/stories</strong> on the host</li>
<li>Container name is <strong>vfarcic/bdd-runner-phantomjs</strong></li>
<li>Use <strong>-P url=http://192.168.50.92 -P widthHeight=1024,768 --story_path data/stories/integration/**</strong> as command</li>
</small>
</ul>
<aside class="notes">
<pre><code>
cd ~/books-fe
sudo docker run -t --rm \
-v $PWD/stories:/opt/bdd/data/stories \
vfarcic/bdd-runner-phantomjs \
-P url=http://192.168.50.92 \
-P widthHeight=1024,768 \
--story_path data/stories/integration/**
</code></pre>
</aside>
</section>
<section id="containersPDSTCode">
<h4>Containers</h4>
<h2>Post Deployment Stress Tests</h2>
<h4><a href="https://github.com/vfarcic/books-stress">vfarcic/books-stress repo</a></h4>
<ul>
<li><a href="https://github.com/vfarcic/books-stress/blob/master/user-files/simulations/technologyconversations/Books.scala">Books.scala</a></li>
<li><a href="https://github.com/vfarcic/books-stress/blob/master/Dockerfile">Dockerfile</a></li>
</ul>
</section>
<!--TODO: Add UI stress tests-->
<section id="containersPDSTComm">
<h4>Containers</h4>
<h2>Post Deployment Stress Tests</h2>
<pre><code data-trim contenteditable>
cd ~
git clone https://github.com/vfarcic/books-stress.git
cd books-stress
sudo docker build -t vfarcic/books-stress .
sudo docker tag vfarcic/books-stress 192.168.50.91:5000/books-stress
sudo docker push 192.168.50.91:5000/books-stress
sudo docker run -t --rm \
-e "DOMAIN=http://192.168.50.92" \
-e "USERS=10" \
-e "USERS_OVER_SECONDS=20" \
-e "MAX_RESPONSE_TIME=1000" \
-e "DURATION=120" \
-v /data/stress/results:/stress/results \
192.168.50.91:5000/books-stress
exit
</code></pre>
</section>
</section>
<section>
<section id="zd">
<h2>Zero-downtime</h2>
<img src="img/downtime.jpg">
</section>
<section id="zdBenefits">
<h2>Zero-downtime</h2>
<ul>
<li>No downtime</li>
<li>Production testing</li>
<li>nginx & etcd</li>
</ul>
</section>
<section id="zdWithDowntimeProcess">
<h4><strike>Zero-downtime</strike></h4>
<h2>Traditional Deployment</h2>
<ul>
<li>Come to the office one weekend when there is least traffic</li>
<li>Download latest release</li>
<li>Stop the running application</li>
<li>Deploy the latest release</li>
<li>Start the deployed application</li>
<li>Hope that there is no reason for rollback</li>
<li>Hope that no one noticed the downtime</li>
</ul>
</section>
<section id="zdWithDowntimeComm">
<h4><strike>Zero-downtime</strike></h4>
<h2>Traditional Deployment</h2>
<pre><code data-trim contenteditable>
vagrant ssh prod
curl http://192.168.50.92/api/v1/books | python -mjson.tool
sudo docker pull 192.168.50.91:5000/books-service
sudo docker rm -f books-service
curl http://192.168.50.92/api/v1/books | python -mjson.tool
sudo docker run -d --name books-service \
-p 9001:8080 \
-v /data/books-service/db:/data/db \
192.168.50.91:5000/books-service
curl http://192.168.50.92/api/v1/books | python -mjson.tool
sudo docker rm -f books-service
</code></pre>
</section>
<section id="zdBlueGreenParallelCode">
<h4>Zero-downtime</h4>
<h2>Blue-Green: Parallel Running</h2>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/nginx_with_books/templates/services.conf.j2">roles/nginx_with_books/templates/services.conf.j2</a></li>
</ul>
</section>
<section id="zdBlueGreenParallelComm">
<h4>Zero-downtime</h4>
<h2>Blue-Green: Parallel Running</h2>
<pre><code data-trim contenteditable>
sudo docker run -d --name books-service-db \
-p 27017:27017 \
-v /data/books-service/db:/data/db \
mongo
sudo docker run -d --name books-service-blue \
-p 9001:8080 \
--link books-service-db:db \
192.168.50.91:5000/books-service
curl http://192.168.50.92/api/v1/books | python -mjson.tool
sudo docker pull 192.168.50.91:5000/books-service
sudo docker run -d --name books-service-green \
-p 9002:8080 \
--link books-service-db:db \
192.168.50.91:5000/books-service
sudo docker ps -a | grep books-service
curl http://192.168.50.92:9002/api/v1/books | python -mjson.tool
cat /data/nginx/sites-enabled/services.conf
exit
</code></pre>
</section>
<section id="zdBlueGreenTests">
<h2>Zero-downtime</h2>
<h4>Blue-Green: Tests</h4>
<pre><code data-trim contenteditable>
vagrant ssh cd
sudo docker run --rm \
-e "TEST_TYPE=integ" \
-e "DOMAIN=http://192.168.50.92:9002" \
-v /data/.ivy2:/root/.ivy2/cache \
192.168.50.91:5000/books-service-tests
sudo docker run -t --rm \
-e "DOMAIN=http://192.168.50.92:9002" \
-e "USERS=10" \
-e "USERS_OVER_SECONDS=20" \
-e "MAX_RESPONSE_TIME=1000" \
-e "DURATION=120" \
-v /data/stress/results:/stress/results \
192.168.50.91:5000/books-stress
exit
</code> </pre>
</section>
<section id="zdBlueGreenSwitch">
<h2>Zero-downtime</h2>
<h4>Blue-Green: Switch</h4>
<pre><code data-trim contenteditable>
vagrant ssh prod
cat /data/nginx/sites-enabled/services.conf
sudo sed -i 's/9001/9002/g' /data/nginx/sites-enabled/services.conf
cat /data/nginx/sites-enabled/services.conf
sudo docker kill -s HUP nginx
sudo docker stop books-service-blue
sudo docker ps -a | grep books-service
exit
</code></pre>
</section>
<section id="zdBlueGreenFinalTests">
<h2>Zero-downtime</h2>
<h4>Blue-Green: Final Tests</h4>
<pre><code data-trim contenteditable>
vagrant ssh cd
sudo docker run -it --rm \
-e "TEST_TYPE=integ" \
-e "DOMAIN=http://192.168.50.92" \
-v /data/.ivy2:/root/.ivy2/cache \
192.168.50.91:5000/books-service-tests
exit
vagrant ssh prod
sudo docker rm -f books-service-blue
sudo docker ps -a | grep books-service
curl http://192.168.50.92/api/v1/books | python -mjson.tool
exit
</code></pre>
</section>
<section id="zdBlueGreenEtcd">
<h2>Zero-downtime</h2>
<h4>Blue-Green: etcd</h4>
<pre><code data-trim contenteditable>
vagrant ssh cd
ansible-playbook /vagrant/ansible/etcd.yml \
-i /vagrant/ansible/hosts/prod
exit
vagrant ssh prod
etcdctl set /books-service/color green
etcdctl set /books-service/port 9002
etcdctl get /books-service/color
etcdctl get /books-service/port
</code></pre>
</section>
<section id="zdBlueGreenBetterSwitch">
<h2>Zero-downtime</h2>
<h4>Blue-Green: Better Switch</h4>
<pre><code data-trim contenteditable>
sudo docker pull 192.168.50.91:5000/books-service
sudo docker run -d --name books-service-blue \
-p 9001:8080 \
--link books-service-db:db \
192.168.50.91:5000/books-service
# Run tests
sudo sed -i 's/9002/9001/g' /data/nginx/sites-enabled/services.conf
cat /data/nginx/sites-enabled/services.conf
sudo docker kill -s HUP nginx
sudo docker stop books-service-green
# Run tests
curl -H 'Content-Type: application/json' \
http://192.168.50.92/api/v1/books | python -mjson.tool
sudo docker rm -f books-service-green
etcdctl set /books-service/color blue
etcdctl set /books-service/port 9001
exit
</code></pre>
</section>
</section>
<section>
<section id="cd">
<h1>Continuous Delivery</h1>
<h2><span class="fragment grow highlight-green">Every commit</span> that passed all tests is deployed <span class="fragment grow highlight-green">to production</span> automatically</h2>
</section>
<section id="cdAnsibleCode">
<h4>Continuous Deployment</h4>
<h2>Ansible</h2>
<ul>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/books-service.yml">books-service.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/books-service/tasks/main.yml">roles/books-service/tasks/main.yml</a></li>
<li><a href="https://github.com/vfarcic/cd-workshop/blob/master/ansible/roles/books-service/templates/books-service.conf.j2">roles/books-service/templates/books-service.conf.j2</a></li>
</ul>
</section>
<section id="cdAnsibleComm">
<h4>Continuous Deployment</h4>
<h2>Ansible</h2>
<pre><code data-trim contenteditable>
vagrant ssh cd
ansible-playbook /vagrant/ansible/books-service.yml \
-i /vagrant/ansible/hosts/prod
</code></pre>
</section>
<section id="cd-ansible-exercise-01" data-background="gray">
<h4>Continuous Deployment</h4>
<h3>Ansible Exercise</h3>
<h2>Playbook</h2>
<h4>books-fe.yml</h4>
<ul>
<li>Create ~/vagrant/ansible/books-fe.yml</li>
<li>Include roles <strong>docker</strong>, <strong>nginx</strong>, <strong>etcd</strong> and <strong>books-fe</strong></li>
<li>Create <strong>~/vagrant/ansible/roles/books-fe/defaults/main.yml</strong></li>
<li>Create <strong>~/vagrant/ansible/roles/books-fe/tasks/main.yml</strong></li>
<li>Create <strong>~/vagrant/ansible/roles/books-fe/templates/main.yml</strong></li>
</ul>
</section>
<section id="cd-ansible-exercise-01-solution" data-background="lightgreen">
<h4>Continuous Deployment</h4>
<h3>Ansible Exercise</h3>
<h2>Playbook Solution</h2>
<h4>books-fe.yml</h4>
<pre><code contenteditable>
- hosts: books-service
remote_user: vagrant
sudo: yes
roles:
- docker
- nginx
- etcd
- books-fe
</code></pre>
</section>
<section id="cd-ansible-exercise-02" data-background="gray">
<h4>Continuous Deployment</h4>
<h3>Ansible Exercise</h3>
<h2>Colors</h2>
<ul>
<li>Retrieve colors from the server with <strong>9011</strong> as the default <strong>blue</strong> and <strong>9012</strong> as the default <strong>green</strong> ports</li>
<li>Set <strong>port</strong> fact/variable as the previously retrieved <strong>new_port</strong></li>
<li>Use debug to see the output (i.e. <strong>- debug: var=colors</strong>)</li>
</ul>
<pre><code contenteditable>
ansible-playbook /vagrant/ansible/books-fe.yml \
-i /vagrant/ansible/hosts/prod --tags "books-fe"
</code></pre>
</section>
<section id="cd-ansible-exercise-02-01-solution" data-background="lightgreen">
<h4>Continuous Deployment</h4>
<h3>Ansible Exercise</h3>
<h2>Colors Solution</h2>
<h4>roles/books-fe/defaults/main.yml</h4>
<pre><code contenteditable>
container: books-fe
blue_port: 9011
green_port: 9012
</code></pre>
</section>
<section id="cd-ansible-exercise-02-02-solution" data-background="lightgreen">
<h4>Continuous Deployment</h4>
<h3>Ansible Exercise</h3>
<h2>Colors Solution</h2>
<h4>roles/books-fe/tasks/main.yml</h4>
<pre><code contenteditable>
- name: Colors are retrieved
blue_green:
name: {{ container }}
blue_port: {{ blue_port }}
green_port: {{ green_port }}
register: colors
tags: [books-fe]
- debug: var=colors