Skip to content

Commit faea34e

Browse files
committed
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.
1 parent 93895f3 commit faea34e

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [0.5.0] - 2025-01-XX
99

10+
### Added
11+
- Post-deployment optimization commands matching GitHub Actions workflow:
12+
- Application optimization (`optimize:clear` and `optimize`)
13+
- Event caching (`event:clear` and `event:cache`)
14+
- Queue worker restart (`queue:restart`)
15+
- Horizon termination (`horizon:terminate`)
16+
- Application cache clearing (`cache:clear`)
17+
- OPcache clearing (`opcache:clear`)
18+
- Configurable caching commands (config, route, view) via config file flags
19+
1020
### Fixed
1121
- Fixed `.env` file being overwritten during incremental deployments
1222
- 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
1929
- App key generation only runs if `APP_KEY` is not set in `.env`
2030
- Storage symlink creation only runs if symlink doesn't exist
2131
- Safe for incremental deployments - preserves user data and configuration files
22-
- Migrations now check for `.env` existence before running
32+
- Removed redundant `.env` file existence checks (file is guaranteed to exist at post-deployment stage)
33+
- `hostinger:deploy` command now matches GitHub Actions workflow post-deployment behavior
2334

2435
### Changed
2536
- Deployment commands are now idempotent - safe to run multiple times without side effects

src/Commands/DeploySharedCommand.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,57 @@ protected function buildDeploymentCommands(string $repoUrl, string $siteDir, str
358358
$commands[] = "if [ -d public ] && [ ! -L public_html ] && [ ! -d public_html ]; then ln -s public public_html; fi";
359359

360360
// Generate app key ONLY if APP_KEY is not set in .env
361-
// Check if .env exists AND if APP_KEY line exists and is not empty
362-
$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";
361+
$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";
363362

364-
// Run migrations only if .env exists (app is configured)
363+
// Run migrations
365364
if (config('hostinger-deploy.deployment.run_migrations', true)) {
366-
$commands[] = "if [ -f .env ]; then echo 'yes' | php artisan migrate --quiet; fi";
365+
$commands[] = "echo 'yes' | php artisan migrate --quiet";
367366
}
368367

369368
// Create storage link only if it doesn't exist
370369
if (config('hostinger-deploy.deployment.run_storage_link', true)) {
371370
$commands[] = "if [ -d public ] && [ ! -L public/storage ] && [ ! -d public/storage ]; then php artisan storage:link --quiet; fi";
372371
}
373372

373+
// Post-deployment optimization commands
374+
// Clear and cache configuration
375+
if (config('hostinger-deploy.deployment.run_config_cache', false)) {
376+
$commands[] = "php artisan config:clear --quiet";
377+
$commands[] = "php artisan config:cache --quiet";
378+
}
379+
380+
// Clear and cache routes
381+
if (config('hostinger-deploy.deployment.run_route_cache', false)) {
382+
$commands[] = "php artisan route:clear --quiet";
383+
$commands[] = "php artisan route:cache --quiet";
384+
}
385+
386+
// Clear and cache views
387+
if (config('hostinger-deploy.deployment.run_view_cache', false)) {
388+
$commands[] = "php artisan view:clear --quiet";
389+
$commands[] = "php artisan view:cache --quiet";
390+
}
391+
392+
// Optimize application (always run)
393+
$commands[] = "php artisan optimize:clear --quiet";
394+
$commands[] = "php artisan optimize --quiet";
395+
396+
// Clear and cache events (if available)
397+
$commands[] = "php artisan event:clear --quiet || true";
398+
$commands[] = "php artisan event:cache --quiet || true";
399+
400+
// Restart queue workers (if using queues)
401+
$commands[] = "php artisan queue:restart --quiet || true";
402+
403+
// Restart Horizon (if using Laravel Horizon)
404+
$commands[] = "php artisan horizon:terminate --quiet || true";
405+
406+
// Clear application cache
407+
$commands[] = "php artisan cache:clear --quiet";
408+
409+
// Clear OPcache (if available)
410+
$commands[] = "php artisan opcache:clear --quiet || true";
411+
374412
return $commands;
375413
}
376414

0 commit comments

Comments
 (0)