From e63793264f87ee78299d44a9a818ae51628ddacd Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sat, 19 Oct 2024 14:50:02 +0200 Subject: [PATCH] Allow to use start-from with provision recipe --- recipe/provision.php | 8 ++++++++ recipe/provision/databases.php | 2 ++ recipe/provision/php.php | 2 ++ recipe/provision/user.php | 2 ++ recipe/provision/website.php | 6 +++++- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/recipe/provision.php b/recipe/provision.php index 362e351af..257d9e681 100644 --- a/recipe/provision.php +++ b/recipe/provision.php @@ -69,6 +69,8 @@ desc('Collects required params'); task('provision:configure', function () { + set('remote_user', get('provision_user')); + $params = [ 'sudo_password', 'domain', @@ -115,6 +117,8 @@ desc('Adds repositories and update'); task('provision:update', function () { + set('remote_user', get('provision_user')); + // PHP run('apt-add-repository ppa:ondrej/php -y', ['env' => ['DEBIAN_FRONTEND' => 'noninteractive']]); @@ -130,6 +134,7 @@ desc('Upgrades all packages'); task('provision:upgrade', function () { + set('remote_user', get('provision_user')); run('apt-get upgrade -y', ['env' => ['DEBIAN_FRONTEND' => 'noninteractive'], 'timeout' => 900]); }) ->oncePerNode() @@ -137,6 +142,7 @@ desc('Installs packages'); task('provision:install', function () { + set('remote_user', get('provision_user')); $packages = [ 'acl', 'apt-transport-https', @@ -171,6 +177,7 @@ desc('Configures the ssh'); task('provision:ssh', function () { + set('remote_user', get('provision_user')); run("sed -i 's/PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_config"); run('ssh-keygen -A'); run('service ssh restart'); @@ -182,6 +189,7 @@ desc('Setups a firewall'); task('provision:firewall', function () { + set('remote_user', get('provision_user')); run('ufw allow 22'); run('ufw allow 80'); run('ufw allow 443'); diff --git a/recipe/provision/databases.php b/recipe/provision/databases.php index f67c94e8e..cb325a195 100644 --- a/recipe/provision/databases.php +++ b/recipe/provision/databases.php @@ -26,6 +26,8 @@ desc('Provision databases'); task('provision:databases', function () { + set('remote_user', get('provision_user')); + $dbType = get('db_type'); if ($dbType === 'none') { return; diff --git a/recipe/provision/php.php b/recipe/provision/php.php index 26f01683e..457ae7296 100644 --- a/recipe/provision/php.php +++ b/recipe/provision/php.php @@ -11,6 +11,8 @@ desc('Installs PHP packages'); task('provision:php', function () { + set('remote_user', get('provision_user')); + $version = get('php_version'); info("Installing PHP $version"); $packages = [ diff --git a/recipe/provision/user.php b/recipe/provision/user.php index 03896a836..9262dbfab 100644 --- a/recipe/provision/user.php +++ b/recipe/provision/user.php @@ -11,6 +11,8 @@ desc('Setups a deployer user'); task('provision:user', function () { + set('remote_user', get('provision_user')); + if (test('id deployer >/dev/null 2>&1')) { // TODO: Check what created deployer user configured correctly. // TODO: Update sudo_password of deployer user. diff --git a/recipe/provision/website.php b/recipe/provision/website.php index 82b451130..38d08c8a5 100644 --- a/recipe/provision/website.php +++ b/recipe/provision/website.php @@ -4,6 +4,8 @@ namespace Deployer; +use function Deployer\Support\escape_shell_argument; + set('domain', function () { return ask(' Domain: ', get('hostname')); }); @@ -14,9 +16,11 @@ desc('Configures a server'); task('provision:server', function () { + set('remote_user', get('provision_user')); run('usermod -a -G www-data caddy'); run("mkdir -p /var/deployer"); - upload(__DIR__ . '/404.html', '/var/deployer/404.html'); + $html = file_get_contents(__DIR__ . '/404.html'); + run("echo $'$html' > /var/deployer/404.html"); })->oncePerNode(); desc('Provision website');