120 lines
3.5 KiB
PHP
120 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Deployer;
|
|
|
|
require 'recipe/laravel.php';
|
|
|
|
set('writable_use_sudo', true);
|
|
set('clear_use_sudo', true);
|
|
set('cleanup_use_sudo', true);
|
|
set('keep_releases', 1);
|
|
set('repository', 'git@git.absdev.net:mag/Helpddesk.git');
|
|
set('node_version', '22.12.0');
|
|
set('allow_anonymous_stats', false);
|
|
|
|
add('shared_files', ['.env']);
|
|
add('shared_dirs', ['storage']);
|
|
add('writable_dirs', ['storage', 'bootstrap/cache']);
|
|
|
|
host('main')
|
|
->set('hostname', 'helpdesk.absdev.net')
|
|
->set('remote_user', 'mag')
|
|
->set('branch', 'main')
|
|
->set('deploy_path', '/var/www/helpdesk');
|
|
|
|
host('develop')
|
|
->set('hostname', 'helpdesk.mpba.dev')
|
|
->set('remote_user', 'mag')
|
|
->set('branch', 'develop')
|
|
->set('deploy_path', '/var/www/helpdesk_dev');
|
|
|
|
host('mpba')
|
|
->set('hostname', 'sirius.absdev.net')
|
|
->set('remote_user', 'mag')
|
|
->set('branch', 'main')
|
|
->set('deploy_path', '/var/www/helpdesk');
|
|
|
|
/*
|
|
* Install the root npm tree, then every module that owns its own lock file,
|
|
* then run ONE root Vite build. Because Vite is compiling a module source file,
|
|
* normal Node resolution finds that module's own node_modules first.
|
|
*/
|
|
task('build', function (): void {
|
|
$node = 'export NVM_DIR="$HOME/.nvm"'
|
|
.' && [ -s "$NVM_DIR/nvm.sh" ]'
|
|
.' && . "$NVM_DIR/nvm.sh"'
|
|
.' && nvm use {{node_version}}';
|
|
|
|
run(
|
|
$node
|
|
.' && cd {{release_path}}'
|
|
.' && npm ci --no-audit --no-fund'
|
|
);
|
|
|
|
run(
|
|
$node
|
|
.' && cd {{release_path}}'
|
|
.' && for lock in Modules/*/package-lock.json; do'
|
|
.' [ -f "$lock" ] || continue;'
|
|
.' module_dir="$(dirname "$lock")";'
|
|
.' echo "[Modules] npm ci: $module_dir";'
|
|
.' (cd "$module_dir" && npm ci --no-audit --no-fund);'
|
|
.' done'
|
|
);
|
|
|
|
run(
|
|
$node
|
|
.' && cd {{release_path}}'
|
|
.' && npm run build'
|
|
);
|
|
});
|
|
|
|
task('queue:restart', function (): void {
|
|
run('cd {{release_path}} && php artisan queue:restart');
|
|
});
|
|
|
|
task('deploy:write_revision_file', function (): void {
|
|
run('cd {{release_path}} && echo "{{branch}}" > BRANCH');
|
|
run('cd {{release_path}} && date -u +"%Y-%m-%dT%H:%M:%SZ" > DEPLOYED_AT');
|
|
});
|
|
|
|
task('artisan:clear', function (): void {
|
|
run('cd {{release_path}} && php artisan view:clear');
|
|
run('cd {{release_path}} && php artisan optimize:clear');
|
|
run('cd {{release_path}} && php artisan config:clear');
|
|
run('cd {{release_path}} && php artisan route:clear');
|
|
});
|
|
|
|
task('services:restart', function (): void {
|
|
// Validate and reload nginx.
|
|
run('sudo -n nginx -t');
|
|
run('sudo -n systemctl reload nginx');
|
|
|
|
// Detect the PHP-FPM socket configured in nginx.
|
|
$socket = trim(run(
|
|
"sudo -n nginx -T 2>/dev/null"
|
|
. " | grep -oE 'php[0-9]+\\.[0-9]+-fpm\\.sock'"
|
|
. " | sort -Vu"
|
|
. " | tail -n 1"
|
|
));
|
|
|
|
if ($socket === '') {
|
|
throw new \RuntimeException(
|
|
'Unable to detect the PHP-FPM version from nginx configuration.'
|
|
);
|
|
}
|
|
// Convert php8.5-fpm.sock into php8.5-fpm.
|
|
$service = str_replace('.sock', '', $socket);
|
|
writeln("<info>Detected PHP-FPM service: {$service}</info>");
|
|
// Restart the detected PHP-FPM service.
|
|
run("sudo -n systemctl restart {$service}");
|
|
writeln("<info>PHP-FPM restarted successfully.</info>");
|
|
});
|
|
|
|
after('deploy:update_code', 'deploy:write_revision_file');
|
|
after('deploy:vendors', 'build');
|
|
after('deploy:symlink', 'artisan:clear');
|
|
after('deploy:symlink', 'queue:restart');
|
|
after('deploy:failed', 'deploy:unlock');
|
|
after('deploy:symlink', 'services:restart');
|