-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmagento.php
More file actions
161 lines (135 loc) · 5.21 KB
/
Copy pathmagento.php
File metadata and controls
161 lines (135 loc) · 5.21 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
158
159
160
161
<?php
namespace Deployer;
use Deployer\Task\Context;
use Symfony\Component\Console\Input\InputOption;
// TODO Add deployer version check (now it works only with Deployer >= 5.0)
require 'recipe/common.php';
set('magento_root_path', function () {
$magentoRoot = get('magento_root');
return empty($magentoRoot) ? '' : (rtrim($magentoRoot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
});
// Magento shared dirs
set(
'shared_dirs',
['{{magento_root_path}}' . 'var', '{{magento_root_path}}' . 'media', '{{magento_root_path}}' . 'sitemaps']
);
// Magento shared files
set('shared_files', ['{{magento_root_path}}' . 'app/etc/local.xml', '{{magento_root_path}}' . '.htaccess']);
// Magento writable dirs
set(
'writable_dirs',
['{{magento_root_path}}' . 'var', '{{magento_root_path}}' . 'media', '{{magento_root_path}}' . 'sitemaps']
);
// Magento media pull exclude dirs (paths must be relative to the media dir)
set('media_pull_exclude_dirs', ['css', 'css_secure', 'js', 'catalog/product/cache']);
// Magento clear paths
set(
'clear_paths',
[
'{{magento_root_path}}' . 'LICENSE.html',
'{{magento_root_path}}' . 'LICENSE.txt',
'{{magento_root_path}}' . 'LICENSE_AFL.txt',
'{{magento_root_path}}' . 'RELEASE_NOTES.txt',
'{{magento_root_path}}' . 'downloader',
]
);
// Setup run timeout
set('setup-run-timeout', 300);
// DB pull strip tables
set('db_pull_strip_tables', ['@stripped']);
// Local/remote magerun path
set('magerun_remote', 'n98-magerun.phar');
set('magerun_local', getenv('DEPLOYER_MAGERUN_LOCAL') ?: 'n98-magerun.phar');
set('local_project_path', function () {
return runLocally('pwd');
});
// Tasks
desc('Run the Magento setup scripts');
task('magento:setup-run', function () {
if (test('[ -f {{release_path}}/{{magento_root_path}}app/etc/local.xml ]')) {
$installed = run('cat {{release_path}}/{{magento_root_path}}app/etc/local.xml | grep "<date>"; true');
if ($installed) {
run(
'cd {{release_path}}/{{magento_root_path}} && {{magerun_remote}} sys:setup:run --no-implicit-cache-flush',
['timeout' => get('setup-run-timeout')]
);
}
}
});
desc('Clear Magento cache');
task('magento:clear-cache', function () {
if (test('[ -f {{release_path}}/{{magento_root_path}}app/etc/local.xml ]')) {
$installed = run('cat {{release_path}}/{{magento_root_path}}app/etc/local.xml | grep "<date>"; true');
if ($installed) {
run('cd {{release_path}}/{{magento_root_path}} && {{magerun_remote}} cache:clean');
}
}
});
desc('Create Magento database dump');
task('magento:db-dump', function () {
run('cd {{current_path}}/{{magento_root_path}} && {{magerun_remote}} db:dump -n -c gz ~');
});
option(
'db-pull-timeout',
null,
InputOption::VALUE_OPTIONAL,
'Timeout for db:dump and db:import executions in db-pull task in seconds (default is 300s)'
);
desc('Pull Magento database to local');
task('magento:db-pull', function () {
$timeout = 300;
if (input()->hasOption('db-pull-timeout')) {
$timeout = input()->getOption('db-pull-timeout');
}
$fileName = uniqid('dbdump_');
$stripTables = implode(' ', get('db_pull_strip_tables'));
$remoteDump = "/tmp/{$fileName}.sql.gz";
run(
'cd {{current_path}}/{{magento_root_path}} && ' .
'{{magerun_remote}} db:dump -n --strip="'. $stripTables .'" -c gz ' . $remoteDump,
['timeout' => $timeout]
);
$dumpName = tempnam(sys_get_temp_dir(), 'deployer_');
$localDumpGz = $dumpName . '.sql.gz';
$localDumpSql = $dumpName . '.sql';
download($remoteDump, $localDumpGz);
run('rm ' . $remoteDump);
runLocally('gunzip ' . $localDumpGz);
runLocally(
'cd {{local_project_path}}/{{magento_root_path}} && {{magerun_local}} db:import -n --drop-tables --optimize ' . $localDumpSql,
['timeout' => $timeout]
);
runLocally('cd {{local_project_path}}/{{magento_root_path}} && {{magerun_local}} cache:disable');
runLocally('rm ' . $localDumpSql);
});
option(
'media-pull-timeout',
null,
InputOption::VALUE_OPTIONAL,
'Timeout for media-pull task in seconds (default is 300s)'
);
desc('Pull Magento media to local');
task('magento:media-pull', function () {
$remotePath = '{{current_path}}/{{magento_root_path}}/media/';
$localPath = '{{local_project_path}}/{{magento_root_path}}/media/';
$excludeDirs = array_map(function($dir) {
return '--exclude '.$dir;
}, get('media_pull_exclude_dirs'));
$timeout = 300;
if (input()->hasOption('media-pull-timeout')) {
$timeout = input()->getOption('media-pull-timeout');
}
$config = [
'options' => $excludeDirs,
'timeout' => $timeout
];
download($remotePath, $localPath, $config);
});
desc('Set "copy" as Magento deploy strategy');
task('magento:set-copy-deploy-strategy', function(){
run('cd {{release_path}} && {{bin/composer}} config extra.magento-deploystrategy copy');
run('cd {{release_path}} && {{bin/composer}} config extra.magento-force true');
});
after('deploy:shared', 'magento:set-copy-deploy-strategy');
before('deploy:symlink', 'magento:setup-run');
after('deploy:symlink', 'magento:clear-cache');