-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
126 lines (103 loc) · 3.41 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Deployer;
use App\Deploy\AsyncProcess;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
require 'recipe/common.php';
function cdToReleasePath(): void
{
cd('{{release_path}}');
}
function toLinuxPath(string $path): string
{
return str_replace('\\', '/', $path);
}
inventory('config/prod/hosts.yaml');
set('composer_options', '{{composer_action}} --no-scripts');
set('ssh_multiplexing', false);
set('symfony/console', '{{bin/php}} {{release_path}}/bin/console');
const LOGS_DIR = 'var/log';
const CACHE_DIR = 'var/cache';
set('shared_dirs', [LOGS_DIR]);
set('shared_files', [
'.env',
'.env.local',
'.env.test',
'.env.test.local',
]);
set('clear_paths', ['.env.local.php']);
set('env', [
//'COMPOSER_MEMORY_LIMIT' => -1,
]);
set('build_assets_path', 'public/build');
after('deploy:failed', 'deploy:unlock');
task('deploy:create-manifest', function (): void {
cdToReleasePath();
run('mkdir {{build_assets_path}} -p');
run('echo "{}" > {{build_assets_path}}/manifest.json');
});
task('deploy:test', function (): void {
cdToReleasePath();
run('{{symfony/console}} doctrine:migrations:migrate -n -e test');
run('{{symfony/console}} doctrine:schema:validate -e test');
run('{{symfony/console}} doctrine:fixtures:load -n -e test');
run('{{bin/php}} vendor/bin/phpunit');
});
task('deploy:migrate', function (): void {
cdToReleasePath();
run('{{symfony/console}} doctrine:migrations:migrate -n');
run('{{symfony/console}} doctrine:schema:validate');
});
after('deploy:vendors', 'deploy:post-install');
task('deploy:post-install', function (): void {
cd('{{release_path}}');
run('{{bin/composer}} run-script auto-scripts');
});
task('deploy:build', function (): void {
cd('{{release_path}}');
run('{{bin/composer}} dump-env prod');
run('{{bin/composer}} dump-autoload --optimize --no-dev --classmap-authoritative');
});
/** @var AsyncProcess $buildAssetsCommand */
$buildAssetsCommand = null;
task('deploy:build-assets', function () use (&$buildAssetsCommand): void {
$buildAssetsCommand = new AsyncProcess('npm run build');
});
task('deploy:upload-assets', function () use (&$buildAssetsCommand): void {
$buildAssetsCommand->wait();
$finder = Finder::create()
->files()
->in(sprintf('%s/%s', __DIR__, get('build_assets_path')));
/** @var SplFileInfo $file */
foreach ($finder as $file) {
set('asset_directory_path', toLinuxPath($file->getRelativePath()));
set('asset_path', toLinuxPath($file->getRelativePathname()));
run('mkdir {{release_path}}/{{build_assets_path}}/{{asset_directory_path}} -p');
runLocally('scp -P {{port}} {{build_assets_path}}/{{asset_path}} {{user}}@{{hostname}}:{{release_path}}/{{build_assets_path}}/{{asset_path}}');
}
});
desc('Deploy your project');
task('deploy', function (): void {
after('deploy:info', 'deploy:build-assets');
after('deploy:create-manifest', 'deploy:test');
before('deploy:symlink', 'deploy:upload-assets');
invoke('quik-deploy');
});
task('quik-deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'deploy:create-manifest',
'deploy:clear_paths',
'deploy:migrate',
'deploy:build',
'deploy:symlink',
'deploy:unlock',
'cleanup',
'success',
]);