-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
109 lines (90 loc) · 2.92 KB
/
deploy.php
File metadata and controls
109 lines (90 loc) · 2.92 KB
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
<?php
namespace Deployer;
require 'recipe/composer.php';
// General settings
set('application', 'application');
set('repository', 'git@github.com:sboerrigter/start.git');
set('default_timeout', 3600);
set('use_atomic_symlink', false);
// Defaults
set('branch', 'main');
set('local_url', 'http://www.start.test');
set('deploy_path', '/var/www/vhosts/TB01-004/{{remote_user}}/site');
set('port', 2223);
set('shared_files', ['.env', 'auth.json', 'web/wp-content/debug.log']);
set('shared_dirs', ['web/wp-content/uploads']);
// Hosts
host('production')
->set('branch', 'main')
->set('hostname', 'tw-server-05.twservices.eu')
->set('remote_user', 'start.bonsjoerd.eu')
->set('remote_url', 'https://start.bonsjoerd.eu');
// Custom tasks
// Install NPM dependencies, build and upload compiled styles and scripts
task('deploy:build', function () {
runLocally('npm install');
runLocally('npm run build');
upload(
'web/wp-content/themes/theme/dist/',
'{{release_path}}/web/wp-content/themes/theme/dist/'
);
});
// SSH into remote server: dep ssh
task('ssh', function () {
runLocally('ssh {{remote_user}}@{{hostname}}');
});
// Pull database: dep db:pull
task('db:pull', function () {
set('ssh_multiplexing', false);
run('cd {{deploy_path}}/current && wp db export {{deploy_path}}/db.sql');
download('{{deploy_path}}/db.sql', 'db.sql');
run('rm -f {{deploy_path}}/db.sql');
runLocally('wp db import db.sql');
runLocally('rm -f db.sql');
runLocally('wp search-replace {{remote_url}} {{local_url}} --all-tables');
});
// Push database: dep db:push
task('db:push', function () {
$sure = askConfirmation(
'Are you sure you want to overwite the remote database?',
false
);
if (!$sure) {
die('Task aborted.');
}
runLocally('wp db export db.sql');
upload('db.sql', '{{deploy_path}}');
runLocally('rm -f db.sql');
run('cd {{deploy_path}}/current && wp db import {{deploy_path}}/db.sql');
run(
'cd {{deploy_path}}/current && wp search-replace {{local_url}} {{remote_url}} --all-tables'
);
run('rm -f {{deploy_path}}/db.sql');
});
// Pull uploads: dep uploads:pull
task('uploads:pull', function () {
runLocally(
'rsync -avz -e "ssh -p {{port}}" {{remote_user}}@{{hostname}}:{{deploy_path}}/shared/web/wp-content/uploads ./web/wp-content'
);
});
// Push uploads: dep uploads:push
task('uploads:push', function () {
runLocally(
'rsync -avz -e "ssh -p {{port}}" ./web/wp-content/uploads {{remote_user}}@{{hostname}}:{{deploy_path}}/shared/web/wp-content'
);
});
// Purge opCache
task('purge:opcache', function () {
run('php-fpm-cli -r "opcache_reset();"');
});
// Purge Varnish
task('purge:varnish', function () {
run(
'curl -sX BAN -H "X-Ban-Method: exact" -H "X-Ban-Host: {{remote_user}}" http://localhost/ > /dev/null'
);
});
// Hooks
after('deploy:prepare', 'deploy:build');
after('deploy', 'purge:opcache');
after('deploy', 'purge:varnish');
after('deploy:failed', 'deploy:unlock');