-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
119 lines (95 loc) · 3.41 KB
/
deploy.php
File metadata and controls
119 lines (95 loc) · 3.41 KB
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
<?php
namespace Deployer;
use Deployer\Exception\Exception;
use function Deployer\Support\str_contains;
require 'recipe/common.php';
set('application', 'fusebox:app');
set('repository', 'git@github.com:titomiguelcosta/fusebox.git');
set('git_tty', false);
set('keep_releases', 3);
set('shared_dirs', []);
set('writable_dirs', ['']);
set('writable_mode', 'acl');
host('fusebox.titomiguelcosta.com')
->user('ubuntu')
->stage('dev')
->set('deploy_path', '/mnt/websites/fusebox')
->set('shared_files', ['.env', 'web/.env'])
->set('branch', 'master')
->set('env', ['PATH' => '/home/ubuntu/.pyenv/plugins/pyenv-virtualenv/shims:/home/ubuntu/.pyenv/shims:/home/ubuntu/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin']);
task('workers:restart', function () {
run('sudo supervisorctl reload');
});
task('database:migrate', function () {
run('python {{release_path}}/fusebox/manage.py migrate --noinput');
});
task('publish:assets', function () {
run('python {{release_path}}/fusebox/manage.py collectstatic --noinput');
});
task('update:dependencies', function () {
run('pip install -r {{release_path}}/requirements.txt');
});
task('frontend:build', function () {
run('cd {{release_path}}/web && yarn install', ['timeout' => null]);
run('cd {{release_path}}/web && yarn build', ['timeout' => null]);
});
desc('Deploy project');
task('deploy', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'update:dependencies',
'deploy:shared',
'deploy:writable',
'database:migrate',
'publish:assets',
'frontend:build',
'deploy:symlink',
'workers:restart',
'deploy:unlock',
'deploy:cleanup',
'success',
]);
after('deploy:failed', 'deploy:unlock');
desc('Preparing host for deploy');
task('deploy:setup', function () {
// Check if shell is POSIX-compliant
$result = run('echo $0');
if (!str_contains($result, 'bash') && !str_contains($result, 'sh')) {
throw new \RuntimeException(
'Shell on your server is not POSIX-compliant. Please change to sh, bash or similar.'
);
}
run('if [ ! -d {{deploy_path}} ]; then mkdir -p {{deploy_path}}; fi');
// Check for existing /current directory (not symlink)
$result = test('[ ! -L {{deploy_path}}/current ] && [ -d {{deploy_path}}/current ]');
if ($result) {
throw new Exception('There already is a directory (not symlink) named "current" in ' . get('deploy_path') . '. Remove this directory so it can be replaced with a symlink for atomic deployments.');
}
// Create metadata .dep dir.
run("cd {{deploy_path}} && if [ ! -d .dep ]; then mkdir .dep; fi");
// Create releases dir.
run("cd {{deploy_path}} && if [ ! -d releases ]; then mkdir releases; fi");
// Create shared dir.
run("cd {{deploy_path}} && if [ ! -d shared ]; then mkdir shared; fi");
});
desc('Cleaning up old releases');
task('deploy:cleanup', function () {
$releases = get('releases_list');
$keep = get('keep_releases');
$runOpts = [];
if ($keep === -1) {
// Keep unlimited releases.
return;
}
while ($keep > 0) {
array_shift($releases);
--$keep;
}
foreach ($releases as $release) {
run("rm -rf {{deploy_path}}/releases/$release", $runOpts);
}
run("cd {{deploy_path}} && if [ -e release ]; then rm release; fi", $runOpts);
});