Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Deployment Tasks Laravel Package

c0ntax/deployment-tasks

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require c0ntax/deployment-tasks
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="C0ntax\DeploymentTasks\DeploymentTasksServiceProvider" --tag="config"
    
  2. 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');
        });
    }
    
  3. 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
    
  4. Verify Task Execution Check the deployment_tasks table (created automatically) for logs or statuses.


Implementation Patterns

Common Workflows

  1. Database Migrations & Optimizations

    DeploymentTasks::add('optimize_db', function () {
        Artisan::call('migrate', ['--force' => true]);
        Artisan::call('db:optimize');
    });
    
  2. Asset Compilation & Caching

    DeploymentTasks::add('compile_assets', function () {
        Artisan::call('vite:build');
        Artisan::call('cache:tags', ['css', 'js']);
    });
    
  3. Environment-Specific Tasks Use conditional logic or environment variables:

    DeploymentTasks::add('setup_prod', function () {
        if (app()->environment('production')) {
            Artisan::call('queue:work', ['--daemon' => true]);
        }
    });
    
  4. Post-Deployment Verification Integrate with health checks or notifications:

    DeploymentTasks::add('notify_success', function () {
        Mail::to('team@example.com')->send(new DeploymentSuccess());
    });
    

Integration Tips

  • Laravel Forge/Envoyer: Hook the deploy command into your deployment script.
  • GitHub Actions/GitLab CI: Run php artisan deploy as a post-deploy step.
  • Custom Commands: Extend the package by creating a custom Artisan command:
    php artisan make:command CustomDeploy
    
    Then override the handle() method to call DeploymentTasks::run().

Gotchas and Tips

Pitfalls

  1. Task Duplication

    • Tasks are idempotent by default (run once per deployment). If a task fails mid-execution, it may rerun unintentionally.
    • Fix: Use transactional logic or check task statuses manually:
      if (!DeploymentTasks::wasRun('clear_cache')) {
          // Run task
      }
      
  2. Missing Dependencies

    • Ensure required Artisan commands (e.g., migrate, queue:work) are available in your composer.json or package.json.
    • Tip: Add a pre-deploy check:
      DeploymentTasks::add('validate_dependencies', function () {
          if (!Artisan::check('migrate')) {
              throw new \Exception('Migrations not available!');
          }
      });
      
  3. Configuration Overrides

    • The package may not support overriding task configurations dynamically. Hardcode sensitive logic (e.g., API keys) in environment files.
  4. Logging Gaps

    • The package lacks built-in logging for task outputs. Extend it by wrapping tasks in logging:
      DeploymentTasks::add('logged_task', function () {
          \Log::info('Starting task...');
          Artisan::call('some:command');
          \Log::info('Task completed.');
      });
      

Debugging Tips

  • 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
        }
    });
    

Extension Points

  1. Custom Storage Override the default database storage by binding a custom DeploymentTaskRepository:

    $this->app->bind(
        \C0ntax\DeploymentTasks\Repositories\DeploymentTaskRepository::class,
        \App\Repositories\CustomDeploymentTaskRepository::class
    );
    
  2. Event Listeners Listen for task execution events (if the package emits them):

    event(new \C0ntax\DeploymentTasks\Events\TaskStarting('clear_cache'));
    
  3. Parallel Execution For long-running tasks, consider running them in parallel using Laravel Queues:

    DeploymentTasks::add('async_task', function () {
        dispatch(new \App\Jobs\HeavyDeploymentJob());
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views