-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
107 lines (82 loc) · 2.66 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
102
103
104
105
106
107
<?php
namespace Deployer;
require 'recipe/common.php';
set('application', 'phala-stats');
set('repository', '[email protected]:l00k/phala-tools-ui.git');
set('git_tty', true);
set('allow_anonymous_stats', false);
set('assets_path', '/');
set('clear_paths', [
'patches',
'public',
'src',
]);
set('shared_files:copy', [
'src/etc/local/config.ts',
]);
set('copy_dirs', [
'node_modules',
]);
host('phala')
->hostname('ovh-server')
->user('ubuntu')
->set('app_variant', 'phala')
->set('deploy_path', '/var/www/phala-100k-dev');
host('khala')
->hostname('ovh-server')
->user('ubuntu')
->set('app_variant', 'khala')
->set('deploy_path', '/var/www/khala-100k-dev');
desc('Deploy your project');
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'custom:asset_build',
'custom:file_upload',
'deploy:shared',
'deploy:writable',
'deploy:clear_paths',
'deploy:symlink',
'deploy:unlock',
'cleanup',
'success',
]);
after('deploy:failed', 'deploy:unlock');
task('custom:asset_build', function () {
if (!empty(get('assets_path', false))) {
$assetsPath = trim(get('assets_path'), '/\\');
runLocally('cd ./' . $assetsPath . ' && APP_VARIANT={{app_variant}} yarn build');
}
});
task('custom:file_upload', function () {
$random = uniqid();
$compressedFilename = "package-$random.tar.gz";
$cmd = 'cd ./dist && tar -zcf ../' . $compressedFilename . ' .';
runLocally($cmd);
$releaseDir = test('[ -L {{deploy_path}}/release ]')
? 'release'
: 'current';
$distPath = get('deploy_path') . '/' . $releaseDir;
upload('./' . $compressedFilename, $distPath);
runLocally('rm ' . $compressedFilename);
run('cd ' . $distPath . ' && tar -xf ' . $compressedFilename);
run('cd ' . $distPath . ' && rm -f ' . $compressedFilename);
});
task('deploy:shared:copy', function () {
$sharedPath = "{{deploy_path}}/shared";
foreach (get('shared_files:copy') as $file) {
$dirname = dirname(parse($file));
if (!test("[ -d {$sharedPath}/{$dirname} ]")) {
run("mkdir -p {$sharedPath}/{$dirname}");
}
if (!test("[ -f $sharedPath/$file ]") && test("[ -f {{release_path}}/$file ]")) {
run("cp -rv {{release_path}}/$file $sharedPath/$file");
}
run("if [ -f $(echo {{release_path}}/$file) ]; then rm -rf {{release_path}}/$file; fi");
run("if [ ! -d $(echo {{release_path}}/$dirname) ]; then mkdir -p {{release_path}}/$dirname;fi");
run("touch $sharedPath/$file");
run("cp -r $sharedPath/$file {{release_path}}/$file");
}
});