-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.php
101 lines (86 loc) · 2.69 KB
/
deploy.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
<?php
namespace Deployer;
require 'recipe/common.php';
// Project name
set('application', 'Magazine_Checker');
// Project repository
set('repository', 'git@github.com:yamanouehare/Magazine-Checker.git');
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
// Shared files/dirs between deploys
set('shared_files', [
'config/DBConfig.php',
'config/EnvConfig.php',
]);
set('shared_dirs', [
'vendor'
]);
//管理するリリース数
set('keep_releases', 5);
// httpサーバのユーザ:nginx
set('http_user','nginx');
// Hosts
host('magazine-checker')
->set('deploy_path', '/var/www/{{application}}');
/*-------------------------------
* 所有者変更タスク
-------------------------------*/
desc('chown_folder');
task('chown_folder', function () {
writeln("<comment>twig_cacheの所有者をnginxに変更</comment>");
$result = run('pwd');
writeln("初期パス: $result");
//htdocs配下に移動し所有者変更
$chown = 'chown -R nginx:nginx twig_cache';
run('cd ' . get('release_path') . '/tmp/'. ' && '. $chown);
writeln("変更完了");
writeln("<comment>php-fpmを再起動</comment>");
run('systemctl restart php72-php-fpm.service');
});
/*-------------------------------
* データフォルダ配下を転送するタスク
-------------------------------*/
desc('upload_file');
task('upload_file', function () {
writeln("<comment>db/data配下のファイルをアップロードします。</comment>");
$appFiles = [
'db/data',
];
$releasePath = get('release_path');
foreach ($appFiles as $file) {
upload("./{$file}", "{$releasePath}/db/");
}
})->desc('Upload static file');
/*-------------------------------
* マイグレーションタスク
-------------------------------*/
desc('migration');
task('migration', function () {
writeln("<comment>マイグレーションを実行します</comment>");
$execphp = 'php72 migrate.php';
$result = run('cd ' . get('release_path') . '/script/'. ' && '. $execphp);
writeln("結果: $result");
})->desc('exec migration');
//標準タスク
desc('Deploy your project');
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'deploy:clear_paths',
'deploy:symlink',
'upload_file', //アップロード
'migration', //マイグレーション
'deploy:unlock',
'cleanup',
'success'
]);
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
//デプロイ後に「chown_folder」実行
after('success', 'chown_folder');