From 4affed756e9040802f24f753660dca22c390e4a3 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Fri, 20 Nov 2026 09:30:42 +0000 Subject: [PATCH] new design with nice layout --- deploy.php | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 deploy.php diff --git a/deploy.php b/deploy.php new file mode 100644 index 0000000..8eecdef --- /dev/null +++ b/deploy.php @@ -0,0 +1,108 @@ +set('hostname', '217.154.36.101') + ->set('remote_user', 'mag') + ->set('branch', 'main') + ->set('deploy_path', '/opt/laravel-sites/absdev-net/deploy'); + + +/* + * 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("Detected PHP-FPM service: {$service}"); + // Restart the detected PHP-FPM service. + run("sudo -n systemctl restart {$service}"); + writeln("PHP-FPM restarted successfully."); +}); + +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');