|
1
|
|
|
<?php |
|
2
|
|
|
namespace Deployer; |
|
3
|
|
|
|
|
4
|
|
|
require 'recipe/symfony.php'; |
|
5
|
|
|
|
|
6
|
|
|
require 'contrib/cachetool.php'; |
|
7
|
|
|
require 'contrib/webpack_encore.php'; |
|
8
|
|
|
|
|
9
|
|
|
// Project name |
|
10
|
|
|
set('application', 'omm.gothick.org.uk'); |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
// Project repository |
|
13
|
|
|
set('repository', '[email protected]:gothick/omm.git'); |
|
14
|
|
|
|
|
15
|
|
|
// [Optional] Allocate tty for git clone. Default value is false. |
|
16
|
|
|
set('git_tty', true); |
|
17
|
|
|
|
|
18
|
|
|
// The default of ten was a bit much. |
|
19
|
|
|
set('keep_releases', 5); |
|
20
|
|
|
|
|
21
|
|
|
// Cachetool needs to be a lower version than default, |
|
22
|
|
|
// as the latest only works with php 8. |
|
23
|
|
|
// https://github.com/deployphp/deployer/issues/2344 |
|
24
|
|
|
// https://gordalina.github.io/cachetool/ |
|
25
|
|
|
// https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L55 |
|
26
|
|
|
// https://github.com/gordalina/cachetool/releases/download/7.0.0/cachetool.phar |
|
27
|
|
|
set('bin/cachetool', function () { |
|
28
|
|
|
if (!test('[ -f {{release_or_current_path}}/cachetool.phar ]')) { |
|
|
|
|
|
|
29
|
|
|
run("cd {{release_or_current_path}} && curl -sLO https://github.com/gordalina/cachetool/releases/download/7.0.0/cachetool.phar"); |
|
30
|
|
|
} |
|
31
|
|
|
return '{{release_or_current_path}}/cachetool.phar'; |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
// Shared files/dirs between deploys |
|
36
|
|
|
add('shared_files', [ |
|
|
|
|
|
|
37
|
|
|
'google-cloud-service-account.json' |
|
38
|
|
|
]); |
|
39
|
|
|
add('shared_dirs', [ |
|
40
|
|
|
// 'var/cache', |
|
41
|
|
|
'public/uploads/gpx', |
|
42
|
|
|
'public/uploads/images', |
|
43
|
|
|
'public/uploads/incoming', |
|
44
|
|
|
'public/media', |
|
45
|
|
|
'php_external_tools_bin' |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
// Writable dirs by web server |
|
49
|
|
|
add('writable_dirs', []); |
|
50
|
|
|
|
|
51
|
|
|
// Hosts |
|
52
|
|
|
|
|
53
|
|
|
// TODO: Try to set the shell to bash, or see if updated versions of deployer |
|
54
|
|
|
// start working with zsh again. I'm on a beta at the moment because Symfony 5 |
|
55
|
|
|
host('ssh.gothick.org.uk') |
|
|
|
|
|
|
56
|
|
|
->set('labels', ['stage' => 'production']) |
|
57
|
|
|
->setRemoteUser('omm') |
|
58
|
|
|
->set('webpack_encore/env', 'production') |
|
59
|
|
|
->set('webpack_encore/package_manager', 'yarn') |
|
60
|
|
|
->set('cachetool_args', '--fcgi=/run/php/chef-managed-fpm-omm.sock --tmp-dir=/tmp') |
|
61
|
|
|
->set('console_options', '-vvv') |
|
62
|
|
|
->set('deploy_path', '/var/www/sites/gothick.org.uk/{{application}}'); |
|
63
|
|
|
|
|
64
|
|
|
host('omm.gothick.org.uk.localhost') |
|
65
|
|
|
->set('labels', ['stage' => 'staging']) |
|
66
|
|
|
->setRemoteUser('omm') |
|
67
|
|
|
->set('webpack_encore/env', 'production') |
|
68
|
|
|
->set('webpack_encore/package_manager', 'yarn') |
|
69
|
|
|
->set('cachetool_args', '--fcgi=/run/php/chef-managed-fpm-omm.sock --tmp-dir=/tmp') |
|
70
|
|
|
->set('console_options', '-vvv') |
|
71
|
|
|
->set('deploy_path', '/var/www/sites/gothick.org.uk/{{application}}'); |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
// Tasks |
|
75
|
|
|
|
|
76
|
|
|
task('build', function () { |
|
|
|
|
|
|
77
|
|
|
run('cd {{release_path}} && build'); |
|
78
|
|
|
}); |
|
79
|
|
|
|
|
80
|
|
|
task('deploy:stop-workers', function () { |
|
81
|
|
|
// Hack alert: https://stackoverflow.com/a/63652279/300836 |
|
82
|
|
|
// We've just move the previous release out of the way, but it's |
|
83
|
|
|
// the previous release's cache that has the details of the |
|
84
|
|
|
// workers we need to kill. |
|
85
|
|
|
if (has('previous_release')) { |
|
|
|
|
|
|
86
|
|
|
run('{{bin/php}} {{previous_release}}/bin/console messenger:stop-workers'); |
|
87
|
|
|
} |
|
88
|
|
|
})->desc('Stop any existing messenger consumers; Supervisor will restart them.'); |
|
89
|
|
|
|
|
90
|
|
|
// Testing |
|
91
|
|
|
task('pwd', function () { |
|
92
|
|
|
$result = run('pwd'); |
|
|
|
|
|
|
93
|
|
|
writeln("Current dir: $result"); |
|
|
|
|
|
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
task('test', function () { |
|
97
|
|
|
writeln('Hello world'); |
|
|
|
|
|
|
98
|
|
|
}); |
|
99
|
|
|
|
|
100
|
|
|
// [Optional] if deploy fails automatically unlock. |
|
101
|
|
|
after('deploy:failed', 'deploy:unlock'); |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
// Clear opcache on successful deployment |
|
104
|
|
|
after('deploy:symlink', 'cachetool:clear:opcache'); |
|
105
|
|
|
|
|
106
|
|
|
// Restart messenger consuers on successful deployment |
|
107
|
|
|
// I don't think this is currently working, but it's probably |
|
108
|
|
|
// because of this bug: |
|
109
|
|
|
// https://github.com/symfony/symfony/issues/40477 |
|
110
|
|
|
// So for now I'm probably going to have to manually restart |
|
111
|
|
|
// stuff with Supervisor :( |
|
112
|
|
|
after('cachetool:clear:opcache', 'deploy:stop-workers'); |
|
113
|
|
|
|
|
114
|
|
|
// Migrate database before symlink new release. |
|
115
|
|
|
|
|
116
|
|
|
before('deploy:symlink', 'database:migrate'); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
// Yarn and Webpack Encore. Note that Yarn has to install _after_ |
|
119
|
|
|
// Composer, as some of the Symfony JS stuff introduces a Yarn |
|
120
|
|
|
// dependency on a file in a Composer vendor directory. (it's for |
|
121
|
|
|
// Charts.js: |
|
122
|
|
|
// "@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", |
|
123
|
|
|
// ) |
|
124
|
|
|
after('deploy:vendors', 'yarn:install'); |
|
125
|
|
|
after('yarn:install', 'webpack_encore:build'); |
|
126
|
|
|
|