Skip to content

Commit

Permalink
Fix rsync transfer when using ssh_config. Add cloudpanel recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
midwestE authored and midwestE committed May 28, 2024
1 parent 79a942a commit 6fb6205
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 7 deletions.
12 changes: 8 additions & 4 deletions contrib/filetransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ public function rsyncCommand(Host $source, string $sourcePath, Host $destination
$port = '';
if ($source instanceof Localhost || hostsOnSameServer($source, $destination)) {
$sourceUri = parse($sourcePath);
} else {
} elseif (!is_null($source->get('config_file'))) {
$port = "-e \"ssh -F " . $source->get('config_file') . "\"";
} elseif (!is_null($source->getPort())) {
$port = "-e \"ssh -p " . $source->getPort() . "\"";
$sourceUri = $source->getRemoteUser() . '@' . $source->getHostname() . ':' . parse($sourcePath);
}

// destination
$destinationUri = $destination->getRemoteUser() . '@' . $destination->getHostname() . ':' . parse($destinationPath);
if ($destination instanceof Localhost || hostsOnSameServer($source, $destination)) {
$destinationUri = parse($destinationPath);
} else {
$destinationUri = $destination->getRemoteUser() . '@' . $destination->getHostname() . ':' . parse($destinationPath);
} elseif (!is_null($destination->get('config_file'))) {
$port = "-e \"ssh -F " . $destination->get('config_file') . "\"";
} elseif (!is_null($destination->getPort())) {
$port = "-e \"ssh -p " . $destination->getPort() . "\"";
}

$command = "$rsync $port $switches $excludes $sourceUri $destinationUri";
Expand Down
110 changes: 110 additions & 0 deletions recipe/cloudpanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Deployer;

require_once __DIR__ . '/common.php';

require_once __DIR__ . '/../contrib/clearserverpaths.php';
require_once __DIR__ . '/../contrib/filetransfer.php';
require_once __DIR__ . '/../contrib/hardening.php';
require_once __DIR__ . '/../contrib/mysql.php';
require_once __DIR__ . '/../contrib/wordpresscli.php';

add('recipes', ['cloudpanel']);

/**
* Siteground configuration
*/
set('shared_dirs', ['wp-content/uploads']);
set('writable_dirs', ['wp-content/uploads']);

/* ----------------- filesharden ----------------- */
// for task 'deploy:harden'
set('harden_dir_permissions', 'u=rx,g=rx,o=rx');
set('harden_file_permissions', 'u=r,g=r,o=r');
/* ----------------- clear_server_paths ----------------- */
set('clear_server_paths', []);

/**
* Deploy task
*/
// desc('Prepares a new release');
// task('deploy:prepare', [
// 'deploy:info',
// 'deploy:setup',
// 'deploy:lock',
// 'deploy:release',
// 'deploy:update_code',
// 'deploy:shared',
// 'deploy:writable',
// ]);

// desc('Publishes the release');
// task('deploy:publish', [
// 'deploy:symlink',
// 'deploy:unlock',
// 'deploy:cleanup',
// 'deploy:success',
// ]);

task('deploy', [
'deploy:prepare',
'deploy:vendors',
'deploy:clear_paths',
'deploy:harden',
'deploy:publish',
'cp:purge'
])->desc('Deploys your project');

/**
* Hooks
*/
before('deploy:cleanup', function () {
invoke('deploy:unharden');
})->desc('Unharden previous site releases');

after('deploy:harden', function () {
invoke('deploy:writablehardened');
})->desc('Apply writable permissions to files/folders in harden_writable_files');

after('deploy:failed', function () {
invoke('deploy:unlock');
invoke('deploy:unharden');
})->desc('Unlock after deploy:failed and unharded failed release');
after('deploy:symlink', 'deploy:clear_server_paths');

task('pull-all', [
'db:pull-replace',
'files:pull',
])->desc('Pull db from a remote stage, replaces instances of domain in db, and pulls writable files');

// task('cp', function () {
// $wpcli = new WordpressCli(currentHost());
// $command = $wpcli->command('cp');
// run($command, ['real_time_output' => true]);
// })->desc('Show the siteground cli options');

task('cp:purge:transient', function () {
$wpcli = new WordpressCli(currentHost());
$command = $wpcli->command('transient delete --all');
run($command);
})->desc('Purge wp transients');

task('cp:purge', function () {
invoke('cp:purge:transient');
invoke('wp:cache:flush');
// invoke('sg:purge:memcached');
// invoke('sg:purge:dynamic');
})->desc('Purge the transients, wp cache, and Siteground dynamic and memcached caches');

// task('sg:purge:dynamic', function () {
// $wpcli = new WordpressCli(currentHost());
// $command = $wpcli->command('sg purge');
// run($command);
// })->desc('Purge the Siteground dynamic cache');

// task('sg:purge:memcached', function () {
// $wpcli = new WordpressCli(currentHost());
// $command = $wpcli->command('sg purge memcached');
// run($command);
// })->desc('Purge the Siteground memcached cache');
6 changes: 3 additions & 3 deletions recipe/siteground.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@
})->desc('Purge wp transients');

task('sg:purge', function () {
invoke('sg:purge:transient');
// invoke('sg:purge:transient');
invoke('wp:cache:flush');
invoke('sg:purge:memcached');
invoke('sg:purge:dynamic');
// invoke('sg:purge:memcached');
// invoke('sg:purge:dynamic');
})->desc('Purge the transients, wp cache, and Siteground dynamic and memcached caches');

task('sg:purge:dynamic', function () {
Expand Down

0 comments on commit 6fb6205

Please sign in to comment.