This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
114 lines (87 loc) · 2.45 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
<?php
declare(strict_types=1);
namespace Deployer;
use Symfony\Component\Dotenv\Dotenv;
require 'recipe/symfony4.php';
// Project name
set('application', 'My Application');
// Project repository
set('repository', '[email protected]:thomasage/atintranet.git');
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
// Shared files/dirs between deploys
set('shared_files', ['.env.local']);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);
set('allow_anonymous_stats', false);
// Hosts
inventory(__DIR__.'/deploy/hosts.yaml');
// Tasks
desc('Execute tests');
task(
'deploy:tests',
function () {
runLocally('vendor/bin/simple-phpunit');
}
);
desc('Setup env variables');
task(
'deploy:env:setup',
function () {
$dotenv = new Dotenv();
// Remote env vars
run('if [ ! -f shared/.env.local ] ; then touch shared/.env.local ; fi');
$remoteEnvs = run('cat shared/.env.local');
$remoteEnvs = $dotenv->parse($remoteEnvs);
// Local env vars
$localEnvs = $dotenv->parse(file_get_contents(__DIR__.'/.env'));
// Populate missing env vars
foreach ($localEnvs as $key => $val) {
if (isset($remoteEnvs[$key])) {
continue;
}
$val = ask($key, $val);
if (false !== strpos($val, ' ')) {
$val = sprintf('"%s"', $val);
}
run(sprintf('echo "%s=%s" >> shared/.env.local', $key, str_replace('"', '\"', $val)));
}
}
);
desc('Compile assets');
task(
'deploy:assets',
function () {
runLocally('yarn run encore prod');
upload('public/build', '{{release_path}}/public');
}
);
desc('Deploy project');
task(
'deploy',
[
'deploy:tests',
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:env:setup',
'deploy:vendors',
'deploy:assets',
'deploy:writable',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]
);
// [Optional] Specific to OVH
set('bin/php', '/usr/local/php7.3/bin/php');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
before('deploy:symlink', 'database:migrate');