-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
157 lines (125 loc) · 4.51 KB
/
deploy.php
File metadata and controls
157 lines (125 loc) · 4.51 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/*
* ______ __ __
* / ____/___ ____ / /__________ / /
* / / / __ \/ __ \/ __/ ___/ __ \/ /
* / /___/ /_/ / / / / /_/ / / /_/ / /
* \______________/_/\__/_/ \____/_/
* / | / / /_
* / /| | / / __/
* / ___ |/ / /_
* /_/ _|||_/\__/ __ __
* / __ \___ / /__ / /____
* / / / / _ \/ / _ \/ __/ _ \
* / /_/ / __/ / __/ /_/ __/
* /_____/\___/_/\___/\__/\___/
*
* Copyright www.controlaltdelete.dev
*/
namespace Deployer;
require 'recipe/magento2.php';
// Configuration
set('repository', 'git@github.com:controlaltdelete-nl/shop.magedispatch.com.git');
set('keep_releases', 3);
set('release_name', date('YmdHis')); // Use timestamp for release name
set('default_timeout', 900); // Increase timeouts because builds can take long
add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);
set('writable_mode', 'chmod');
set('static_content_locales', 'en_US nl_NL');
set('static_deploy_options', '--force --no-parent --no-js-bundle');
function getCpuCount(int $default): int {
if (is_file('/proc/cpuinfo')) {
$cpuinfo = file_get_contents('/proc/cpuinfo');
$count = substr_count(strtolower($cpuinfo), 'processor');
return $count > 0 ? $count : $default;
}
return $default;
}
set('static_content_jobs', getCpuCount(4));
set('shared_files', [
// Copied from the recipe
'{{magento_dir}}/app/etc/env.php',
'{{magento_dir}}/var/.maintenance.ip',
]);
set('shared_dirs', [
// Copied from the recipe
'{{magento_dir}}/pub/media',
'{{magento_dir}}/pub/sitemap',
'{{magento_dir}}/pub/static/_cache',
'{{magento_dir}}/var/backups',
'{{magento_dir}}/var/export',
'{{magento_dir}}/var/import',
'{{magento_dir}}/var/importexport',
'{{magento_dir}}/var/import_history',
'{{magento_dir}}/var/log',
'{{magento_dir}}/var/report',
'{{magento_dir}}/var/session',
'{{magento_dir}}/var/tmp',
]);
//
// Hosts are loaded from hosts.yml
import(__DIR__ . '/hosts.yml');
//
// Hooks
after('deploy:failed', 'deploy:unlock');
//
// Tasks
# Clear Deployer default command.
task('cachetool:clear:opcache', function () {});
task('database:development:copy', [
'database:development:dump',
'database:development:download',
]);
task('database:development:dump', function () {
run('rm -f ~/stripped-dump.sql || true');
run('rm -f ~/stripped-dump.sql.gz || true');
run('cd {{current_path}} && magerun2 db:dump ~/stripped-dump.sql --strip="@stripped_project"');
run('gzip ~/stripped-dump.sql');
});
task('database:development:download', function () {
download('~/stripped-dump.sql.gz', 'stripped-dump.sql.gz');
run('rm ~/stripped-dump.sql.gz');
});
task('database:development:import', function () {
runLocally('ddev exec magerun2 db:import -c gz stripped-dump.sql.gz');
runLocally('ddev exec bin/magento setup:upgrade --keep-generated --no-interaction');
runLocally('ddev exec magerun2 admin:user:create --admin-user=michiel --admin-password=asdfasdf1 --admin-email=michiel@example.com --admin-firstname=Michiel --admin-lastname=Gerritsen --no-interaction');
});
task('database:development:import-to-local', [
'database:development:dump',
'database:development:download',
'database:development:import',
]);
task('database:production:copy', [
'database:production:backup',
'download:database:production:backup',
]);
task('database:production:backup', function () {
run('rm -f ~/shop.magedispatch.com-backup.sql || true');
run('rm -f ~/shop.magedispatch.com-backup.sql.gz || true');
run('cd {{current_path}} && magerun2 db:dump ~/shop.magedispatch.com-backup.sql');
run('gzip ~/shop.magedispatch.com-backup.sql');
});
task('download:database:production:backup', function () {
download('~/shop.magedispatch.com-backup.sql.gz', 'shop.magedispatch.com-backup.sql.gz');
run('rm ~/shop.magedispatch.com-backup.sql.gz');
});
task('php-fpm:restart', function () {
run('sudo service php8.3-fpm reload');
});
after('deploy:symlink', 'php-fpm:restart');
task('local:media:sync', function () {
// Define paths
$remoteMediaPath = '{{deploy_path}}/shared/pub/media/';
$localMediaPath = __DIR__ . '/pub/media/';
// Define rsync command
$rsyncCommand = sprintf(
'rsync -avz --progress {{remote_user}}@{{hostname}}:%s %s',
$remoteMediaPath,
$localMediaPath
);
// Run the rsync command locally
runLocally($rsyncCommand);
})->desc('Sync media files from the remote server to the local machine');