diff --git a/recipe/provision.php b/recipe/provision.php index 154ef17f8..862a48e2f 100644 --- a/recipe/provision.php +++ b/recipe/provision.php @@ -7,6 +7,7 @@ require __DIR__ . '/provision/php.php'; require __DIR__ . '/provision/website.php'; +use Deployer\Task\Context; use function Deployer\Support\parse_home_dir; add('recipes', ['provision']); @@ -47,16 +48,23 @@ $release = run('cat /etc/os-release'); ['NAME' => $name, 'VERSION_ID' => $version] = parse_ini_string($release); - if ($name !== 'Ubuntu' || $version !== '20.04') { + if ($name !== 'Ubuntu') { warning('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); warning('!! !!'); - warning('!! Only Ubuntu 20.04 LTS supported! !!'); + warning('!! Only Ubuntu is supported! !!'); warning('!! !!'); warning('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); if (!askConfirmation(' Do you want to continue? (Not recommended)', false)) { throw new \RuntimeException('Provision aborted due to incompatible OS.'); } } + // Also only version 20 and older are supported. + if (version_compare($version, '20', '<')) { + warning("Ubuntu $version is not supported. Use Ubuntu 20 or newer."); + if (!askConfirmation(' Do you want to continue? (Not recommended)', false)) { + throw new \RuntimeException('Provision aborted due to incompatible OS.'); + } + } })->oncePerNode(); desc('Collects required params'); @@ -73,25 +81,35 @@ 'db_name', 'db_password', ]; - $code = "\n\n* To streamline script execution, include the following configuration in your deploy.php."; - $code .= "\n - Do not include sensitive information if the file is shared. Replace with actual data"; - $code .= "\n - If a database configuration is not required, 'db_user', 'db_name', and 'db_password' can be omitted."; - $code .= "\n\n====== Configuration Start ======"; - $code .= "\nhost('{{alias}}')"; - foreach (array_merge($params, $dbparams) as $name) { - $code .= "\n ->set('$name', '…')"; - } - $code .= ";\n"; - $code .= "====== Configuration End ======\n\n"; - writeln($code); + + $showCode = false; + foreach ($params as $name) { + if (!Context::get()->getConfig()->hasOwn($name)) { + $showCode = true; + } get($name); } + if (get('db_type') !== 'none') { foreach ($dbparams as $name) { + if (!Context::get()->getConfig()->hasOwn($name)) { + $showCode = true; + } get($name); } } + + if ($showCode) { + $code = "\n\n====== Configuration Start ======"; + $code .= "\nhost('{{alias}}')"; + foreach (array_merge($params, $dbparams) as $name) { + $code .= "\n ->set('$name', '" . get($name) . "')"; + } + $code .= ";\n"; + $code .= "====== Configuration End ======\n\n"; + writeln($code); + } }); @@ -104,13 +122,6 @@ run("curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor --yes -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg"); run("curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' > /etc/apt/sources.list.d/caddy-stable.list"); - // Nodejs - $keyring = '/usr/share/keyrings/nodesource.gpg'; - run("curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee '$keyring' >/dev/null"); - run("gpg --no-default-keyring --keyring '$keyring' --list-keys"); - run("echo 'deb [signed-by=$keyring] https://deb.nodesource.com/{{nodejs_version}} {{lsb_release}} main' | sudo tee /etc/apt/sources.list.d/nodesource.list"); - run("echo 'deb-src [signed-by=$keyring] https://deb.nodesource.com/{{nodejs_version}} {{lsb_release}} main' | sudo tee -a /etc/apt/sources.list.d/nodesource.list"); - // Update run('apt-get update', ['env' => ['DEBIAN_FRONTEND' => 'noninteractive']]); }) diff --git a/recipe/provision/Caddyfile b/recipe/provision/Caddyfile index 2b485c612..2d753e2e1 100644 --- a/recipe/provision/Caddyfile +++ b/recipe/provision/Caddyfile @@ -1,5 +1,4 @@ {{domain}} { - root * {{deploy_path}}/current/{{public_path}} file_server php_fastcgi * unix//run/php/php{{php_version}}-fpm.sock { diff --git a/recipe/provision/databases.php b/recipe/provision/databases.php index e89745c23..f67c94e8e 100644 --- a/recipe/provision/databases.php +++ b/recipe/provision/databases.php @@ -13,7 +13,7 @@ }); set('db_name', function () { - return ask(' DB name: '); + return ask(' DB name: ', 'prod'); }); set('db_user', function () { diff --git a/recipe/provision/nodejs.php b/recipe/provision/nodejs.php index b95402672..402740f8c 100644 --- a/recipe/provision/nodejs.php +++ b/recipe/provision/nodejs.php @@ -3,7 +3,7 @@ namespace Deployer; // Node.js version from https://github.com/nodesource/distributions. -set('nodejs_version', 'node_20.x'); +set('nodejs_version', 'node_23.x'); desc('Installs npm packages'); task('provision:npm', function () { diff --git a/recipe/provision/php.php b/recipe/provision/php.php index 0ba7a1568..72c1af900 100644 --- a/recipe/provision/php.php +++ b/recipe/provision/php.php @@ -3,10 +3,10 @@ namespace Deployer; set('php_version', function () { - $defaultphpVersion = file_exists('composer.json') + $defaultPhpVersion = file_exists('composer.json') ? explode('|', preg_replace('/[^0-9.|]+/', '', json_decode(file_get_contents('composer.json'), true)['require']['php'] ?? '8.3'))[0] : '8.3'; - return ask(' What PHP version to install? ', $defaultphpVersion, ['5.6', '7.4', '8.0', '8.1', '8.2']); + return ask(' What PHP version to install? ', $defaultPhpVersion, ['5.6', '7.4', '8.0', '8.1', '8.2']); }); desc('Installs PHP packages');