Created
October 30, 2019 12:07
-
-
Save richardhj/8a63df6e1909075abe8b8d9ec54c9b4e to your computer and use it in GitHub Desktop.
Deployer (Contao deployment) with scp instead of rsync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Deployer; | |
$recipes = [ | |
'common', | |
'symfony', | |
'terminal42/deployer-recipes/recipe/contao', | |
'terminal42/deployer-recipes/recipe/database', | |
'terminal42/deployer-recipes/recipe/deploy', | |
'terminal42/deployer-recipes/recipe/maintenance', | |
]; | |
// Require the recipes | |
foreach ($recipes as $recipe) { | |
if (false === strpos($recipe, '/')) { | |
require_once sprintf('recipe/%s.php', $recipe); | |
continue; | |
} | |
require_once sprintf('%s/vendor/%s.php', getcwd(), $recipe); | |
} | |
// Load the hosts | |
inventory('deploy-hosts.yml'); | |
// Enable SSH multiplexing | |
set('ssh_multiplexing', true); | |
// Number of releases to keep | |
set('keep_releases', 3); | |
// set shared directories | |
set( | |
'shared_dirs', | |
[ | |
'assets/images', | |
'files', | |
'system/config', | |
'var/sql', | |
'contao-manager', | |
'var/logs', | |
'web/share', | |
] | |
); | |
// Disable anonymous stats | |
set('allow_anonymous_stats', false); | |
set('scp_src', __DIR__); | |
set('scp_dest', '{{release_path}}'); | |
// Tasks | |
task( | |
'database:backup', | |
static function () { | |
// ... | |
} | |
)->desc('Backup database'); | |
task( | |
'scp_files', | |
static function () { | |
$src = get('scp_src'); | |
while (is_callable($src)) { | |
$src = $src(); | |
} | |
if (!trim($src)) { | |
throw new \RuntimeException('You need to specify a source path.'); | |
} | |
$dst = get('scp_dest'); | |
while (is_callable($dst)) { | |
$dst = $dst(); | |
} | |
if (!trim($dst)) { | |
throw new \RuntimeException('You need to specify a destination path.'); | |
} | |
$server = \Deployer\Task\Context::get()->getHost(); | |
if ($server instanceof \Deployer\Host\Localhost) { | |
throw new \RuntimeException('Host is localhost.'); | |
} | |
$host = $server->getRealHostname(); | |
$port = $server->getPort() ? ' -p' . $server->getPort() : ''; | |
$user = !$server->getUser() ? '' : $server->getUser() . '@'; | |
runLocally("scp$port '$src/config/config.yml' '$user$host:$dst/config'"); | |
runLocally("scp$port '$src/composer.json' '$user$host:$dst'"); | |
runLocally("scp$port '$src/composer.lock' '$user$host:$dst'"); | |
runLocally("scp$port -r '$src/contao/' '$user$host:$dst'"); | |
} | |
)->desc('SCP local->remote'); | |
// Main task | |
task( | |
'deploy', | |
[ | |
// Prepare | |
'contao:validate', | |
// Deploy | |
'deploy:info', | |
'deploy:prepare', | |
'deploy:lock', | |
'deploy:release', | |
'deploy:create_initial_dirs', | |
'deploy:shared', | |
'scp_files', | |
'deploy:composer_self_update', | |
'deploy:platform_release', | |
'deploy:vendors', | |
'deploy:entry_points', | |
// Release | |
'maintenance:enable', | |
'contao:download_manager', | |
'deploy:symlink', | |
'deploy:clear_accelerator_clear', | |
'database:backup', | |
'maintenance:disable', | |
// Cleanup | |
'deploy:unlock', | |
'cleanup', | |
'success', | |
] | |
)->desc('Deploy your project'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment