Skip to content

Commit

Permalink
Update provision test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Oct 17, 2024
1 parent 14d1b7e commit ecbd16e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
51 changes: 31 additions & 20 deletions recipe/provision.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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');
Expand All @@ -73,25 +81,35 @@
'db_name',
'db_password',
];
$code = "\n\n<comment>* To streamline script execution, include the following configuration in your <info>deploy.php</info>.</comment>";
$code .= "\n<fg=magenta> - Do not include sensitive information if the file is shared. Replace <info>…</info> with actual data</>";
$code .= "\n<fg=magenta> - If a database configuration is not required, 'db_user', 'db_name', and 'db_password' can be omitted.</>";
$code .= "\n\n<comment>====== Configuration Start ======</comment>";
$code .= "\nhost(<info>'{{alias}}'</info>)";
foreach (array_merge($params, $dbparams) as $name) {
$code .= "\n ->set(<info>'$name'</info>, <info>'…'</info>)";
}
$code .= ";\n";
$code .= "<comment>====== Configuration End ======</comment>\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<comment>====== Configuration Start ======</comment>";
$code .= "\nhost(<info>'{{alias}}'</info>)";
foreach (array_merge($params, $dbparams) as $name) {
$code .= "\n ->set(<info>'$name'</info>, <info>'" . get($name) . "'</info>)";
}
$code .= ";\n";
$code .= "<comment>====== Configuration End ======</comment>\n\n";
writeln($code);
}
});


Expand All @@ -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']]);
})
Expand Down
1 change: 0 additions & 1 deletion recipe/provision/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{domain}} {

root * {{deploy_path}}/current/{{public_path}}
file_server
php_fastcgi * unix//run/php/php{{php_version}}-fpm.sock {
Expand Down
2 changes: 1 addition & 1 deletion recipe/provision/databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
});

set('db_name', function () {
return ask(' DB name: ');
return ask(' DB name: ', 'prod');
});

set('db_user', function () {
Expand Down
2 changes: 1 addition & 1 deletion recipe/provision/nodejs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions recipe/provision/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ecbd16e

Please sign in to comment.