From 8677b1d85dbe23bdbc659c2da5fc35d5de797a62 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 23 May 2023 15:48:05 +0200 Subject: [PATCH] fix --- .env.production | 2 ++ app/Console/Kernel.php | 2 ++ .../Livewire/Project/Application/Deploy.php | 2 +- app/Jobs/DeployApplicationJob.php | 32 ++++++++++++++----- app/Jobs/DockerCleanupDanglingImagesJob.php | 2 +- bootstrap/helpers.php | 2 +- config/horizon.php | 14 ++++---- .../etc/s6-overlay/s6-rc.d/queue-worker/run | 2 +- .../application/get-deployments.blade.php | 11 ++++--- scripts/run | 3 ++ storage/framework/cache/data/.gitignore | 2 -- 11 files changed, 49 insertions(+), 25 deletions(-) delete mode 100644 storage/framework/cache/data/.gitignore diff --git a/.env.production b/.env.production index 05e553f39..55294fc40 100644 --- a/.env.production +++ b/.env.production @@ -21,3 +21,5 @@ DB_PASSWORD= QUEUE_CONNECTION=redis REDIS_HOST=coolify-redis REDIS_PASSWORD= + +CACHE_DRIVER=redis diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index dc98c5478..f6369005a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,8 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule): void { + $schedule->command('horizon:snapshot')->everyFiveMinutes(); + $schedule->job(new DockerCleanupDanglingImagesJob)->everyFiveMinutes(); $schedule->job(new AutoUpdateJob)->everyFifteenMinutes(); $schedule->job(new ProxyCheckJob)->everyMinute(); diff --git a/app/Http/Livewire/Project/Application/Deploy.php b/app/Http/Livewire/Project/Application/Deploy.php index cc3df7e8b..71dc5318c 100644 --- a/app/Http/Livewire/Project/Application/Deploy.php +++ b/app/Http/Livewire/Project/Application/Deploy.php @@ -27,7 +27,7 @@ public function mount() $this->parameters = getParameters(); $this->application = Application::where('id', $this->applicationId)->first(); $this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first(); - dispatch(new ContainerStatusJob($this->application->uuid)); + // dispatch(new ContainerStatusJob($this->application->uuid)); } protected function setDeploymentUuid() { diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index b580500d1..a683d2b4a 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -5,6 +5,7 @@ use App\Actions\CoolifyTask\RunRemoteProcess; use App\Data\CoolifyTaskArgs; use App\Enums\ActivityTypes; +use App\Enums\ProcessStatus; use App\Models\Application; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -18,12 +19,13 @@ use Illuminate\Support\Str; use Spatie\Url\Url; use Illuminate\Queue\Middleware\WithoutOverlapping; +use Throwable; class DeployApplicationJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - protected $application; + protected Application $application; protected $destination; protected $source; protected Activity $activity; @@ -34,15 +36,13 @@ class DeployApplicationJob implements ShouldQueue protected $env_args; public static int $batch_counter = 0; public $timeout = 3600; + public $tries = 60; public function middleware(): array { - return [new WithoutOverlapping($this->application_uuid)]; - } - public function uniqueId(): string - { - return $this->application_uuid; + return [(new WithoutOverlapping($this->application->uuid))->releaseAfter(10)]; } + public function __construct( public string $deployment_uuid, public string $application_uuid, @@ -223,10 +223,26 @@ public function handle(): void Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose); } $this->executeNow(["docker rm -f {$this->deployment_uuid} >/dev/null 2>&1"], hideFromOutput: true); - dispatch(new ContainerStatusJob($this->application_uuid)); + // dispatch(new ContainerStatusJob($this->application_uuid)); } } - + public function failed(Throwable $exception): void + { + $outputStack[] = [ + 'type' => 'out', + 'output' => $exception->getMessage(), + 'timestamp' => hrtime(true), + 'batch' => DeployApplicationJob::$batch_counter, + 'order' => 0, + ]; + $this->activity->description = json_encode($outputStack); + $this->activity->properties = $this->activity->properties->merge([ + 'exitCode' => 0, + 'status' => ProcessStatus::ERROR->value, + ]); + $this->activity->save(); + $this->fail($exception); + } private function execute_in_builder(string $command) { return "docker exec {$this->deployment_uuid} bash -c '{$command}'"; diff --git a/app/Jobs/DockerCleanupDanglingImagesJob.php b/app/Jobs/DockerCleanupDanglingImagesJob.php index 256016330..f0aeea9f0 100644 --- a/app/Jobs/DockerCleanupDanglingImagesJob.php +++ b/app/Jobs/DockerCleanupDanglingImagesJob.php @@ -14,7 +14,7 @@ class DockerCleanupDanglingImagesJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - + public $timeout = 500; /** * Create a new job instance. */ diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 79e9e140f..72b8912e8 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -115,7 +115,7 @@ function generateSshCommand(string $private_key_location, string $server_ip, str . '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' . '-o PasswordAuthentication=no ' . '-o ConnectTimeout=3600 ' - . '-o ServerAliveInterval=60 ' + . '-o ServerAliveInterval=20 ' . '-o RequestTTY=no ' . '-o LogLevel=ERROR ' . "-p {$port} " diff --git a/config/horizon.php b/config/horizon.php index 256119644..d9f841aa6 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -180,7 +180,7 @@ */ 'defaults' => [ - 'supervisor-1' => [ + 's6' => [ 'connection' => 'redis', 'queue' => ['default'], 'balance' => 'auto', @@ -190,25 +190,27 @@ 'maxJobs' => 0, 'memory' => 128, 'tries' => 1, - 'timeout' => 600, + 'timeout' => 3600, 'nice' => 0, ], ], 'environments' => [ 'production' => [ - 'supervisor-1' => [ + 's6' => [ + 'autoScalingStrategy' => 'size', 'maxProcesses' => env('HORIZON_MAX_PROCESSES', 10), 'balanceMaxShift' => env('HORIZON_BALANCE_MAX_SHIFT', 1), - 'balanceCooldown' => env('HORIZON_BALANCE_COOLDOWN', 3), + 'balanceCooldown' => env('HORIZON_BALANCE_COOLDOWN', 1), ], ], 'local' => [ - 'supervisor-1' => [ + 's6' => [ + 'autoScalingStrategy' => 'size', 'maxProcesses' => env('HORIZON_MAX_PROCESSES', 10), 'balanceMaxShift' => env('HORIZON_BALANCE_MAX_SHIFT', 1), - 'balanceCooldown' => env('HORIZON_BALANCE_COOLDOWN', 3), + 'balanceCooldown' => env('HORIZON_BALANCE_COOLDOWN', 1), ], ], ], diff --git a/docker/dev-ssu/etc/s6-overlay/s6-rc.d/queue-worker/run b/docker/dev-ssu/etc/s6-overlay/s6-rc.d/queue-worker/run index 99e7184e6..0029f9615 100644 --- a/docker/dev-ssu/etc/s6-overlay/s6-rc.d/queue-worker/run +++ b/docker/dev-ssu/etc/s6-overlay/s6-rc.d/queue-worker/run @@ -1,2 +1,2 @@ #!/command/execlineb -P -su - webuser -c "php /var/www/html/artisan queue:listen --timeout=600" +su - webuser -c "php /var/www/html/artisan queue:listen" diff --git a/resources/views/livewire/project/application/get-deployments.blade.php b/resources/views/livewire/project/application/get-deployments.blade.php index 85bd05e67..ac5af3780 100644 --- a/resources/views/livewire/project/application/get-deployments.blade.php +++ b/resources/views/livewire/project/application/get-deployments.blade.php @@ -1,9 +1,10 @@ - $status == 'in_progress' || $status == 'queued', - 'border-error hover:bg-error' => $status == 'error', - 'border-success hover:bg-success' => $status == 'finished', + 'bg-coolgray-200 p-2 border-l border-dashed transition-colors hover:no-underline', + 'border-warning hover:bg-warning hover:text-black' => + $status === 'in_progress', + 'border-primary hover:bg-primary' => $status === 'queued', + 'border-error hover:bg-error' => $status === 'error', + 'border-success hover:bg-success' => $status === 'finished', ]) @if ($status === 'in_progress' || $status === 'queued') wire:poll.5000ms='polling' @endif href="{{ url()->current() }}/{{ $deployment_uuid }}" class="hover:no-underline"> diff --git a/scripts/run b/scripts/run index 44fe4ca7d..c0a3fc069 100755 --- a/scripts/run +++ b/scripts/run @@ -25,6 +25,9 @@ function sync-bunny { function queue { bash vendor/bin/spin exec -u webuser coolify php artisan queue:listen } +function horizon { + bash vendor/bin/spin exec -u webuser coolify php artisan horizon -vvv +} function schedule { bash vendor/bin/spin exec -u webuser coolify php artisan schedule:work } diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore deleted file mode 100644 index d6b7ef32c..000000000 --- a/storage/framework/cache/data/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore