mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-22 16:27:39 +01:00
* Hotfix: Fixed file read error in website.php Moved the directory creation and ownership setting code before the file read operation to prevent the file read error. * Hotfix: Adjusted Caddyfile path and ensured its inclusion in build * Regenerate docs using php bin/docgen
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Deployer;
|
|
|
|
set('domain', function () {
|
|
return ask(' Domain: ');
|
|
});
|
|
|
|
set('public_path', function () {
|
|
return ask(' Public path: ', 'public');
|
|
});
|
|
|
|
desc('Provision website');
|
|
task('provision:website', function () {
|
|
run("[ -d {{deploy_path}} ] || mkdir -p {{deploy_path}}");
|
|
run("chown -R deployer:deployer {{deploy_path}}");
|
|
|
|
set('deploy_path', run("realpath {{deploy_path}}"));
|
|
cd('{{deploy_path}}');
|
|
|
|
run("[ -d log ] || mkdir log");
|
|
run("chgrp caddy log");
|
|
|
|
$caddyfile = parse(file_get_contents(__DIR__ . '/Caddyfile'));
|
|
|
|
if (test('[ -f Caddyfile ]')) {
|
|
run("echo $'$caddyfile' > Caddyfile.new");
|
|
$diff = run('diff -U5 --color=always Caddyfile Caddyfile.new', ['no_throw' => true]);
|
|
if (empty($diff)) {
|
|
run('rm Caddyfile.new');
|
|
} else {
|
|
info('Found Caddyfile changes');
|
|
writeln("\n" . $diff);
|
|
$answer = askChoice(' Which Caddyfile to save? ', ['old', 'new'], 0);
|
|
if ($answer === 'old') {
|
|
run('rm Caddyfile.new');
|
|
} else {
|
|
run('mv Caddyfile.new Caddyfile');
|
|
}
|
|
}
|
|
} else {
|
|
run("echo $'$caddyfile' > Caddyfile");
|
|
}
|
|
|
|
if (!test("grep -q 'import {{deploy_path}}/Caddyfile' /etc/caddy/Caddyfile")) {
|
|
run("echo 'import {{deploy_path}}/Caddyfile' >> /etc/caddy/Caddyfile");
|
|
}
|
|
run('service caddy reload');
|
|
|
|
info("Website {{domain}} configured!");
|
|
})->limit(1);
|
|
|
|
desc('Shows caddy logs');
|
|
task('logs:caddy', function () {
|
|
run('tail -f {{deploy_path}}/log/access.log');
|
|
})->verbose();
|
|
|
|
desc('Shows caddy syslog');
|
|
task('logs:caddy:syslog', function () {
|
|
run('sudo journalctl -u caddy -f');
|
|
})->verbose();
|