-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
2813 lines (2055 loc) · 183 KB
/
atom.xml
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Build and Release]]></title>
<link href="http://lifuzu.com/atom.xml" rel="self"/>
<link href="http://lifuzu.com/"/>
<updated>2019-02-10T15:26:54-08:00</updated>
<id>http://lifuzu.com/</id>
<author>
<name><![CDATA[Richard Li]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[一个神奇的配置文件结构]]></title>
<link href="http://lifuzu.com/blog/2019/02/10/using-terraform-external-data-source/"/>
<updated>2019-02-10T14:51:35-08:00</updated>
<id>http://lifuzu.com/blog/2019/02/10/using-terraform-external-data-source</id>
<content type="html"><![CDATA[<p><img src="http://lifuzu.com/images/terraform.png" title="Terraform external data source" alt="Terraform external data source" /></p>
<h2>引子</h2>
<p>大约两年之前,当我还在Groupon工作的时候,实现过一个用JSON作为配置文件的build flow。基本概念借鉴 Bitrise和Fastlane,但力求每一个步骤(Step)使用JSON作为输入和输出,中间有一个处理过程。当时为了如何传递出返回的JSON信息,又不想污染环境变量,再加上出错信息处理,是否需要把出错结果也放在JSON里面,费过一段时间脑子。仍然没能设计出一个比较满意的结果。考虑到实现期限,当时的项目后来搁浅了。</p>
<p>因为离开了Groupon,那个项目没有善终。但是,如何设计一个比较满意的build step的配置文件,能够把编译步骤定义在其中,用JSON输入,JSON输出,如果出错能够妥善处理,log信息以编译模块为单元导入后台log服务,以便比较快速定位、查找出错信息,一直是我在持续编译/集成(Continuous Integration)上考虑的方向。</p>
<p>使用JSON格式,还有一个棘手的问题是怎么支持没有完全模块化的功能,比如,临时编写、调用一段bash脚本处理一个功能。JSON是一个非常简单的数据格式,不能支持变量替换,不能支持定义function(函数),把function写成string放在大段block中又失去了格式化显示、review纠错的优势。</p>
<p>几个月以前,首次接触了Jsonnet,对于JSON欠缺的功能,Jsonnet可谓对症下药,厉害之极(另一文详述)。然而如何在配置文件中实现函数,或者调用函数,关键是如何为之后的步骤传递返回值,没有帮助。这个不是Jsonnet的问题,因为Jsonnet本质上是一个JSON数据文件的扩展,它输出的是一个JSON数据文件,不能要求它考虑更多逻辑上面的实现。</p>
<h2>Terraform的外部数据源配置结构</h2>
<p>直到今天接触到terraform的external data source配置结构的设计,简直如得良玉,如获珍宝。它可以实现我想要的一切功能。首先上结构,然后详细解释:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>data "external" "example" {
</span><span class='line'> program = ["python", "${path.module}/example-data-source.py"]
</span><span class='line'>
</span><span class='line'> query = {
</span><span class='line'> # arbitrary map from strings to strings, passed
</span><span class='line'> # to the external program as the data query.
</span><span class='line'> id = "abc123"
</span><span class='line'> }
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>
<p><a href="https://www.terraform.io/docs/providers/external/data_source.html">https://www.terraform.io/docs/providers/external/data_source.html</a></p>
<h2>HCL配置结构解释</h2>
<p>这是一个HCL结构的配置文件。HCL(链接#2)是HashiCorp的配置文件,借鉴了UCL(链接#1)。虽然表现格式各有不同(包括Toml,Yaml),本质上都是JSON。底层的语言实现都会把这些数据存放为类JSON的结构。比如Python里面的Dict,Javascript的Assiciate Array,Java里面的Map,C++的Vector,等等。</p>
<p>这段配置文件定义了一个结构,如果用JSON表现,应该是这样的:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>{
</span><span class='line'> “data”: {
</span><span class='line'> “external”: {
</span><span class='line'> “example”: {
</span><span class='line'> “program”: [
</span><span class='line'> “python”,
</span><span class='line'> “${path.module}/example-data-source.py”
</span><span class='line'> ],
</span><span class='line'> “query”: {
</span><span class='line'> “id”: “abc123”
</span><span class='line'> }
</span><span class='line'> }
</span><span class='line'> }
</span><span class='line'> }
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>
<p>HCL结构非常灵活,第一行的<code>data "external" "example"</code>,实际上可以定义任意多个字段,表现为JSON可以是任意级的block。这也正是HCL结构巧妙之处,它可以非常清楚的定义出在哪个层次执行;换句话说,执行体层次定义清楚。如果用JSON直接表现,很难看出来执行体会在哪一层运行。因为JSON对每一层级都同等对待,所以对于人眼而言,表现力不够清楚和明显。</p>
<p>第二行的program是一个程序的调用,很容易能够理解为,使用python为解释器运行在目录 ${path.module}/下的脚本example-data-source.py。</p>
<p>第三行query是一段提供给以上程序的输入参数,完全的JSON结构。Terraform严格要求数据值为string(字符串),意味着integer(整型数字)也需要用引号包括。</p>
<p>上面的这个结构,实现了一个函数调用,大意如此:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ python ${path.module}/example-data-source.py ${query}</span></code></pre></td></tr></table></div></figure>
<h2>神奇的HCL配置结构</h2>
<p>那究竟奇妙的地方在哪里呢?</p>
<ol>
<li><p>它定义了输入参数/输出返回值的格式,这些返回值如何被后面的过程使用。比如,上传文件的过程完成以后,后面的过程需要知道上传文件成功返回的URL(链接),或者上传失败返回的错误信息。</p></li>
<li><p>它可以非常灵活的调用任何脚本,Python,Bash,Ruby,NodeJS等等;</p></li>
<li><p>它也可以是Serverless的调用端(如果满足JSON输入和JSON输出);</p></li>
<li><p>它可以实现没有完全模块化的功能;例如一个编译过程的临时fix(修正),之后可以用模块替代(使用Terraform模块扩展);</p></li>
</ol>
<h2>例子</h2>
<p>用一个例子来说明:</p>
<h3>安装Terraform</h3>
<p>Terraform是一个客户端软件,安装非常方便,下载一个客户端命令行程序,放在一个PATH路径下,shell可以找到就可以了。这个是安装指导:<a href="https://learn.hashicorp.com/terraform/getting-started/install.html%E3%80%82">https://learn.hashicorp.com/terraform/getting-started/install.html%E3%80%82</a></p>
<p>简单步骤:
1. 从这里:<a href="https://www.terraform.io/downloads.html">https://www.terraform.io/downloads.html</a> 下载对应的压缩包;
2. 解压生成<code>terraform</code>;
3. 后移到:<code>/usr/local/bin</code>目录下。</p>
<h3>Terraform 配置文件</h3>
<p>然后找到一个工作目录,创建一个terraform 配置文件,用到我们以上讨论到的结构,命名为<code>example.tf</code>,内容如下:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>data "external" "example" {
</span><span class='line'> program = ["python", "./example.py"]
</span><span class='line'>
</span><span class='line'> query = {
</span><span class='line'> # arbitrary map from strings to strings, passed
</span><span class='line'> # to the external program as the data query.
</span><span class='line'> id = "abc123"
</span><span class='line'> }
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'># 使用以上过程产生的结果,打印验证
</span><span class='line'>output "result" {
</span><span class='line'> value = "${data.external.example.result}"
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>
<h3>脚本文件</h3>
<p>在同样的目录下,创建对应的脚本文件example.py:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>import json
</span><span class='line'>import sys
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>def main(opts=None):
</span><span class='line'> '''The main routine'''
</span><span class='line'>
</span><span class='line'> retval = {}
</span><span class='line'> # 直接使用输入参数,这里可以改变为其他逻辑
</span><span class='line'> retval.update(opts)
</span><span class='line'> # 为了能看出改变,添加了一个key/value到输出
</span><span class='line'> retval.update({"abc": "123abc"})
</span><span class='line'> return retval
</span><span class='line'>
</span><span class='line'>if __name__ == "__main__":
</span><span class='line'> # 获得输入参数
</span><span class='line'> args = json.load(sys.stdin)
</span><span class='line'> # 运行主函数
</span><span class='line'> retval = main(args)
</span><span class='line'> # 打印JSON格式输出
</span><span class='line'> print(json.dumps(retval))</span></code></pre></td></tr></table></div></figure>
<h3>初始化配置环境</h3>
<p>然后在同样目录下,初始化这个terrform例子的配置环境:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ terraform init</span></code></pre></td></tr></table></div></figure>
<p>可以看到external plugin安装了:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Initializing provider plugins...
</span><span class='line'>- Checking for available provider plugins on https://releases.hashicorp.com...
</span><span class='line'>- Downloading plugin for provider "external" (1.0.0)...
</span><span class='line'>
</span><span class='line'>The following providers do not have any version constraints in configuration,
</span><span class='line'>so the latest version was installed.
</span><span class='line'>
</span><span class='line'>To prevent automatic upgrades to new major versions that may contain breaking
</span><span class='line'>changes, it is recommended to add version = "..." constraints to the
</span><span class='line'>corresponding provider blocks in configuration, with the constraint strings
</span><span class='line'>suggested below.
</span><span class='line'>
</span><span class='line'>* provider.external: version = "~> 1.0"
</span><span class='line'>
</span><span class='line'>Terraform has been successfully initialized!</span></code></pre></td></tr></table></div></figure>
<h3>运行配置文件</h3>
<p>运行terraform apply使用配置文件:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ terraform apply</span></code></pre></td></tr></table></div></figure>
<p>可以得到一下结果:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>data.external.example: Refreshing state...
</span><span class='line'>
</span><span class='line'>Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
</span><span class='line'>
</span><span class='line'>Outputs:
</span><span class='line'>
</span><span class='line'>result = {
</span><span class='line'> abc = 123abc
</span><span class='line'> id = abc123
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>
<p>我们可以看出terraform调用了python脚本,并把返回值放在模块命名的结构中:<code>data.external.example.result</code>。我们也可以在python脚本中加入错误处理(第二个版本)。可以加入log处理,以及其他一些可以<code>aspect oriented</code>(不影响主流程的功能块)的逻辑。</p>
<p>至此,我们完成了对Terraform的external data source作为配置结构的神奇之处的说明。你可以在这里看到本文的源代码:<a href="https://github.com/lifuzu/terraform">https://github.com/lifuzu/terraform</a> ,或者<a href="https://github.com/lifuzu/terraform/issues/new">“点击此链接”</a>给出你的意见和好的建议,谢谢</p>
<h3>参考文章或者链接:</h3>
<ul>
<li>UCL配置文件语言:<a href="https://github.com/vstakhov/libucl">https://github.com/vstakhov/libucl</a></li>
<li>HCL配置文件语言:<a href="https://github.com/hashicorp/hcl">https://github.com/hashicorp/hcl</a></li>
<li>HCL2配置文件语言:<a href="https://github.com/hashicorp/hcl2">https://github.com/hashicorp/hcl2</a></li>
<li>Terraform软件基础设施代码化:<a href="https://www.terraform.io/">https://www.terraform.io/</a></li>
<li>Terraform模块扩展:<a href="https://www.terraform.io/docs/extend/index.html">https://www.terraform.io/docs/extend/index.html</a></li>
<li>Jsonnet数据模块语言:<a href="https://jsonnet.org/">https://jsonnet.org/</a></li>
<li>本文源代码:<a href="https://github.com/lifuzu/terraform">https://github.com/lifuzu/terraform</a></li>
</ul>
<p>以下是一些扩展阅读。</p>
<h3>HCL与UCL关系:</h3>
<p>翻译自<a href="https://github.com/hashicorp/hcl/issues/154">https://github.com/hashicorp/hcl/issues/154</a></p>
<blockquote><p>(HCL)与UCL的兼容性肯定不是目标。尽管从一些通用语法风格中获取灵感,HCL的设计已经独立发展。可能最好将这两者视为表面相似,而不是更进一步的类同。</p>
<p>这里有一些非常详尽的列表,列出了我能想到的一些差异,只关注最终用户(不是Go API)的观点差异:</p>
<ul>
<li>UCL被定义为JSON的超集,而HCL分别处理本地语法和JSON语法:两者没有混淆。</li>
<li>HCL本地语法使用换行符分隔项目,而UCL需要逗号或分号。</li>
<li>HCL没有自动数字乘数后缀,尽管早期的文档声称它确实如此。 (这是Terraform直接使用UCL时继承的)</li>
<li>HCL没有内置的宏或包含支持;如果需要,这是必须在应用层处理的东西。</li>
</ul>
<p>在撰写本文时,HCL(很快将被追溯称为“HCL版本1”)不具有对变量或表达式的本机支持,如果需要,要求应用程序单独实现。这将在即将发布的版本2中发生变化其中受先前单独的[HIL](> <a href="https://github.com/hashicorp/hil%EF%BC%89">https://github.com/hashicorp/hil%EF%BC%89</a> 启发的表达式语法将包含在HCL中。一旦发布,HCL表达式将成为UCL变量的超集。</p>
<p>正如我所说,可能更好的是将这些视为表面上相似的两种语言,但已经发展出一些不同的决策和目标。</p>
<p>— Martin Atkins</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Instore Pick-up Maps]]></title>
<link href="http://lifuzu.com/blog/2016/05/01/instore-pick-up-maps/"/>
<updated>2016-05-01T22:22:22-07:00</updated>
<id>http://lifuzu.com/blog/2016/05/01/instore-pick-up-maps</id>
<content type="html"><![CDATA[<p><img src="http://lifuzu.com/images/floor-map.jpg" alt="floor plan map" /></p>
<h3>Instore pick-up maps</h3>
<p>Thoughts about a mobile application that provides a guide for customers to pick-up goods they wanted inside a supermarket.</p>
<p>With providing some goods’ name to the application that a customer want to buy, the application should provide an optimized route for the user to guide him/her to pick up the goods easily, without traffic jam around crowd, which always happens in some popular supermarkets, like Costco.</p>
<!-- more -->
<p>The application should improve the efficiency for customers, and provide high throughout for vendors. And even more, since some customers select items before they go to the supermarket, the application provide some prediction on what will become more popular soon, which provide a way for vendors to prepare beforehand.</p>
<h3>How to use:</h3>
<ol>
<li>Create and upload floor-map;</li>
<li>Craft a shape ( click some points to form a shape ) in a specified zone to put a goods’ info;</li>
<li>Tap the shape to config ( first time ) / display the details of the goods – price, and comments;</li>
<li>Long tap the shape to re-config the goods, or delete the goods;</li>
</ol>
<h3>References:</h3>
<p>Articles:</p>
<p><a href="http://www.extremetech.com/computing/132484-indoor-navigation-on-your-smartphone-using-the-earths-magnetic-field-just-like-a-homing-pigeon">http://www.extremetech.com/computing/132484-indoor-navigation-on-your-smartphone-using-the-earths-magnetic-field-just-like-a-homing-pigeon</a>
<a href="http://www.theverge.com/2012/7/10/3148926/indooratlas-indoor-navigation-magnetic-field">http://www.theverge.com/2012/7/10/3148926/indooratlas-indoor-navigation-magnetic-field</a>
<a href="http://www.sigmobile.org/mobisys/2011/slides/magnetism.pdf">http://www.sigmobile.org/mobisys/2011/slides/magnetism.pdf</a></p>
<p>Indoor Positioning System SDK:</p>
<p><a href="https://www.indooratlas.com/how-it-works/">https://www.indooratlas.com/how-it-works/</a>
<a href="https://developer.indooratlas.com/guide">https://developer.indooratlas.com/guide</a>
<a href="https://developer.indooratlas.com/dashboard">https://developer.indooratlas.com/dashboard</a>
<a href="http://blog.indooratlas.com/2015/06/17/getting-started-with-the-blue-dot/">http://blog.indooratlas.com/2015/06/17/getting-started-with-the-blue-dot/</a></p>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[User Generated Content Backend Design]]></title>
<link href="http://lifuzu.com/blog/2016/04/18/user-generated-content-backend-design/"/>
<updated>2016-04-18T22:44:27-07:00</updated>
<id>http://lifuzu.com/blog/2016/04/18/user-generated-content-backend-design</id>
<content type="html"><![CDATA[<h3>User Generated Content Backend Design</h3>
<p><img src="https://lh3.googleusercontent.com/-_Gyq2BrP680/VxW8wprqROI/AAAAAAAAEIU/JTX430yak3MIzuwq9Z5GRjexHiwcxwLmACLcB/s1000/back-end-mobile-design-banner.png" title="back-end-mobile-design-banner.png" alt="enter image description here" /></p>
<p>Most of time, web browser or mobile platform user only care how to get information from web or apps, they send GET on http protocol much more than POST/PUT. However, as one of our application required, we have to handle the requests which user submit contents to backend server.</p>
<p>We design the process in asynchronized way. User submit contents, once the 1st tier server (as the figure below) – mainly act as a database with a REST Interface – receive and save the contents, the server send back a response immediately to user, which indicates that user submit successfully.</p>
<!-- more -->
<p><img src="https://lh3.googleusercontent.com/-Pn33GdV6ATc/VxW9ADoVuuI/AAAAAAAAEIc/eEv5_BVLbaUnUSGf52dh_sepQytQRLHoACLcB/s1000/Backend_Design.png" title="Backend_Design.png" alt="enter image description here" /></p>
<p>However, the raw information saved to the 1st tier server doesn’t mean we don’t handle it soon. Sometimes, handling the information takes much time, such as making a compilation, parsing some web pages, creating a batch of email and/or sending some of the emails. In case to interrupt the previous process by the following requests, we build a message queue to adapt the messages with the asynchronized method. When more requests are coming, we can easily scale up with setting more processes to handle the jobs, and when requests decrease, we suspend some of them to save resources.</p>
<p>There are several solutions to support message queue with the existing services, such as SQS from Amazon, RabbitMQ as a Service from CloudAMQP, or Beanstalkd if like to host. We need them to provide APIs to trigger or be pulled by the handling processes to complete the jobs in a line or several lines.</p>
<p>Once the jobs have been handled, some contents have to be created and saved to content server, such as articles, and images which embedded in the articles. We put the contents, including images to a backend server – or 2nd tier server – and return the link and/or metadata to the 1st tier database server for providing quick responses to the coming requests.</p>
<h4>Options for Components</h4>
<p>For the 1st tier database server, I prefer to using Parse.com, or self-host CouchDB, which act as a thin layer of service, sort of cache, but persistent. Of course, for performance, we can add one more layer as cache on top, such as memcache, and even cache cluster.</p>
<p>We used to create and host own processing servers, now there are a bunch of continuous integration server can be used as a processing server, such as wercker.com, bitrise.com, if prefer to own and host, Jenkins is another good option, or Runner which come from gitlab.com</p>
<p>Content server is to store contents, like web pages (for social sharing to Facebook, Twitter, Wechat, etc.), images. Wordpress with the REST API plugin support is a good solution. You can submit a new post through REST API, then get the generated result to know what is the public URL for the article, then save the public URL to the 1st tier database for rapid responses.</p>
<p>AWS S3 is an alternative to Wordpress, S3 is more static then WordPress, since WordPress equiped with MySQL database which supports dynamic contents easier. However, storing images, css, javascript on S3 then cache to CDN is more popular solution than only rely on Wordpress for all of the contents.</p>
<p>Authenticate is an individual task, which we can leverage the 3rd party vendor with their services. Please refer to the Ref #1 for detail information.</p>
<h3>References:</h3>
<ol>
<li>Authenticate Vendor – <a href="http://www.auth0.com">http://www.auth0.com</a></li>
<li>Processing server – <a href="http://www.wercker.com">http://www.wercker.com</a></li>
<li>RabbitMQ as a service – <a href="https://www.cloudamqp.com/">https://www.cloudamqp.com/</a></li>
</ol>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Continuous Integration/Delivery Pipeline]]></title>
<link href="http://lifuzu.com/blog/2016/04/13/continuous-integration-slash-delivery-pipeline/"/>
<updated>2016-04-13T09:42:18-07:00</updated>
<id>http://lifuzu.com/blog/2016/04/13/continuous-integration-slash-delivery-pipeline</id>
<content type="html"><![CDATA[<p><img src="https://lh3.googleusercontent.com/-vYfGCI7QdNQ/Vw52k6Q4XdI/AAAAAAAAEHg/FrNo5qzDlYY8QcdY0bzU4FOf6EuTUs-XgCLcB/s600/Gas-Pipelines-in-Columbia.jpg" title="Gas-Pipelines-in-Columbia.jpg" alt="enter image description here" /></p>
<p>Based on several software release engineering system, such as: Jenkins (include a bunch of Plugins), Gerrit, Git, Mocha, Nodejs and etc, we create a continuous integration pipeline to control source code, validation change(s), build artifact, report test results and deploy the artifacts to various deployment servers, just as: dev, staging, production (all groups). Here is a draft diagram we are trying to implement for Content Stream Application Service:</p>
<!-- more -->
<p><img src="https://lh3.googleusercontent.com/-H3FwqFg7z38/Vw50_hFK4tI/AAAAAAAAEHU/1lUUkyBENdUb64L1LA640DUUNewtn03dwCLcB/s1000/Continuous+Integration+Pipeline.png" title="Continuous Integration Pipeline.png" alt="Continuous Integration Pipeline" /></p>
<p>Here are some explanations for a specific job of content stream, for example:</p>
<ul>
<li>The job contentstream-<strong>patchset</strong> will be triggered automatically when
one change is being pushed to Gerrit for review, it will set verify
bit ‘+1’ for the review if the build successfully; or warn the
submitter of the change if the build fail;</li>
<li>When any change is merged to the branch, for example, ‘master’, the
job contentstream-<strong>master</strong> will be triggered automatically to verify
the change if it affects the branch;</li>
<li>The job contentstream-master-<strong>release</strong> is to make tag, push the tag to server
to label a version of source code, which should be deployed to
deployment servers some time later;</li>
<li>The deployment jobs, like contentstream-master-<strong>deploy</strong>-to-* will deploy the source code to the dev|stag|prod (group1, group2, …) servers according to the version which labeled on the release job as above;</li>
</ul>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Feeding Build Logs Into Elasticsearch With Logstash on Jenkins]]></title>
<link href="http://lifuzu.com/blog/2016/03/21/feeding-build-logs-into-elasticsearch-with-logstash-on-jenkins/"/>
<updated>2016-03-21T11:47:26-07:00</updated>
<id>http://lifuzu.com/blog/2016/03/21/feeding-build-logs-into-elasticsearch-with-logstash-on-jenkins</id>
<content type="html"><![CDATA[<p><img src="https://lh3.googleusercontent.com/-AdsV-jHNTfA/VvBBBCryniI/AAAAAAAAEEk/LctcadsOSwAR2lnqdOxpxJUQdgurnCbHA/s600/BuildLogCollectionPipeline+%25282%2529.png" title="BuildLogCollectionPipeline (2).png" alt="enter image description here" /></p>
<p>Elasticsearch platform is designed to take data from any source and as a build guy, we create a lot of metadata every day, across Android, iOS, Windows platform, such as compiler warnings, errors, lint message, unit test reports, etc. Is it possible to collect such data, then store into Elasticsearch with Logstash plugins, then visualize them with Kibana?</p>
<p>In this article, we setup an Elasticsearch instance very quickly, with the support of elastic cloud, then config the Logstash plugin on Jenkins to feed log data into Elasticsearch space, then display the message with Kibana.</p>
<!-- more -->
<h3>Create elasticsearch instance on elastic cloud:</h3>
<p><img src="https://lh3.googleusercontent.com/-xgIACl1UHFM/VuItxKcMS3I/AAAAAAAAECA/N78QxZachx0aMysdbsfY3VtcRgp40M6Xw/s600/Screen+Shot+2016-03-10+at+6.30.03+PM.png" title="Screen Shot 2016-03-10 at 6.30.03 PM.png" alt="enter image description here" /></p>
<h3>Install logstash plugin on Jenkins with Plugin Manager:</h3>
<p><img src="https://lh3.googleusercontent.com/-fbTQCm8VCIo/VuIs5Qk7j5I/AAAAAAAAEBw/J_kEmkW-gf0Shr6Hi7GbuXYAoxVy-7GrQ/s1200/Screen+Shot+2016-03-10+at+6.25.34+PM.png" title="Screen Shot 2016-03-10 at 6.25.34 PM.png" alt="enter image description here" /></p>
<h3>Config logstash plugin as an agent:</h3>
<p><img src="https://lh3.googleusercontent.com/-2XN3VyQvZhE/VuIt8XeDuLI/AAAAAAAAECI/SMd98pqVqdcpxZoYsFU4BNYZ8GQJIcWyw/s600/Screen+Shot+2016-03-10+at+6.28.10+PM.png" title="Screen Shot 2016-03-10 at 6.28.10 PM.png" alt="enter image description here" /></p>
<h3>Config logstash for each project:</h3>
<p><img src="https://lh3.googleusercontent.com/-swBgeznEUNY/VuIuLocDnOI/AAAAAAAAECQ/pyA-RBdpM7cTVCOfaqo6e6uKY7P_fiNPg/s600/Screen+Shot+2016-03-10+at+6.31.52+PM.png" title="Screen Shot 2016-03-10 at 6.31.52 PM.png" alt="enter image description here" />
<img src="https://lh3.googleusercontent.com/-9YqKZ39g248/VuIuQkOTPeI/AAAAAAAAECY/7J-PSi5O9UoDItYQC5j1kdPT_Yy91QHjw/s600/Screen+Shot+2016-03-10+at+6.31.39+PM.png" title="Screen Shot 2016-03-10 at 6.31.39 PM.png" alt="enter image description here" /></p>
<h3>Search message from Kibana Web UI:</h3>
<p><img src="https://lh3.googleusercontent.com/-VvwIFnL0PLQ/VuIu_plyA4I/AAAAAAAAECw/k-2xBoXGfNI_AH4oRwZdPCdu5XVBRAQBA/s600/Screen+Shot+2016-03-10+at+6.35.05+PM.png" title="Screen Shot 2016-03-10 at 6.35.05 PM.png" alt="enter image description here" /></p>
<h3>Some useful URL to check status of elasticsearch:</h3>
<p>Check health of elasticsearch:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://02bb48d4a19b37090ea4ef33d4a4e596.us-west-1.aws.found.io:9200/_cat/health?v</span></code></pre></td></tr></table></div></figure>
<p>Check indices (tables/contents) on elasticsearch:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://02bb48d4a19b37090ea4ef33d4a4e596.us-west-1.aws.found.io:9200/_cat/indices?v</span></code></pre></td></tr></table></div></figure>
<h3>References:</h3>
<ol>
<li><a href="https://www.elastic.co/cloud">https://www.elastic.co/cloud</a></li>
<li><a href="https://wiki.jenkins-ci.org/display/JENKINS/Logstash+Plugin">https://wiki.jenkins-ci.org/display/JENKINS/Logstash+Plugin</a></li>
</ol>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Playing With Ansible to Manage Build Pool]]></title>
<link href="http://lifuzu.com/blog/2016/03/06/playing-with-ansible-to-manage-build-pool/"/>
<updated>2016-03-06T23:30:26-08:00</updated>
<id>http://lifuzu.com/blog/2016/03/06/playing-with-ansible-to-manage-build-pool</id>
<content type="html"><![CDATA[<p><img src="https://lh3.googleusercontent.com/-5avk7kTPus4/Vt0q8cKjYhI/AAAAAAAAEBU/3hJt7LybC-w/s600/ansible.png" title="ansible.png" alt="Ansible" /></p>
<p>Ansible is one of the best configuration management system, together with Puppet, Chef, and etc. Ansible makes IT deployment automatic and easy. With Ansible, deploying application, managing systems is becoming easier than ever, as well as building a strong foundation for DevOps.</p>
<p>This article use Ansible to config and manage Xcode build pool step by step.</p>
<!-- more -->
<h3>Install ansible on Ubuntu</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ sudo apt-get install software-properties-common
</span><span class='line'>$ sudo apt-add-repository ppa:ansible/ansible
</span><span class='line'>$ sudo apt-get update
</span><span class='line'>$ sudo apt-get install ansible</span></code></pre></td></tr></table></div></figure>
<h3>Install brew on Mac OS X server</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</span></code></pre></td></tr></table></div></figure>
<h3>Install ansible on all of the server</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ brew install ansible</span></code></pre></td></tr></table></div></figure>
<h3>Connect all clients from a machine (called controller) which you are using to control all clients</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ssh-genkey -t rsa -b 2048
</span><span class='line'>$ ssh-copy-id <client_username>@<client_server_address></span></code></pre></td></tr></table></div></figure>
<p>for example (for every client):</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ssh-copy-id [email protected]</span></code></pre></td></tr></table></div></figure>
<h3>Create hosts document under <code>/etc/ansible/hosts</code> on the controller</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[office:vars]
</span><span class='line'>admin_user=admin
</span><span class='line'>
</span><span class='line'>[sandbox]
</span><span class='line'>imac-1.local
</span><span class='line'>
</span><span class='line'>[office]
</span><span class='line'>imac-1.local
</span><span class='line'>imac-2.local</span></code></pre></td></tr></table></div></figure>
<h3>Config scp over ssh <code>/etc/ansible/ansible.cfg</code> (ref #3)</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[ssh_connection]
</span><span class='line'>scp_if_ssh=True</span></code></pre></td></tr></table></div></figure>
<h3>Try to connect all of the clients</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ansible -i hosts ubuntuservers -m ping -u build # specify hosts file
</span><span class='line'># OR
</span><span class='line'>$ ansible all -m ping -u admin
</span><span class='line'>imac-1.local | success >> {
</span><span class='line'> "changed": false,
</span><span class='line'> "ping": "pong"
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>imac-2.local | success >> {
</span><span class='line'> "changed": false,
</span><span class='line'> "ping": "pong"
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>
<p>cool, looks good for now!</p>
<h3>Create a playbook named <code>hello-ansible.yml</code> under the current folder</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>---
</span><span class='line'>- hosts: all
</span><span class='line'> remote_user: admin
</span><span class='line'> gather_facts: False
</span><span class='line'> tasks:
</span><span class='line'> - name: print to stdout
</span><span class='line'> command: echo "Hello"
</span><span class='line'> register: hello
</span><span class='line'>
</span><span class='line'> - debug: msg=""
</span><span class='line'>
</span><span class='line'> - name: print Java version
</span><span class='line'> shell: "java -version 2>&1"
</span><span class='line'> register: java_version
</span><span class='line'>
</span><span class='line'> - debug: msg=""</span></code></pre></td></tr></table></div></figure>
<h3>Run the playbook we created above</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ansible-playbook hello-ansible.yml</span></code></pre></td></tr></table></div></figure>
<p>It should print a lot of outputs, including:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>...
</span><span class='line'>TASK: [debug msg=""] *************************************************
</span><span class='line'>ok: [imac-1.local] => {
</span><span class='line'> "msg": "{u'changed': True, u'end': u'2015-10-22 14:21:08.740247', u'stdout': u'Hello', u'cmd': [u'echo', u'Hello'], u'start': u'2015-10-22 14:21:08.734848', u'delta': u'0:00:00.005399', u'stderr': u'', u'rc': 0, 'invocation': {'module_name': 'command', 'module_args': 'echo Hello'}, 'stdout_lines': [u'Hello']}"
</span><span class='line'>}
</span><span class='line'>ok: [imac-2.local] => {
</span><span class='line'> "msg": "{u'changed': True, u'end': u'2015-10-22 14:21:08.742023', u'stdout': u'Hello', u'cmd': [u'echo', u'Hello'], u'start': u'2015-10-22 14:21:08.736217', u'delta': u'0:00:00.005806', u'stderr': u'', u'rc': 0, 'invocation': {'module_name': 'command', 'module_args': 'echo Hello'}, 'stdout_lines': [u'Hello']}"
</span><span class='line'>}
</span><span class='line'>...
</span><span class='line'>TASK: [debug msg=""] *****************************
</span><span class='line'>ok: [imac-1.local] => {
</span><span class='line'> "msg": "[u'java version 1.8.0_45', u'Java(TM) SE Runtime Environment (build 1.8.0_45-b14)', u'Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)']"
</span><span class='line'>}
</span><span class='line'>ok: [imac-2.local] => {
</span><span class='line'> "msg": "[u'java version 1.8.0_45', u'Java(TM) SE Runtime Environment (build 1.8.0_45-b14)', u'Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)']"
</span><span class='line'>}
</span><span class='line'>...</span></code></pre></td></tr></table></div></figure>
<p>OR</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ansible-playbook -i hosts macports.yaml -K</span></code></pre></td></tr></table></div></figure>
<p><code>-i</code> specify hosts file, and <code>-K</code> ask for sudo password.</p>
<h3>Create a git repo to store the playbooks</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ git init .
</span><span class='line'>$ git add .
</span><span class='line'>$ git config --global user.email "<[email protected]>"
</span><span class='line'>$ git config --global user.name "<Your Name>"
</span><span class='line'>$ git commit
</span><span class='line'>$ git remote add origin <git_repo>
</span><span class='line'>$ git push origin master</span></code></pre></td></tr></table></div></figure>
<p>OK, we start to figure out how to manage Xcode from now.</p>
<h3>Create a playbook for xcode-install</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>---
</span><span class='line'>- hosts: all
</span><span class='line'> remote_user: jenkins-admin
</span><span class='line'> gather_facts: False
</span><span class='line'> tasks:
</span><span class='line'> - name: install xcode-install
</span><span class='line'> gem: name=xcode-install state=present</span></code></pre></td></tr></table></div></figure>
<p>name it as <code>xcode-install.yaml</code></p>
<p>TODO:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ softwareupdate -l
</span><span class='line'>$ softwareupdate -i -a
</span><span class='line'>$ xcode-install list
</span><span class='line'>$ xcode-install install 7.1
</span><span class='line'>$ ...</span></code></pre></td></tr></table></div></figure>
<h3>Reuse the shared module, Ansible call it <code>Role</code> (ref #4)</h3>
<p>“Roles in Ansible build on the idea of include files and combine them to form clean, reusable abstractions – they allow you to focus more on the big picture and only dive down into the details when needed.”</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ sudo ansible-galaxy install smola.java # see readme at ref #5</span></code></pre></td></tr></table></div></figure>
<p>then create playbook <code>java.yml</code> with the following content:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>---
</span><span class='line'>- hosts: ubuntuservers
</span><span class='line'> remote_user: build
</span><span class='line'> sudo: True
</span><span class='line'> vars:
</span><span class='line'> java_packages:
</span><span class='line'> - oracle-java6-installer
</span><span class='line'> - oracle-java6-set-default
</span><span class='line'>
</span><span class='line'> roles:
</span><span class='line'> - { role: smola.java }</span></code></pre></td></tr></table></div></figure>
<p>run the command:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ansible-playbook -i hosts java.yml</span></code></pre></td></tr></table></div></figure>
<h3>References:</h3>
<ol>
<li><a href="http://brew.sh/">http://brew.sh/</a></li>
<li><a href="https://github.com/ideasonpurpose/ansible-playbooks">https://github.com/ideasonpurpose/ansible-playbooks</a></li>
<li><a href="http://stackoverflow.com/questions/23899028/ansible-failed-to-transfer-file-to">http://stackoverflow.com/questions/23899028/ansible-failed-to-transfer-file-to</a></li>
<li><a href="http://docs.ansible.com/ansible/playbooks_roles.html">http://docs.ansible.com/ansible/playbooks_roles.html</a></li>
<li><a href="https://github.com/smola/ansible-java-role">https://github.com/smola/ansible-java-role</a></li>
</ol>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Install Libxmljs Failed on Macosx]]></title>
<link href="http://lifuzu.com/blog/2016/01/01/install-libxmljs-failed-on-macosx/"/>
<updated>2016-01-01T15:59:11-08:00</updated>
<id>http://lifuzu.com/blog/2016/01/01/install-libxmljs-failed-on-macosx</id>
<content type="html"><![CDATA[<p>Today I am trying to install osmosis on macosx</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>npm i --save osmosis</span></code></pre></td></tr></table></div></figure>
<p>libxmljs is one of the dependency of it, which is failed during installing, here is the error log:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>...
</span><span class='line'>3 warnings generated.
</span><span class='line'> CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
</span><span class='line'> LIBTOOL-STATIC Release/xml.a
</span><span class='line'>libtool: unrecognized option `-static'
</span><span class='line'>libtool: Try `libtool --help' for more information.
</span><span class='line'>make: *** [Release/xml.a] Error 1
</span><span class='line'>gyp ERR! build error
</span><span class='line'>gyp ERR! stack Error: `make` failed with exit code: 2
</span><span class='line'>...</span></code></pre></td></tr></table></div></figure>
<!-- more -->
<p>Search with Google, found some cues, but not total same. I remember I installed libtool with port to fix a build error before, so the root cause should be two different libtools installed on my macosx:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ which -a libtool
</span><span class='line'>/usr/local/bin/libtool
</span><span class='line'>/usr/bin/libtool</span></code></pre></td></tr></table></div></figure>
<p>Verify if installed with <code>port</code>:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ port installed
</span><span class='line'>The following ports are currently installed:
</span><span class='line'> ...
</span><span class='line'> libtool @2.4.6_2 (active)
</span><span class='line'> ...</span></code></pre></td></tr></table></div></figure>
<p>Uninstall the one which <code>port</code> installed:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ sudo port uninstall libtool</span></code></pre></td></tr></table></div></figure>
<p>Then try to compile libxmljs component:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>...
</span><span class='line'>3 warnings generated.
</span><span class='line'> CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
</span><span class='line'> LIBTOOL-STATIC Release/xml.a
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/libxmljs.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_attribute.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_document.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_element.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_comment.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_namespace.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_node.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_sax_parser.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_syntax_error.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_text.o
</span><span class='line'> CXX(target) Release/obj.target/xmljs/src/xml_xpath_context.o
</span><span class='line'> SOLINK(target) Release/xmljs.node</span></code></pre></td></tr></table></div></figure>
<p>The problem is resolved!</p>
<h3>References:</h3>
<ol>
<li><a href="https://github.com/Homebrew/homebrew/issues/28442">https://github.com/Homebrew/homebrew/issues/28442</a></li>
<li><a href="https://github.com/rc0x03/node-osmosis">https://github.com/rc0x03/node-osmosis</a></li>
</ol>
<blockquote><p>Written with <a href="https://stackedit.io/">StackEdit</a>.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[RESTful WordPress]]></title>
<link href="http://lifuzu.com/blog/2015/10/08/restful-wordpress/"/>
<updated>2015-10-08T22:36:58-07:00</updated>
<id>http://lifuzu.com/blog/2015/10/08/restful-wordpress</id>
<content type="html"><![CDATA[<p><img src="http://www.codediesel.com/wp-content/uploads/2015/07/wordpress-rest-api.jpg" alt="enter image description here" />
This article introduce how to launch and config WordPress at first time, based on the composed WordPress docker container. With the several WordPress plugins, setup the RESTful API and config their permissions to register users, create new posts etc.</p>
<!-- more -->
<p>At first, please following the <a href="http://lifuzu.com/blog/2015/10/05/wordpress-in-docker/">previous post</a> to compose the latest WordPress docker container.</p>
<h3>Start the composed WordPress docker container</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'># Inside the directory contained docker-compose.yml
</span><span class='line'>$ docker-compose up -d</span></code></pre></td></tr></table></div></figure>
<p>You should be able to get the container IP address (not localhost, or 127.0.0.1) with the commands:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'># 1. to find the launched container
</span><span class='line'>$ docker-machine ls
</span><span class='line'>NAME ACTIVE DRIVER STATE URL SWARM
</span><span class='line'>default virtualbox Running tcp://192.168.99.100:2376
</span><span class='line'>
</span><span class='line'># 2. to address the IP address with the name
</span><span class='line'>$ docker-machine ip default
</span><span class='line'>192.168.99.100</span></code></pre></td></tr></table></div></figure>
<p>Now open a browser to access the IP address with the port which set up in the composed yaml file: <code>docker-compose.yml</code>:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://192.168.99.100:8080</span></code></pre></td></tr></table></div></figure>
<h3>Config WordPress with a blog name and admin account</h3>