This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployer
executable file
·185 lines (177 loc) · 5.7 KB
/
deployer
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
<?php
namespace Deployer;
require 'recipe/common.php';
set('repository', 'git@git.rep.elt:Phalcon/landing.git');
host('php.elt')
->user('default')
->port(22)
->identityFile('~/.ssh/id_rsa')
->set('deploy_path', '/www/htdocs/team2');
// Laravel shared dirs
set('shared_dirs', [
'storage',
]);
// Laravel shared file
set('shared_files', [
'.env',
]);
set('branch', 'master');
set('tag', function () {
$cmd = 'git ls-remote --tags --refs {{repository}}';
// $output = runLocally($cmd);
$output = run($cmd);
$tags = preg_split('#$#m', $output);
$tags = array_map(
function ($x) {
$tt = explode('/', $x);
return $tt[count($tt) - 1];
},
$tags);
natsort($tags);
$tags = array_values($tags);
return count($tags) ? $tags[count($tags) - 1] : null;
});
// Laravel writable dirs
set('writable_dirs', [
'bootstrap/cache',
'storage',
'storage/app',
'storage/app/public',
'storage/framework',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
]);
set('laravel_version', function () {
$result = run('{{bin/php}} {{release_path}}/artisan --version');
preg_match_all('/(\d+\.?)+/', $result, $matches);
$version = $matches[0][0] ?? 5.6;
return $version;
});
/**
* Helper tasks
*/
desc('Disable maintenance mode');
task('artisan:up', function () {
$output = run('if [ -f {{deploy_path}}/current/artisan ]; then {{bin/php}} {{deploy_path}}/current/artisan up; fi');
writeln('<info>' . $output . '</info>');
});
desc('Enable maintenance mode');
task('artisan:down', function () {
$output = run('if [ -f {{deploy_path}}/current/artisan ]; then {{bin/php}} {{deploy_path}}/current/artisan down; fi');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan migrate');
task('artisan:migrate', function () {
run('{{bin/php}} {{release_path}}/artisan migrate --force');
});
desc('Execute artisan migrate:fresh');
task('artisan:migrate:fresh', function () {
run('{{bin/php}} {{release_path}}/artisan migrate:fresh --force');
});
desc('Execute artisan migrate:rollback');
task('artisan:migrate:rollback', function () {
$output = run('{{bin/php}} {{release_path}}/artisan migrate:rollback --force');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan migrate:status');
task('artisan:migrate:status', function () {
$output = run('{{bin/php}} {{release_path}}/artisan migrate:status');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan db:seed');
task('artisan:db:seed', function () {
$output = run('{{bin/php}} {{release_path}}/artisan db:seed --force');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan cache:clear');
task('artisan:cache:clear', function () {
run('{{bin/php}} {{release_path}}/artisan cache:clear');
});
desc('Execute artisan config:cache');
task('artisan:config:cache', function () {
run('{{bin/php}} {{release_path}}/artisan config:cache');
});
desc('Execute artisan route:cache');
task('artisan:route:cache', function () {
run('{{bin/php}} {{release_path}}/artisan route:cache');
});
desc('Execute artisan view:clear');
task('artisan:view:clear', function () {
run('{{bin/php}} {{release_path}}/artisan view:clear');
});
desc('Execute artisan optimize');
task('artisan:optimize', function () {
$deprecatedVersion = 5.6;
$currentVersion = get('laravel_version');
if (version_compare($currentVersion, $deprecatedVersion, '<')) {
run('{{bin/php}} {{release_path}}/artisan optimize');
}
});
desc('Execute artisan queue:restart');
task('artisan:queue:restart', function () {
run('{{bin/php}} {{release_path}}/artisan queue:restart');
});
desc('Execute artisan storage:link');
task('artisan:storage:link', function () {
$needsVersion = 5.5;
$currentVersion = get('laravel_version');
if (version_compare($currentVersion, $needsVersion, '>=')) {
run('{{bin/php}} {{release_path}}/artisan storage:link');
}
});
task('deploy:update_code', function () {
$tag = get('tag');
if (empty($tag)) {
throw new \Exception("No release tag specified to deploy!");
}
writeln("About to get sources from tags/{{tag}}");
run("git clone --depth 1 --branch {{branch}} {{repository}} {{release_path}}");
run("cd {{release_path}} && git fetch --tags && git checkout tags/{{tag}}");
})->desc('Updating code from git repository');
task('status', function () {
writeln("latest release tag: {{tag}}");
})->desc('Show status of custom deploy features');
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
/**
* Task deploy:public_disk support the public disk.
* To run this task automatically, please add below line to your deploy.php file
*
* before('deploy:symlink', 'deploy:public_disk');
*
* @see https://laravel.com/docs/5.2/filesystem#configuration
*/
desc('Make symlink for public disk');
task('deploy:public_disk', function () {
// Remove from source.
run('if [ -d $(echo {{release_path}}/public/storage) ]; then rm -rf {{release_path}}/public/storage; fi');
// Create shared dir if it does not exist.
run('mkdir -p {{deploy_path}}/shared/storage/app/public');
// Symlink shared dir to release dir
run('{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage');
});
/**
* Main task
*/
desc('Deploy your project');
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:vendors',
'deploy:writable',
'artisan:storage:link',
'artisan:view:clear',
'artisan:cache:clear',
'artisan:config:cache',
'artisan:optimize',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
after('deploy', 'success');