-
Notifications
You must be signed in to change notification settings - Fork 32
/
Envoy.blade.php
1802 lines (1664 loc) · 84.8 KB
/
Envoy.blade.php
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
@include('envoy.config.php');
@setup
if ( ! isset($app_name) ) {
throw new Exception('App Name is not set');
}
if ( ! isset($server_connections) ) {
throw new Exception('Server connections(SSH login username/host is not set)');
}
if ( ! isset($source_repo)){
throw new Exception('VCS Source repository is not set');
}
if ( ! isset($pack_mode) ) {
throw new Exception('Pack Mode is not set');
}
if ( ! isset($deploy_mode) ) {
throw new Exception('Deploy Mode is not set');
}
if ( ! isset($settings) ) {
throw new Exception('Misc Settings is not set');
}
if ( ! isset($deploy_basepath) ) {
throw new Exception('Base Path is not set');
}
if ( ! isset($release_keep_count) ) {
throw new Exception('Release Keep Count is not set');
}
if ( intval($release_keep_count)<1 ) {
throw new Exception('Release Keep Count must greater than 1');
}
if ( substr($deploy_basepath, 0, 1) !== '/' ) {
throw new Exception('Careful - your base path does not begin with /');
}
$server_labels = [];
$server_owners = [];
$server_userathosts = [];
$server_hosts = [];
$server_ports = [];
$server_map = [];
foreach($server_connections as $row_label=>$row_conn_settings){
$row_userathost = '';
$row_host = '';
$row_port = 22;
$row_conn_string = '';
$row_owner_set = false;
$row_owner = $settings['service_owner_default'];
if(is_array($row_conn_settings)){
if(isset($row_conn_settings['conn'])){
$row_conn_string = $row_conn_settings['conn'];
if(isset($row_conn_settings['owner'])){
$row_owner = $row_conn_settings['owner']; $row_owner_set = true;
}
}elseif(isset($row_conn_settings[0])){
$row_conn_string = $row_conn_settings[0];
if(isset($row_conn_settings[1])){
$row_owner = $row_conn_settings[1]; $row_owner_set = true;
}
}else{
throw Exception('server connections settings error at #'.$row_label);
}
}else{
$row_conn_string = trim($row_conn_settings);
}
if(preg_match('/^(.*)(-p\s*[0-9]+)(.*)$/',$row_conn_string,$matches)){
foreach($matches as $line=>$match){
if($line>0){
$match = trim($match);
if(!empty($match)){
if(substr($match,0,2)=='-p'){
$row_port = intval(trim(substr($match,2)));
}else{
$row_userathost = $match;
}
}
}
}
}else{
$row_userathost = $row_conn_string;
}
$row_userandhostset = explode('@',$row_userathost);
if(count($row_userandhostset)>1){
if($row_owner_set==false){
$row_owner = trim($row_userandhostset[0]);
$row_owner_set = true;
}
$row_host = trim($row_userandhostset[1]);
}else{
$row_host = trim($row_userandhostset[0]);
}
$server_label = $row_label;
is_numeric($server_label) && $server_label = $settings['server_prefix_default'].$server_label;
$server_labels[] = $server_label;
$server_owners[] = $row_owner;
$server_userathosts[] = $row_userathost;
$server_hosts[] = $row_host;
$server_ports[] = $row_port;
$server_map[$server_label] = $row_conn_string;
}
$envoy_servers = array_merge(['local'=>'localhost',],$server_map);
$now = new DateTime();
$dateDisplay = $now->format('Y-m-d H:i:s');
$date = $now->format('YmdHis');
$env = isset($env) ? $env : $settings['env_default'];
$branch = isset($branch) ? $branch : $settings['branch_default'];
$deploy_mode = trim(strtolower($deploy_mode));
$deploy_basepath = rtrim($deploy_basepath, '/');
$app_base = $deploy_basepath.'/'.$app_name;
$source_name = 'source';
$version_name = 'current';
$source_dir = $app_base.'/'.$source_name;
$build_dir = $app_base.'/builds';
$release_dir = $app_base.'/releases';
$version_dir = $app_base.'/versions';
$shared_dir = $app_base.'/shared';
$tmp_dir = $app_base.'/tmp';
$app_dir = $app_base.'/'.$version_name;
$releaseprev_dir_incr = $version_dir.'/releaseprev_incr';
$releaselast_dir_incr = $version_dir.'/releaselast_incr';
$releaseprev_dir_link = $version_dir.'/releaseprev_link';
$releaselast_dir_link = $version_dir.'/releaselast_link';
$releasecurrent_dir_link = $version_dir.'/releasecurrent_link';
$buildreleaseprev_incr = $version_dir.'/buildreleaseprev_incr';
$buildreleaselast_incr = $version_dir.'/buildreleaselast_incr';
$buildreleaseprev_link = $version_dir.'/buildreleaseprev_link';
$buildreleaselast_link = $version_dir.'/buildreleaselast_link';
$buildreleasecurrent_link = $version_dir.'/buildreleasecurrent_link';
$release = isset($release) ? $release :'release_' . date('YmdHis');
$local_dir = getcwd();
$localdeploy_dirname = '.envoydeploy';
$localdeploy_base = $local_dir.'/'.$localdeploy_dirname;
$localdeploy_source_dir = $localdeploy_base.'/'.$source_name;
$localdeploy_tmp_dir = $localdeploy_base.'/tmp';
$rsyncExcludePatternContext = $rsyncExcludePatternSharedDirs = $rsyncExcludePatternAddon = $rsyncExcludePatternSubmodule = '';
$tarExcludePatternContext = $tarExcludePatternSharedDirs = $tarExcludePatternAddon = $tarExcludePatternSubmodule = '';
if(!empty($shared_subdirs)){
foreach($shared_subdirs as $subdirname){
$rsyncExcludePatternSharedDirs.= ' --exclude="/'.$subdirname.'/"';
$tarExcludePatternSharedDirs.= ' --exclude="./'.$subdirname.'/"';
}
}
if(isset($exclude_addon_pattens) && !empty($exclude_addon_pattens)){
foreach($exclude_addon_pattens as $exclude_addon_patten){
$rsyncExcludePatternAddon.= ' --exclude="'.$exclude_addon_patten.'"';
$tarExcludePatternAddon.= ' --exclude=".'.$exclude_addon_patten.'"';
}
}
if(isset($submodule_pathmap) && !empty($submodule_pathmap)){
foreach($submodule_pathmap as $submodule_path=>$submodule_deployedpath){
$rsyncExcludePatternSubmodule.= ' --exclude="/'.$submodule_path.'/"';
$tarExcludePatternSubmodule.= ' --exclude="./'.$submodule_path.'/"';
}
}
$rsyncExcludePatternContext .= $rsyncExcludePatternSharedDirs;
$rsyncExcludePatternContext .= $rsyncExcludePatternAddon;
$rsyncExcludePatternContext .= $rsyncExcludePatternSubmodule;
//$tarExcludePatternContext .= $tarExcludePatternSharedDirs;
$tarExcludePatternContext .= $tarExcludePatternAddon;
$tarExcludePatternContext .= $tarExcludePatternSubmodule;
$spec_procs = array(
'pack_localpack'=>array(
//'show_env_local',
//'init_basedir_local',
'updaterepo_localsrc',
'envsetup_localsrc',
'depsinstall_localsrc',
'extracustomoverwrite_localsrc',
//'runtimeoptimize_localsrc',
'packrelease_localsrc',
),
'rcp_localpack'=>array(
'rcpreleasepack_to_remote',
),
'extract_localpack'=>array(
'extractreleasepack_on_remote',
),
'pack_localbuildpack'=>array(
//'show_env_local',
//'init_basedir_local',
'updaterepo_localsrc',
'envsetup_localsrc',
'depsinstall_localsrc',
'extracustomoverwrite_localsrc',
'runtimeoptimize_localsrc',
'boxbuild_localsrc',
),
'rcp_localbuildpack'=>array(
'rcpbuildreleasepack_to_remote',
),
'extract_localbuildpack'=>array(
'extractbuildreleasepack_on_remote',
),
'pack_remotepack'=>array(
//'show_env_remote',
//'init_basedir_remote',
'updaterepo_remotesrc',
'envsetup_remotesrc',
'depsinstall_remotesrc',
'extracustomoverwrite_remotesrc',
//'runtimeoptimize_remotesrc',
),
'pack_remotebuildpack'=>array(
//'show_env_remote',
//'init_basedir_remote',
'updaterepo_remotesrc',
'envsetup_remotesrc',
'depsinstall_remotesrc',
'extracustomoverwrite_remotesrc',
'runtimeoptimize_remotesrc',
'boxbuild_remotesrc',
),
'subproc_releasesetup'=>array(
'syncshareddata_remotesrc',
'prepare_remoterelease',
'baseenvlink_remoterelease',
'depsreinstall_remoterelease',
),
'subproc_versionsetup'=>array(
'syncreleasetoapp_version',
'runtimeoptimize_version',
'databasemigrate_version',
'customtask_on_deploy',
'cleanupoldreleases_on_remote',
'cleanup_tempfiles_local',
'cleanup_tempfiles_remote',
),
'subproc_buildreleasesetup'=>array(
'prepare_remotebuildrelease',
),
'subproc_buildversionsetup'=>array(
'syncbuildreleasetoapp_version',
'baseenvlink_version',
'cleanupoldbuildreleases_on_remote',
'cleanup_tempfiles_local',
'cleanup_tempfiles_remote',
),
);
$deploy_macro_context = '';
$deploy_macro_context .= implode(PHP_EOL,['show_env_local','init_basedir_local','init_basedir_remote','rcp_env_to_remote','link_env_on_remote']).PHP_EOL;
if($pack_mode=='local'){
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['pack_localpack']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['rcp_localpack']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['extract_localpack']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['subproc_releasesetup']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['subproc_versionsetup']);
}else{
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['pack_remotepack']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['subproc_releasesetup']).PHP_EOL;
$deploy_macro_context .= implode(PHP_EOL,$spec_procs['subproc_versionsetup']);
}
$build_macro_context = '';
$build_macro_context .= implode(PHP_EOL,['show_env_local','init_basedir_local','init_basedir_remote','rcp_env_to_remote','link_env_on_remote']).PHP_EOL;
if($pack_mode=='local'){
$build_macro_context .= implode(PHP_EOL,$spec_procs['pack_localbuildpack']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['rcp_localbuildpack']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['extract_localbuildpack']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['subproc_buildreleasesetup']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['subproc_buildversionsetup']);
}else{
$build_macro_context .= implode(PHP_EOL,$spec_procs['pack_remotebuildpack']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['subproc_buildreleasesetup']).PHP_EOL;
$build_macro_context .= implode(PHP_EOL,$spec_procs['subproc_buildversionsetup']);
}
@endsetup
@servers($envoy_servers)
@task('customtask_on_deploy',['on' => $server_labels, 'parallel' => true])
if [ {{ intval($settings['enable_custom_task_after_deploy']) }} -eq 1 ]; then
echo 'Calling Custom Task On Deploy...';
cd {{ $app_dir }};
{{-- Call your custom task on deploy eg: --}}
@if ( function_exists('customtask_on_deploy') )
{{ customtask_on_deploy() }}
@endif
echo "Custom Task done.";
fi
@endtask
@macro('help')
show_cmd_list
@endmacro
@macro('show_env')
show_env_local
show_env_remote
@endmacro
@macro('deploy_init')
init_basedir_local
init_basedir_remote
rcp_env_all_to_remote
link_env_on_remote
@endmacro
@macro('deploy')
{{ $deploy_macro_context }}
@endmacro
@macro('build')
{{ $build_macro_context }}
@endmacro
@macro('rollback')
rollback_version
@endmacro
@macro('buildrollback')
buildrollback_version
@endmacro
@macro('deploy_remotepack')
show_env_remote
init_basedir_local
init_basedir_remote
rcp_env_to_remote
link_env_on_remote
updaterepo_remotesrc
envsetup_remotesrc
depsinstall_remotesrc
extracustomoverwrite_remotesrc
runtimeoptimize_remotesrc
syncshareddata_remotesrc
prepare_remoterelease
baseenvlink_remoterelease
depsreinstall_remoterelease
syncreleasetoapp_version
databasemigrate_version
customtask_on_deploy
cleanupoldreleases_on_remote
cleanup_tempfiles_local
cleanup_tempfiles_remote
@endmacro
@macro('deploy_localpack')
show_env_remote
init_basedir_local
init_basedir_remote
rcp_env_to_remote
link_env_on_remote
updaterepo_localsrc
envsetup_localsrc
depsinstall_localsrc
extracustomoverwrite_localsrc
runtimeoptimize_localsrc
packrelease_localsrc
rcpreleasepack_to_remote
extractreleasepack_on_remote
syncshareddata_remotesrc
prepare_remoterelease
baseenvlink_remoterelease
depsreinstall_remoterelease
syncreleasetoapp_version
databasemigrate_version
customtask_on_deploy
cleanupoldreleases_on_remote
cleanup_tempfiles_local
cleanup_tempfiles_remote
@endmacro
@macro('pack_remotepack')
show_env_remote
init_basedir_remote
updaterepo_remotesrc
envsetup_remotesrc
depsinstall_remotesrc
extracustomoverwrite_remotesrc
runtimeoptimize_remotesrc
@endmacro
@macro('pack_localpack')
show_env_local
init_basedir_local
updaterepo_localsrc
envsetup_localsrc
depsinstall_localsrc
extracustomoverwrite_localsrc
runtimeoptimize_localsrc
packrelease_localsrc
@endmacro
@macro('rcp_localpack')
rcpreleasepack_to_remote
@endmacro
@macro('extract_localpack')
extractreleasepack_on_remote
@endmacro
@macro('mandeploy_remotesrc')
syncshareddata_remotesrc
prepare_remoterelease
baseenvlink_remoterelease
depsreinstall_remoterelease
syncreleasetoapp_version
databasemigrate_version
customtask_on_deploy
cleanupoldreleases_on_remote
cleanup_tempfiles_local
cleanup_tempfiles_remote
@endmacro
@macro('pack_localbuildpack')
show_env_local
init_basedir_local
updaterepo_localsrc
envsetup_localsrc
depsinstall_localsrc
extracustomoverwrite_localsrc
runtimeoptimize_localsrc
boxbuild_localsrc
@endmacro
@macro('rcp_localbuildpack')
rcpbuildreleasepack_to_remote
@endmacro
@macro('extract_localbuildpack')
extractbuildreleasepack_on_remote
@endmacro
@macro('manbuild_remotesrc')
prepare_remotebuildrelease
syncbuildreleasetoapp_version
baseenvlink_version
cleanupoldbuildreleases_on_remote
cleanup_tempfiles_local
cleanup_tempfiles_remote
@endmacro
@macro('dbrollback')
databasemigraterollback_version
@endmacro
@macro('appbackup')
backupapp_version
@endmacro
@macro('databackup')
backupshareddata_version
@endmacro
@task('show_cmd_list',['on' => 'local'])
echo '================';
echo '---- [common task] ----';
echo 'show_cmd_list';
echo 'show_env';
echo 'deploy_init';
echo 'deploy';
echo 'rollback';
echo 'build';
echo 'buildrollback';
echo '---- [spec task] ----';
echo 'deploy_remotepack';
echo 'deploy_localpack';
echo 'pack_remotepack';
echo 'pack_localpack';
echo 'rcp_localpack';
echo 'extract_localpack';
echo 'mandeploy_remotesrc';
echo 'pack_localbuildpack';
echo 'rcp_localbuildpack';
echo 'extract_localbuildpack';
echo 'manbuild_remotesrc';
echo '---- [addon task] ----';
echo 'dbrollback';
echo 'appbackup';
echo 'databackup';
echo '================';
@endtask
@task('show_env_local',['on' => 'local'])
echo '...[execute at local]';
echo 'Current Release Name: {{$release}}';
echo 'Current environment is {{$env}}';
echo 'Current branch is {{$branch}}';
echo 'Current pack mode is {{$pack_mode}}';
echo 'Current deploy mode is {{$deploy_mode}}';
echo 'Deployment Start at {{$dateDisplay}}';
echo '----';
@endtask
@task('show_env_remote',['on' => $server_labels, 'parallel' => true])
echo '...[execute at remote]';
echo 'Current Release Name: {{$release}}';
echo 'Current environment is {{$env}}';
echo 'Current pack mode is {{$pack_mode}}';
echo 'Current branch is {{$branch}}';
echo 'Current deploy mode is {{$deploy_mode}}';
echo 'Deployment Start at {{$dateDisplay}}';
echo '----';
@endtask
@task('init_basedir_local',['on' => 'local'])
[ -d {{ $localdeploy_base }} ] || mkdir -p {{ $localdeploy_base }};
{{--[ -d {{ $localdeploy_source_dir }} ] || mkdir -p {{ $localdeploy_source_dir }};--}}
[ -d {{ $localdeploy_tmp_dir }} ] || mkdir -p {{ $localdeploy_tmp_dir }};
[ -d {{ $localdeploy_tmp_dir }}/servers ] || mkdir -p {{ $localdeploy_tmp_dir }}/servers;
@endtask
@task('init_basedir_remote',['on' => $server_labels, 'parallel' => true])
{{--[ -d {{ $source_dir }} ] || mkdir -p {{ $source_dir }};--}}
[ -d {{ $build_dir }} ] || mkdir -p {{ $build_dir }};
[ -d {{ $release_dir }} ] || mkdir -p {{ $release_dir }};
[ -d {{ $version_dir }} ] || mkdir -p {{ $version_dir }};
[ -d {{ $shared_dir }} ] || mkdir -p {{ $shared_dir }};
[ -d {{ $tmp_dir }} ] || mkdir -p {{ $tmp_dir }};
shareddirs="{{ implode(' ',$shared_subdirs) }}";
for subdirname in ${shareddirs};
do
[ -d {{ $shared_dir }}/${subdirname} ] || mkdir -p {{ $shared_dir }}/${subdirname};
done
@endtask
@task('updatesharedpermissions_on_remote',['on' => $server_labels, 'parallel' => true])
echo "update shared path permissions...";
if [ -e {{ $tmp_dir }}/service_owner ]; then
service_owner=`cat {{ $tmp_dir }}/service_owner`;
else
service_owner="{{ $settings['service_owner_default'] }}";
fi
shareddirs="{{ implode(' ',$shared_subdirs) }}";
for subdirname in ${shareddirs};
do
[ -d {{ $shared_dir }}/${subdirname} ] || mkdir -p {{ $shared_dir }}/${subdirname};
chgrp -Rf ${service_owner} {{ $shared_dir }}/${subdirname};
chmod -Rf ug+rwx {{ $shared_dir }}/${subdirname};
done
echo "update shared path permissions Done.";
@endtask
@task('rcp_env_to_remote',['on' => 'local'])
echo "rcp env file to remote...";
server_owners="{{ implode(' ',$server_owners) }}";
server_hosts="{{ implode(' ',$server_hosts) }}";
server_userathosts="{{ implode(' ',$server_userathosts) }}";
server_ports="{{ implode(' ',$server_ports) }}";
index_count=0;
for item in $server_owners;do
eval server_owners_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_hosts;do
eval server_hosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_userathosts;do
eval server_userathosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_ports;do
eval server_ports_${index_count}=$item;
index_count=$((index_count+1));
done
index_length=$((index_count-1));
for step_index in $(seq 0 $index_length)
do
eval step_owners=\$server_owners_${step_index};
eval step_hosts=\$server_hosts_${step_index};
eval step_userathosts=\$server_userathosts_${step_index};
eval step_ports=\$server_ports_${step_index};
echo "execute for server: ${step_userathosts} ${step_ports}";
echo "${step_owners}" > {{ $localdeploy_tmp_dir }}/servers/${step_hosts};
scp -p${step_ports} {{ $localdeploy_tmp_dir }}/servers/${step_hosts} ${step_userathosts}:{{ $tmp_dir }}/service_owner;
[ -f {{ $local_dir }}/.env.{{ $env }} ] && scp -p${step_ports} {{ $local_dir }}/.env.{{ $env }} ${step_userathosts}:{{ $app_base }}/.env.{{ $env }};
[ -f {{ $local_dir }}/envoy.config.{{ $env }}.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.{{ $env }}.php ${step_userathosts}:{{ $app_base }}/envoy.config.{{ $env }}.php;
done
echo "rcp env file to remote Done.";
@endtask
@task('rcp_env_all_to_remote',['on' => 'local'])
echo "rcp env all files to remote...";
server_owners="{{ implode(' ',$server_owners) }}";
server_hosts="{{ implode(' ',$server_hosts) }}";
server_userathosts="{{ implode(' ',$server_userathosts) }}";
server_ports="{{ implode(' ',$server_ports) }}";
index_count=0;
for item in $server_owners;do
eval server_owners_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_hosts;do
eval server_hosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_userathosts;do
eval server_userathosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_ports;do
eval server_ports_${index_count}=$item;
index_count=$((index_count+1));
done
index_length=$((index_count-1));
for step_index in $(seq 0 $index_length)
do
eval step_owners=\$server_owners_${step_index};
eval step_hosts=\$server_hosts_${step_index};
eval step_userathosts=\$server_userathosts_${step_index};
eval step_ports=\$server_ports_${step_index};
echo "execute for server: ${step_userathosts} ${step_ports}";
echo "${step_owners}" > {{ $localdeploy_tmp_dir }}/servers/${step_hosts};
scp -p${step_ports} {{ $localdeploy_tmp_dir }}/servers/${step_hosts} ${step_userathosts}:{{ $tmp_dir }}/service_owner;
[ -f {{ $local_dir }}/.env.development ] && scp -p${step_ports} {{ $local_dir }}/.env.development ${step_userathosts}:{{ $app_base }}/.env.development;
[ -f {{ $local_dir }}/.env.local ] && scp -p${step_ports} {{ $local_dir }}/.env.local ${step_userathosts}:{{ $app_base }}/.env.local;
[ -f {{ $local_dir }}/.env.production ] && scp -p${step_ports} {{ $local_dir }}/.env.production ${step_userathosts}:{{ $app_base }}/.env.production;
[ -f {{ $local_dir }}/.env.testing ] && scp -p${step_ports} {{ $local_dir }}/.env.testing ${step_userathosts}:{{ $app_base }}/.env.testing;
[ -f {{ $local_dir }}/.env.{{ $env }} ] && scp -p${step_ports} {{ $local_dir }}/.env.{{ $env }} ${step_userathosts}:{{ $app_base }}/.env.{{ $env }};
[ -f {{ $local_dir }}/envoy.config.development.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.development.php ${step_userathosts}:{{ $app_base }}/envoy.config.development.php;
[ -f {{ $local_dir }}/envoy.config.local.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.local.php ${step_userathosts}:{{ $app_base }}/envoy.config.local.php;
[ -f {{ $local_dir }}/envoy.config.production.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.production.php ${step_userathosts}:{{ $app_base }}/envoy.config.production.php;
[ -f {{ $local_dir }}/envoy.config.testing.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.testing.php ${step_userathosts}:{{ $app_base }}/envoy.config.testing.php;
[ -f {{ $local_dir }}/envoy.config.{{ $env }}.php ] && scp -p${step_ports} {{ $local_dir }}/envoy.config.{{ $env }}.php ${step_userathosts}:{{ $app_base }}/envoy.config.{{ $env }}.php;
done
echo "rcp env all files to remote Done.";
@endtask
@task('link_env_on_remote',['on' => $server_labels, 'parallel' => true])
echo "link env on remote...";
if [ -e {{ $tmp_dir }}/service_owner ]; then
service_owner=`cat {{ $tmp_dir }}/service_owner`;
else
service_owner="{{ $settings['service_owner_default'] }}";
fi
[ -f {{ $app_base }}/.env.{{ $env }} ] && rm -rf {{ $app_base }}/.env;
[ -f {{ $app_base }}/.env.{{ $env }} ] && ln -nfs {{ $app_base }}/.env.{{ $env }} {{ $app_base }}/.env;
[ -f {{ $app_base }}/.env.{{ $env }} ] && chgrp -h ${service_owner} {{ $app_base }}/.env;
[ -f {{ $app_base }}/envoy.config.{{ $env }}.php ] && rm -rf {{ $app_base }}/envoy.config.php;
[ -f {{ $app_base }}/envoy.config.{{ $env }}.php ] && ln -nfs {{ $app_base }}/envoy.config.{{ $env }}.php {{ $app_base }}/envoy.config.php;
[ -f {{ $app_base }}/envoy.config.{{ $env }}.php ] && chgrp -h ${service_owner} {{ $app_base }}/envoy.config.php;
echo "link env on remote Done.";
@endtask
@task('updaterepo_workingcopy',['on' => 'local'])
echo "Workingcopy Repository update...";
cd {{ $local_dir }};
git fetch origin;
git pull;
echo "Workingcopy Repository updated.";
@endtask
@task('depsinstall_workingcopy',['on' => 'local'])
echo "Workingcopy Dependencies install...";
cd {{ $local_dir }};
if [ {{ intval($settings['deps_install_component']['composer']) }} -eq 1 ]; then
echo "Composer install...";
{{ $settings['deps_install_command']['composer'] }};
{{--php artisan clear-compiled --env={{ $env }};--}}
{{--php artisan optimize --env={{ $env }};--}}
echo "Composer installed.";
fi
if [ {{ intval($settings['deps_install_component']['npm']) }} -eq 1 ]; then
echo "NPM install...";
{{ $settings['deps_install_command']['npm'] }};
echo "NPM installed.";
fi
if [ {{ intval($settings['deps_install_component']['bower']) }} -eq 1 ]; then
echo "Bower install...";
{{ $settings['deps_install_command']['bower'] }};
echo "Bower installed.";
fi
if [ {{ intval($settings['deps_install_component']['gulp']) }} -eq 1 ]; then
echo "gulp build...";
{{ $settings['deps_install_command']['gulp'] }};
echo "gulp built.";
fi
echo "Workingcopy Dependencies installed.";
@endtask
@task('updaterepo_localsrc',['on' => 'local'])
echo "LocalSource Repository update...";
if [ -d {{ $localdeploy_source_dir }} ]; then
echo "Repository exits only update...";
cd {{ $localdeploy_source_dir }};
git fetch origin;
git checkout -B {{ $branch }} origin/{{ $branch }};
git pull origin {{ $branch }};
else
echo "No Previous Repository exits and cloning...";
git clone {{ $source_repo }} --branch={{ $branch }} --depth=1 {{ $localdeploy_source_dir }};
fi
echo "LocalSource Repository updated.";
@endtask
@task('envsetup_localsrc',['on' => 'local'])
echo "LocalSource Repository Environment file setup";
[ -f {{ $local_dir }}/.env.{{ $env }} ] && cp -RLpf {{ $local_dir }}/.env.{{ $env }} {{ $localdeploy_source_dir }}/.env;
[ -f {{ $localdeploy_source_dir }}/.env.{{ $env }} ] && cp -RLpf {{ $localdeploy_source_dir }}/.env.{{ $env }} {{ $localdeploy_source_dir }}//.env;
echo "LocalSource Repository Environment file setup done";
@endtask
@task('depsinstall_localsrc',['on' => 'local'])
echo "LocalSource Dependencies install...";
cd {{ $localdeploy_source_dir }};
if [ {{ intval($settings['deps_install_component']['composer']) }} -eq 1 ]; then
echo "Composer install...";
{{ $settings['deps_install_command']['composer'] }};
echo "Composer installed.";
fi
if [ {{ intval($settings['deps_install_component']['npm']) }} -eq 1 ]; then
echo "NPM install...";
{{ $settings['deps_install_command']['npm'] }};
echo "NPM installed.";
fi
if [ {{ intval($settings['deps_install_component']['bower']) }} -eq 1 ]; then
echo "Bower install...";
{{ $settings['deps_install_command']['bower'] }};
echo "Bower installed.";
fi
if [ {{ intval($settings['deps_install_component']['gulp']) }} -eq 1 ]; then
echo "gulp build...";
{{ $settings['deps_install_command']['gulp'] }};
echo "gulp built.";
fi
echo "LocalSource Dependencies installed.";
@endtask
@task('extracustomoverwrite_localsrc',['on' => 'local'])
if [ {{ intval($settings['extracustomoverwrite_enable']) }} -eq 1 ]; then
echo "LocalSource Extra custom files overwriting...";
cd {{ $localdeploy_source_dir }};
if [ -d {{ $localdeploy_source_dir }}/extra/custom ]; then
cp -af {{ $localdeploy_source_dir }}/extra/custom/* {{ $localdeploy_source_dir }}/;
fi
echo "LocalSource Extra custom files overwrote.";
fi
@endtask
@task('runtimeoptimize_localsrc',['on' => 'local'])
echo "LocalSource Runtime optimize...";
cd {{ $localdeploy_source_dir }};
if [ {{ intval($settings['runtime_optimize_component']['composer']) }} -eq 1 ]; then
echo "Composer optimize...";
{{ $settings['runtime_optimize_command']['composer'] }};
echo "Composer optimized.";
fi
if [ {{ intval($settings['runtime_optimize_component']['artisan']['optimize']) }} -eq 1 ]; then
echo "artisan optimize...";
{{ $settings['runtime_optimize_command']['artisan']['optimize'] }};
echo "artisan optimized.";
fi
if [ {{ intval($settings['runtime_optimize_component']['artisan']['config_cache']) }} -eq 1 ]; then
echo "artisan config:cache...";
{{ $settings['runtime_optimize_command']['artisan']['config_cache'] }};
echo "artisan config:cache done.";
fi
if [ {{ intval($settings['runtime_optimize_component']['artisan']['route_cache']) }} -eq 1 ]; then
echo "artisan route:cache...";
{{ $settings['runtime_optimize_command']['artisan']['route_cache'] }};
echo "artisan route:cache done.";
fi
echo "LocalSource Runtime optimized.";
@endtask
@task('packrelease_localsrc',['on' => 'local'])
echo "LocalSource Pack release...";
[ -f {{ $localdeploy_tmp_dir }}/release.tgz ] && rm -rf {{ $localdeploy_tmp_dir }}/release.tgz;
cd {{ $localdeploy_base }}/;
tar {{ $tarExcludePatternContext }} -czf {{ $localdeploy_tmp_dir }}/release.tgz {{ $source_name }};
echo "LocalSource Pack release Done.";
@endtask
@task('rcpreleasepack_to_remote',['on' => 'local'])
echo "rcp localpack release to remote...";
if [ -f {{ $localdeploy_tmp_dir }}/release.tgz ]; then
server_userathosts="{{ implode(' ',$server_userathosts) }}";
server_ports="{{ implode(' ',$server_ports) }}";
index_count=0;
for item in $server_userathosts;do
eval server_userathosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_ports;do
eval server_ports_${index_count}=$item;
index_count=$((index_count+1));
done
index_length=$((index_count-1));
for step_index in $(seq 0 $index_length)
do
eval step_userathosts=\$server_userathosts_${step_index};
eval step_ports=\$server_ports_${step_index};
echo "execute for server: ${step_userathosts} ${step_ports}";
rsync -avz --progress --port ${step_ports} {{ $localdeploy_tmp_dir }}/release.tgz ${step_userathosts}:{{ $tmp_dir }}/;
done
else
echo "localpack release NOT EXISTS.";
echo "Pass [Ctrl-c] to quit.";
while true; do sleep 100;done;
exit 1;
fi
echo "rcp localpack release to remote Done.";
@endtask
@task('rcpbuildreleasepack_to_remote',['on' => 'local'])
echo "rcp localpack build release to remote...";
if [ -f {{ $localdeploy_source_dir }}/{{ $app_name }}.phar ]; then
server_userathosts="{{ implode(' ',$server_userathosts) }}";
server_ports="{{ implode(' ',$server_ports) }}";
index_count=0;
for item in $server_userathosts;do
eval server_userathosts_${index_count}=$item;
index_count=$((index_count+1));
done
index_count=0;
for item in $server_ports;do
eval server_ports_${index_count}=$item;
index_count=$((index_count+1));
done
index_length=$((index_count-1));
for step_index in $(seq 0 $index_length)
do
eval step_userathosts=\$server_userathosts_${step_index};
eval step_ports=\$server_ports_${step_index};
echo "execute for server: ${step_userathosts} ${step_ports}";
rsync -avz --progress --port ${step_ports} {{ $localdeploy_source_dir }}/{{ $app_name }}.phar ${step_userathosts}:{{ $tmp_dir }}/;
done
else
echo "localpack build release NOT EXISTS.";
echo "Pass [Ctrl-c] to quit.";
while true; do sleep 100;done;
exit 1;
fi
echo "rcp localpack build release to remote Done.";
@endtask
@task('extractreleasepack_on_remote',['on' => $server_labels, 'parallel' => true])
echo "extract pack release on remote...";
if [ -f {{ $tmp_dir }}/release.tgz ]; then
[ -d {{ $tmp_dir }}/{{ $source_name }} ] && rm -rf {{ $tmp_dir }}/{{ $source_name }};
tar zxf {{ $tmp_dir }}/release.tgz -C {{ $tmp_dir }};
if [ -d {{ $tmp_dir }}/{{ $source_name }} ]; then
if [ -d {{ $source_dir }} ]; then
echo "Previous Remote Source Dir Exists,Moving.";
[ -d {{ $app_base }}/source_prev ] && rm -rf {{ $app_base }}/source_prev;
mv {{ $source_dir }} {{ $app_base }}/source_prev;
mv {{ $tmp_dir }}/{{ $source_name }} {{ $source_dir }};
else
mv {{ $tmp_dir }}/{{ $source_name }} {{ $source_dir }};
fi
else
echo "extract pack release on remote ERROR.";
echo "Pass [Ctrl-c] to quit.";
while true; do sleep 100;done;
exit 1;
fi
else
echo "pack release NOT EXISTS.";
echo "Pass [Ctrl-c] to quit.";
while true; do sleep 100;done;
exit 1;
fi
echo "extract pack release on remote Done.";
@endtask
@task('extractbuildreleasepack_on_remote',['on' => $server_labels, 'parallel' => true])
echo "extract pack build release on remote...";
if [ -f {{ $tmp_dir }}/{{ $app_name }}.phar ]; then
[ -f {{ $source_dir }}/{{ $app_name }}.phar ] && rm -rf {{ $source_dir }}/{{ $app_name }}.phar;
mv {{ $tmp_dir }}/{{ $app_name }}.phar {{ $tmp_dir }}/{{ $app_name }}.phar;
else
echo "pack build release NOT EXISTS.";
echo "Pass [Ctrl-c] to quit.";
while true; do sleep 100;done;
exit 1;
fi
echo "extract pack build release on remote Done.";
@endtask
@task('boxbuild_workingcopy',['on' => 'local'])
echo "Workingcopy Box Build...";
cd {{ $local_dir }};
[ -f {{ $local_dir }}/{{ $app_name }}.phar ] && rm -rf {{ $local_dir }}/{{ $app_name }}.phar;
$HOME/.composer/vendor/bin/box build -vvv -c {{ $local_dir }}/box.json;
echo "Workingcopy Box Build Done.";
@endtask
@task('boxbuild_localsrc',['on' => 'local'])
echo "LocalSource Box Build...";
cd {{ $localdeploy_source_dir }};
[ -f {{ $localdeploy_source_dir }}/{{ $app_name }}.phar ] && rm -rf {{ $localdeploy_source_dir }}/{{ $app_name }}.phar;
$HOME/.composer/vendor/bin/box build -vvv -c {{ $localdeploy_source_dir }}/box.json;
echo "LocalSource Box Build Done.";
@endtask
@task('boxbuild_remotesrc',['on' => $server_labels, 'parallel' => true])
echo "RemoteSource Box Build...";
if [ -e {{ $tmp_dir }}/service_owner ]; then
service_owner=`cat {{ $tmp_dir }}/service_owner`;
else
service_owner="{{ $settings['service_owner_default'] }}";
fi
cd {{ $source_dir }};
[ -f {{ $source_dir }}/{{ $app_name }}.phar ] && rm -rf {{ $source_dir }}/{{ $app_name }}.phar;
$HOME/.composer/vendor/bin/box build -vvv -c {{ $source_dir }}/box.json;
echo "RemoteSource Box Build Done.";
@endtask
@task('updaterepo_remotesrc',['on' => $server_labels, 'parallel' => true])
echo "RemoteSource Repository update...";
if [ -d {{ $source_dir }} ]; then
echo "Repository exits only update...";
cd {{ $source_dir }};
git fetch origin;
git checkout -B {{ $branch }} origin/{{ $branch }};
git pull origin {{ $branch }};
else
echo "No Previous Repository exits and cloning...";
git clone {{ $source_repo }} --branch={{ $branch }} --depth=1 {{ $source_dir }};
fi
echo "RemoteSource Repository updated.";
@endtask
@task('envsetup_remotesrc',['on' => $server_labels, 'parallel' => true])
echo "RemoteSource Repository Environment file setup";
[ -f {{ $source_dir }}/.env.{{ $env }} ] && cp -RLpf {{ $source_dir }}/.env.{{ $env }} {{ $source_dir }}/.env;
[ -f {{ $app_base }}/.env.{{ $env }} ] && cp -RLpf {{ $app_base }}/.env.{{ $env }} {{ $source_dir }}//.env;
echo "RemoteSource Repository Environment file setup done";
@endtask
@task('depsinstall_remotesrc',['on' => $server_labels, 'parallel' => true])
echo "RemoteSource Dependencies install...";
cd {{ $source_dir }};
if [ {{ intval($settings['deps_install_component']['composer']) }} -eq 1 ]; then
echo "Composer install...";
{{ $settings['deps_install_command']['composer'] }};
echo "Composer installed.";
fi
if [ {{ intval($settings['deps_install_component']['npm']) }} -eq 1 ]; then
echo "NPM install...";
{{ $settings['deps_install_command']['npm'] }};
echo "NPM installed.";
fi
if [ {{ intval($settings['deps_install_component']['bower']) }} -eq 1 ]; then
echo "Bower install...";
{{ $settings['deps_install_command']['bower'] }};
echo "Bower installed.";
fi
if [ {{ intval($settings['deps_install_component']['gulp']) }} -eq 1 ]; then
echo "gulp build...";
{{ $settings['deps_install_command']['gulp'] }};
echo "gulp built.";
fi
echo "RemoteSource Dependencies installed.";
@endtask
@task('extracustomoverwrite_remotesrc',['on' => $server_labels, 'parallel' => true])
if [ {{ intval($settings['extracustomoverwrite_enable']) }} -eq 1 ]; then
echo "RemoteSource Extra custom files overwriting...";
cd {{ $source_dir }};
if [ -d {{ $source_dir }}/extra/custom ]; then
cp -af {{ $source_dir }}/extra/custom/* {{ $source_dir }}/;
fi
echo "RemoteSource Extra custom files overwrote.";
fi
@endtask
@task('runtimeoptimize_remotesrc',['on' => $server_labels, 'parallel' => true])
echo "RemoteSource Runtime optimize...";
cd {{ $source_dir }};
if [ {{ intval($settings['runtime_optimize_component']['composer']) }} -eq 1 ]; then
echo "Composer optimize...";
{{ $settings['runtime_optimize_command']['composer'] }};
echo "Composer optimized.";
fi
if [ {{ intval($settings['runtime_optimize_component']['artisan']['optimize']) }} -eq 1 ]; then
echo "artisan optimize...";
{{ $settings['runtime_optimize_command']['artisan']['optimize'] }};
echo "artisan optimized.";