104 lines
2.9 KiB
PHP
Executable File
104 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Deployer;
|
|
|
|
require_once '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/WMS.git');
|
|
set('node_version', '22.12.0');
|
|
set('allow_anonymous_stats', false);
|
|
|
|
const RELEASE_CD = 'cd {{release_path}} && ';
|
|
const RELEASE_AND_CD = ' && cd {{release_path}}';
|
|
const DEPLOY_SYMLINK = 'deploy:symlink';
|
|
|
|
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.mlba.dev')
|
|
->set('remote_user', 'mag')
|
|
->set('branch', 'develop')
|
|
->set('deploy_path', '/var/www/helpdesk_dev');
|
|
|
|
host('stage')
|
|
->set('hostname', 'stage.wms.mpba.dev')
|
|
->set('remote_user', 'mag')
|
|
->set('branch', 'stage')
|
|
->set('deploy_path', '/var/www/wms/core');
|
|
|
|
/*
|
|
* 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
|
|
. RELEASE_AND_CD
|
|
. ' && npm ci --no-audit --no-fund',
|
|
);
|
|
|
|
run(
|
|
$node
|
|
. RELEASE_AND_CD
|
|
. ' && 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
|
|
. RELEASE_AND_CD
|
|
. ' && npm run build',
|
|
);
|
|
});
|
|
|
|
task('queue:restart', function (): void {
|
|
run(RELEASE_CD . 'php artisan queue:restart');
|
|
});
|
|
|
|
task('deploy:write_revision_file', function (): void {
|
|
run(RELEASE_CD . 'echo "{{branch}}" > BRANCH');
|
|
run(RELEASE_CD . 'date -u +"%Y-%m-%dT%H:%M:%SZ" > DEPLOYED_AT');
|
|
});
|
|
|
|
task('artisan:clear', function (): void {
|
|
run(RELEASE_CD . 'php artisan view:clear');
|
|
run(RELEASE_CD . 'php artisan optimize:clear');
|
|
run(RELEASE_CD . 'php artisan config:clear');
|
|
run(RELEASE_CD . 'php artisan route:clear');
|
|
});
|
|
|
|
task('services:restart', function (): void {
|
|
run('sudo -n nginx -t');
|
|
run('sudo -n systemctl reload nginx');
|
|
run('sudo -n systemctl restart php8.4-fpm');
|
|
});
|
|
|
|
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');
|