Passed
Push — master ( 84dd4e...009c90 )
by Matt
11:14
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('ssh.gothick.org.uk')
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('ssh.gothick.org.uk')
Loading history...
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 () {
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

76
/** @scrutinizer ignore-call */ 
77
task('build', function () {
Loading history...
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')) {
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

85
    if (/** @scrutinizer ignore-call */ has('previous_release')) {
Loading history...
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');
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...
93
    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

93
    /** @scrutinizer ignore-call */ 
94
    writeln("Current dir: $result");
Loading history...
94
});
95
96
task('test', function () {
97
    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

97
    /** @scrutinizer ignore-call */ 
98
    writeln('Hello world');
Loading history...
98
});
99
100
// [Optional] if deploy fails automatically unlock.
101
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

101
/** @scrutinizer ignore-call */ 
102
after('deploy:failed', 'deploy:unlock');
Loading history...
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');
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

116
/** @scrutinizer ignore-call */ 
117
before('deploy:symlink', 'database:migrate');
Loading history...
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