-
Notifications
You must be signed in to change notification settings - Fork 65
/
Envoy.blade.php
171 lines (136 loc) · 4.87 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
#--------------------------------------------------------------------------
# List of tasks, that you can run...
# e.g. envoy run hello
#--------------------------------------------------------------------------
#
# hello Check ssh connection
# release Publish new release
# list Show list of releases
# checkout Checkout to the given release (must provide --release=/path/to/release)
# prune Purge old releases (must provide --keep=n, where n is a number)
#
@servers(['web' => 'aws-seoul-deploy'])
@setup
$path = [
'base' => '/home/deployer/www',
'docroot' => '/home/deployer/www/l5.appkr.kr',
'shared' => '/home/deployer/www/shared',
'release' => '/home/deployer/www/releases',
];
$required_dirs = [
$path['base'],
$path['shared'],
$path['release'],
];
$shared_item = [
'/home/deployer/www/shared/.env' => '.env',
'/home/deployer/www/shared/storage' => 'storage',
'/home/deployer/www/shared/cache' => 'bootstrap/cache',
'/home/deployer/www/shared/attachments' => 'public/attachments',
];
$distribution = [
'name' => 'release_' . date('YmdHis'),
];
$git = [
'repo' => 'git@github.com:appkr/l5essential.git',
];
@endsetup
@task('hello', ['on' => ['web']])
HOSTNAME=$(hostname);
echo "Hello Envoy! Responding from $HOSTNAME";
@endtask
@task('release', ['on' => ['web']])
{{--Create directories if not exists--}}
@foreach ($required_dirs as $dir)
if [ ! -d {{ $dir }} ]; then
mkdir {{ $dir }};
chgrp -h -R www-data {{ $dir }};
fi;
@endforeach
{{--Download book keeping officer--}}
if [ ! -f {{ $path['base'] }}/officer.php ]; then
wget https://raw.githubusercontent.com/appkr/envoy/master/scripts/officer.php -O {{ $path['base'] }}/officer.php;
fi;
{{--Fetch code from git--}}
cd {{ $path['release'] }};
git clone -b master {{ $git['repo'] }} {{ $distribution['name'] }};
{{--Symlink shared directory to current release.--}}
{{--e.g. storage, .env, user uploaded file storage, ...--}}
cd {{ $path['release'] }}/{{ $distribution['name'] }};
@foreach($shared_item as $global => $local)
[ -f {{ $local }} ] && rm {{ $local }};
[ -d {{ $local }} ] && rm -rf {{ $local }};
ln -nfs {{ $global }} {{ $local }};
chgrp -h -R www-data {{ $local }};
@endforeach
{{--Run composer install--}}
composer install --prefer-dist --no-scripts;
php artisan clear-compiled;
php artisan optimize;
php artisan cache:clear;
php artisan my:update-lesson;
{{--Symlink current release to service directory.--}}
ln -nfs {{ $path['release'] }}/{{ $distribution['name'] }} {{ $path['docroot'] }};
chgrp -h -R www-data {{ $path['docroot'] }};
{{--Set permission and change owner. Do one final more for safety.--}}
chgrp -h -R www-data {{ $path['release'] }}/{{ $distribution['name'] }};
{{--Book keeping--}}
php {{ $path['base'] }}/officer.php deploy {{ $path['release'] }}/{{ $distribution['name'] }};
{{--Restart web server.--}}
sudo service nginx restart;
sudo service php5-fpm restart;
@endtask
@task('prune', ['on' => 'web'])
if [ ! -f {{ $path['base'] }}/officer.php ]; then
echo '"officer.php" script not found.';
echo '\$ envoy run hire_officer';
exit 1;
fi;
@if (isset($keep) and $keep > 0)
php {{ $path['base'] }}/officer.php prune {{ $keep }};
@else
echo 'Must provide --keep=n, where n is a number.';
@endif
@endtask
@task('hire_officer', ['on' => 'web'])
{{--Download "officer.php" to the server--}}
wget https://raw.githubusercontent.com/appkr/envoy/master/scripts/officer.php -O {{ $path['base'] }}/officer.php;
echo '"officer.php" is ready!';
@endtask
@task('list', ['on' => 'web'])
{{--Show the list of release--}}
if [ ! -f {{ $path['base'] }}/officer.php ]; then
echo '"officer.php" script not found.';
echo '\$ envoy run hire_officer';
exit 1;
fi;
php {{ $path['base'] }}/officer.php list;
@endtask
@task('checkout', ['on' => 'web'])
{{--Checkout to the given release path--}}
if [ ! -f {{ $path['base'] }}/officer.php ]; then
echo '"officer.php" script not found.';
echo '\$ envoy run hire_officer';
exit 1;
fi;
@if (isset($release))
cd {{ $release }};
{{--Symlink shared directory to the given release.--}}
@foreach($shared_item as $global => $local)
[ -f {{ $local }} ] && rm {{ $local }};
[ -d {{ $local }} ] && rm -rf {{ $local }};
ln -nfs {{ $global }} {{ $local }};
chgrp -h -R www-data {{ $local }};
@endforeach
{{--Symlink the given release to service directory.--}}
ln -nfs {{ $release }} {{ $path['docroot'] }};
chgrp -h -R www-data {{ $path['docroot'] }};
{{--Book keeping--}}
php {{ $path['base'] }}/officer.php checkout {{ $release }};
{{--Restart web server.--}}
sudo service nginx restart;
sudo service php5-fpm restart;
@else
echo 'Must provide --release=/full/path/to/release.';
@endif
@endtask