Passed
Push — master ( 8d8b1d...10fd19 )
by Matt
08:27 queued 04:07
created

deploy.php (11 issues)

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');
0 ignored issues
show
The function set was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
/** @scrutinizer ignore-call */ 
11
set('application', 'omm.gothick.org.uk');
Loading history...
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 ]')) {
0 ignored issues
show
The function test was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
    if (!/** @scrutinizer ignore-call */ test('[ -f {{release_or_current_path}}/cachetool.phar ]')) {
Loading history...
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', [
0 ignored issues
show
The function add was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
/** @scrutinizer ignore-call */ 
37
add('shared_files', [
Loading history...
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('production')
0 ignored issues
show
The function host was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
/** @scrutinizer ignore-call */ 
56
host('production')
Loading history...
56
    ->setHostname('ssh.gothick.org.uk')
57
    ->set('labels', ['stage' => 'production'])
58
    ->setRemoteUser('omm')
59
    ->set('webpack_encore/env', 'production')
60
    ->set('webpack_encore/package_manager', 'yarn')
61
    ->set('cachetool_args', '--fcgi=/run/php/chef-managed-fpm-omm.sock --tmp-dir=/tmp')
62
    ->set('console_options', '-vvv')
63
    ->set('deploy_path', '/var/www/sites/gothick.org.uk/{{application}}');
64
65
host('staging')
66
    ->setHostname('omm.gothick.org.uk.localhost')
67
    ->set('labels', ['stage' => 'staging'])
68
    ->setRemoteUser('omm')
69
    ->set('webpack_encore/env', 'production')
70
    ->set('webpack_encore/package_manager', 'yarn')
71
    ->set('cachetool_args', '--fcgi=/run/php/chef-managed-fpm-omm.sock --tmp-dir=/tmp')
72
    ->set('console_options', '-vvv')
73
    ->set('deploy_path', '/var/www/sites/gothick.org.uk/{{application}}');
74
75
76
// Tasks
77
78
task('build', function () {
0 ignored issues
show
The function task was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
/** @scrutinizer ignore-call */ 
79
task('build', function () {
Loading history...
79
    run('cd {{release_path}} && build');
80
});
81
82
task('deploy:stop-workers', function () {
83
    // Hack alert: https://stackoverflow.com/a/63652279/300836
84
    // We've just move the previous release out of the way, but it's
85
    // the previous release's cache that has the details of the
86
    // workers we need to kill.
87
    if (has('previous_release')) {
0 ignored issues
show
The function has was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
    if (/** @scrutinizer ignore-call */ has('previous_release')) {
Loading history...
88
        run('{{bin/php}} {{previous_release}}/bin/console messenger:stop-workers');
89
    }
90
})->desc('Stop any existing messenger consumers; Supervisor will restart them.');
91
92
// Testing
93
task('pwd', function () {
94
    $result = run('pwd');
0 ignored issues
show
Are you sure the assignment to $result is correct as run('pwd') seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
95
    writeln("Current dir: $result");
0 ignored issues
show
The function writeln was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
    /** @scrutinizer ignore-call */ 
96
    writeln("Current dir: $result");
Loading history...
96
});
97
98
task('test', function () {
99
    writeln('Hello world');
0 ignored issues
show
The function writeln was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
    /** @scrutinizer ignore-call */ 
100
    writeln('Hello world');
Loading history...
100
});
101
102
// [Optional] if deploy fails automatically unlock.
103
after('deploy:failed', 'deploy:unlock');
0 ignored issues
show
The function after was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
/** @scrutinizer ignore-call */ 
104
after('deploy:failed', 'deploy:unlock');
Loading history...
104
105
// Clear opcache on successful deployment
106
after('deploy:symlink', 'cachetool:clear:opcache');
107
108
// Restart messenger consuers on successful deployment
109
// I don't think this is currently working, but it's probably
110
// because of this bug:
111
// https://github.com/symfony/symfony/issues/40477
112
// So for now I'm probably going to have to manually restart
113
// stuff with Supervisor :(
114
after('cachetool:clear:opcache', 'deploy:stop-workers');
115
116
// Migrate database before symlink new release.
117
118
before('deploy:symlink', 'database:migrate');
0 ignored issues
show
The function before was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

118
/** @scrutinizer ignore-call */ 
119
before('deploy:symlink', 'database:migrate');
Loading history...
119
120
// Yarn and Webpack Encore. Note that Yarn has to install _after_
121
// Composer, as some of the Symfony JS stuff introduces a Yarn
122
// dependency on a file in a Composer vendor directory. (it's for
123
// Charts.js:
124
//         "@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets",
125
// )
126
after('deploy:vendors', 'yarn:install');
127
after('yarn:install', 'webpack_encore:build');
128