Enhance post-deployment process with new optimization commands and configurable caching options. Updated DeploySharedCommand to streamline application optimization, event caching, and queue management. Removed redundant checks for .env file existence during migrations. Updated CHANGELOG to reflect these changes.

This commit is contained in:
Zura Sekhniashvili
2025-12-09 12:52:07 +11:00
parent 93895f3a60
commit faea34e884
2 changed files with 54 additions and 5 deletions

View File

@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.5.0] - 2025-01-XX ## [0.5.0] - 2025-01-XX
### Added
- Post-deployment optimization commands matching GitHub Actions workflow:
- Application optimization (`optimize:clear` and `optimize`)
- Event caching (`event:clear` and `event:cache`)
- Queue worker restart (`queue:restart`)
- Horizon termination (`horizon:terminate`)
- Application cache clearing (`cache:clear`)
- OPcache clearing (`opcache:clear`)
- Configurable caching commands (config, route, view) via config file flags
### Fixed ### Fixed
- Fixed `.env` file being overwritten during incremental deployments - Fixed `.env` file being overwritten during incremental deployments
- Fixed app key regeneration breaking user sessions on subsequent deployments - Fixed app key regeneration breaking user sessions on subsequent deployments
@@ -19,7 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- App key generation only runs if `APP_KEY` is not set in `.env` - App key generation only runs if `APP_KEY` is not set in `.env`
- Storage symlink creation only runs if symlink doesn't exist - Storage symlink creation only runs if symlink doesn't exist
- Safe for incremental deployments - preserves user data and configuration files - Safe for incremental deployments - preserves user data and configuration files
- Migrations now check for `.env` existence before running - Removed redundant `.env` file existence checks (file is guaranteed to exist at post-deployment stage)
- `hostinger:deploy` command now matches GitHub Actions workflow post-deployment behavior
### Changed ### Changed
- Deployment commands are now idempotent - safe to run multiple times without side effects - Deployment commands are now idempotent - safe to run multiple times without side effects

View File

@@ -358,12 +358,11 @@ class DeploySharedCommand extends BaseHostingerCommand
$commands[] = "if [ -d public ] && [ ! -L public_html ] && [ ! -d public_html ]; then ln -s public public_html; fi"; $commands[] = "if [ -d public ] && [ ! -L public_html ] && [ ! -d public_html ]; then ln -s public public_html; fi";
// Generate app key ONLY if APP_KEY is not set in .env // Generate app key ONLY if APP_KEY is not set in .env
// Check if .env exists AND if APP_KEY line exists and is not empty $commands[] = "if ! grep -q '^APP_KEY=base64:' .env 2>/dev/null && ! grep -q '^APP_KEY=\"base64:' .env 2>/dev/null; then php artisan key:generate --quiet; fi";
$commands[] = "if [ -f .env ] && ! grep -q '^APP_KEY=base64:' .env 2>/dev/null && ! grep -q '^APP_KEY=\"base64:' .env 2>/dev/null; then php artisan key:generate --quiet; fi";
// Run migrations only if .env exists (app is configured) // Run migrations
if (config('hostinger-deploy.deployment.run_migrations', true)) { if (config('hostinger-deploy.deployment.run_migrations', true)) {
$commands[] = "if [ -f .env ]; then echo 'yes' | php artisan migrate --quiet; fi"; $commands[] = "echo 'yes' | php artisan migrate --quiet";
} }
// Create storage link only if it doesn't exist // Create storage link only if it doesn't exist
@@ -371,6 +370,45 @@ class DeploySharedCommand extends BaseHostingerCommand
$commands[] = "if [ -d public ] && [ ! -L public/storage ] && [ ! -d public/storage ]; then php artisan storage:link --quiet; fi"; $commands[] = "if [ -d public ] && [ ! -L public/storage ] && [ ! -d public/storage ]; then php artisan storage:link --quiet; fi";
} }
// Post-deployment optimization commands
// Clear and cache configuration
if (config('hostinger-deploy.deployment.run_config_cache', false)) {
$commands[] = "php artisan config:clear --quiet";
$commands[] = "php artisan config:cache --quiet";
}
// Clear and cache routes
if (config('hostinger-deploy.deployment.run_route_cache', false)) {
$commands[] = "php artisan route:clear --quiet";
$commands[] = "php artisan route:cache --quiet";
}
// Clear and cache views
if (config('hostinger-deploy.deployment.run_view_cache', false)) {
$commands[] = "php artisan view:clear --quiet";
$commands[] = "php artisan view:cache --quiet";
}
// Optimize application (always run)
$commands[] = "php artisan optimize:clear --quiet";
$commands[] = "php artisan optimize --quiet";
// Clear and cache events (if available)
$commands[] = "php artisan event:clear --quiet || true";
$commands[] = "php artisan event:cache --quiet || true";
// Restart queue workers (if using queues)
$commands[] = "php artisan queue:restart --quiet || true";
// Restart Horizon (if using Laravel Horizon)
$commands[] = "php artisan horizon:terminate --quiet || true";
// Clear application cache
$commands[] = "php artisan cache:clear --quiet";
// Clear OPcache (if available)
$commands[] = "php artisan opcache:clear --quiet || true";
return $commands; return $commands;
} }