Skip to content

Commit 6ba8fb1

Browse files
Merge pull request #26 from xima-media/media_push_rsync_fix
feat: patch media:push task due to broken rsync flag
2 parents f0b5891 + e8dffcc commit 6ba8fb1

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,15 @@ import-job:
132132
- vendor/bin/dep reset:from_gitlab_artifact --options="token:$CI_VARIABLE_WITH_API_TOKEN,dumpcode:myArtifact" host-a
133133
when: manual
134134
```
135+
136+
## Patch for media:push task
137+
138+
The flag `--keep-dirlinks (-K)` is broken in recent rsync versions - this causes media:push from https://github.com/sourcebroker/deployer-extended-media to fail when syncing into symlinked directories: https://github.com/sourcebroker/deployer-extended-media/issues/9
139+
140+
To patch this, the absolute path to the shared dir is used:
141+
```php
142+
# 37 $src = get('deploy_path') . '/' . (test('[ -L {{deploy_path}}/release ]') ? 'release' : 'current');
143+
$src = get('deploy_path') . '/' . 'shared';
144+
```
145+
146+
Warning: All synchronised directories in **media_custom** must be **shared_dirs**.

autoload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
require_once(__DIR__ . '/recipe/check_requirements.php');
2222
require_once(__DIR__ . '/recipe/sequelace.php');
2323
require_once(__DIR__ . '/recipe/reset_from_gitlab_artifact.php');
24+
require_once(__DIR__ . '/recipe/media_push.php');
25+
2426

2527
// prevent pipeline fail on first deploy (no tables)
2628
// + enable database copy in feature branch deployment

recipe/media_push.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
use Deployer\Exception\GracefulShutdownException;
6+
use SourceBroker\DeployerExtendedMedia\Utility\FileUtility;
7+
use SourceBroker\DeployerInstance\Configuration;
8+
9+
/*
10+
* @see https://github.com/sourcebroker/deployer-extended-media#media-push
11+
*/
12+
task('media:push', function () {
13+
$targetName = get('argument_host');
14+
if ($targetName === get('instance_live_name', 'live')) {
15+
if (!get('media_allow_push_live', true)) {
16+
throw new GracefulShutdownException(
17+
'FORBIDDEN: For security its forbidden to push media to top instance: "' . $targetName . '"!'
18+
);
19+
}
20+
if (!get('media_allow_push_live_force', false)) {
21+
writeln("<error>\n\n");
22+
writeln(sprintf(
23+
"You going to push media from instance: \"%s\" to top instance: \"%s\". ",
24+
get('local_host'),
25+
$targetName
26+
));
27+
writeln("This can be destructive.\n\n");
28+
writeln("</error>");
29+
if (!askConfirmation('Do you really want to continue?', false)) {
30+
throw new GracefulShutdownException('Process aborted.');
31+
}
32+
if (!askConfirmation('Are you sure?', false)) {
33+
throw new GracefulShutdownException('Process aborted.');
34+
}
35+
}
36+
}
37+
$src = get('deploy_path') . '/' . 'shared';
38+
if (!trim($src)) {
39+
throw new GracefulShutdownException('You need to specify a source path.');
40+
}
41+
$src = (new FileUtility)->normalizeFolder($src);
42+
43+
$dst = get('media_rsync_dest');
44+
while (is_callable($dst)) {
45+
$dst = $dst();
46+
}
47+
if (!trim($dst)) {
48+
throw new GracefulShutdownException('You need to specify a destination path.');
49+
}
50+
$dst = (new FileUtility)->normalizeFolder($dst);
51+
52+
$targetServer = Configuration::getHost($targetName);
53+
$host = $targetServer->getHostname();
54+
$user = !$targetServer->getRemoteUser() ? '' : $targetServer->getRemoteUser() . '@';
55+
56+
$rsyncSshOptions = '';
57+
$connectionOptions = $targetServer->connectionOptionsString();
58+
if ($connectionOptions !== '') {
59+
$rsyncSshOptions = '-e "ssh ' . $connectionOptions . ' "';
60+
}
61+
runLocally(
62+
'rsync ' . $rsyncSshOptions . ' {{media_rsync_flags}}{{media_rsync_options}}{{media_rsync_includes}}{{media_rsync_excludes}}{{media_rsync_filter}}'
63+
. ' '
64+
. escapeshellarg($dst)
65+
. ' '
66+
. escapeshellarg($user . $host . ':' . $src)
67+
);
68+
})->desc('Synchronize media from local instance to remote instance');

0 commit comments

Comments
 (0)