Installation
composer require c0ntax/deployment-tasks
Publish the config file (if needed):
php artisan vendor:publish --provider="C0ntax\DeploymentTasks\DeploymentTasksServiceProvider" --tag="config"
Define a Deployment Task
Register a task in app/Providers/AppServiceProvider.php (or a dedicated service provider):
use C0ntax\DeploymentTasks\DeploymentTasks;
public function boot()
{
DeploymentTasks::add('clear_cache', function () {
Artisan::call('cache:clear');
Artisan::call('config:clear');
});
}
Trigger Tasks on Deployment
Use the deploy Artisan command to run all registered tasks:
php artisan deploy
Or run a specific task:
php artisan deploy:run clear_cache
Verify Task Execution
Check the deployment_tasks table (created automatically) for logs or statuses.
Database Migrations & Optimizations
DeploymentTasks::add('optimize_db', function () {
Artisan::call('migrate', ['--force' => true]);
Artisan::call('db:optimize');
});
Asset Compilation & Caching
DeploymentTasks::add('compile_assets', function () {
Artisan::call('vite:build');
Artisan::call('cache:tags', ['css', 'js']);
});
Environment-Specific Tasks Use conditional logic or environment variables:
DeploymentTasks::add('setup_prod', function () {
if (app()->environment('production')) {
Artisan::call('queue:work', ['--daemon' => true]);
}
});
Post-Deployment Verification Integrate with health checks or notifications:
DeploymentTasks::add('notify_success', function () {
Mail::to('team@example.com')->send(new DeploymentSuccess());
});
deploy command into your deployment script.php artisan deploy as a post-deploy step.php artisan make:command CustomDeploy
Then override the handle() method to call DeploymentTasks::run().Task Duplication
if (!DeploymentTasks::wasRun('clear_cache')) {
// Run task
}
Missing Dependencies
migrate, queue:work) are available in your composer.json or package.json.DeploymentTasks::add('validate_dependencies', function () {
if (!Artisan::check('migrate')) {
throw new \Exception('Migrations not available!');
}
});
Configuration Overrides
Logging Gaps
DeploymentTasks::add('logged_task', function () {
\Log::info('Starting task...');
Artisan::call('some:command');
\Log::info('Task completed.');
});
Check Task Statuses
php artisan deploy:list
Inspect the deployment_tasks table for execution history.
Dry Runs
Use --dry-run flag to simulate task execution without side effects:
php artisan deploy --dry-run
Error Handling Wrap tasks in try-catch blocks to prevent silent failures:
DeploymentTasks::add('safe_task', function () {
try {
Artisan::call('risky:command');
} catch (\Exception $e) {
\Log::error("Task failed: " . $e->getMessage());
throw $e; // Re-throw to mark task as failed
}
});
Custom Storage
Override the default database storage by binding a custom DeploymentTaskRepository:
$this->app->bind(
\C0ntax\DeploymentTasks\Repositories\DeploymentTaskRepository::class,
\App\Repositories\CustomDeploymentTaskRepository::class
);
Event Listeners Listen for task execution events (if the package emits them):
event(new \C0ntax\DeploymentTasks\Events\TaskStarting('clear_cache'));
Parallel Execution For long-running tasks, consider running them in parallel using Laravel Queues:
DeploymentTasks::add('async_task', function () {
dispatch(new \App\Jobs\HeavyDeploymentJob());
});
How can I help you explore Laravel packages today?