This commit is contained in:
Andras Bacsai
2023-05-23 15:48:05 +02:00
parent 8e819485e4
commit 8677b1d85d
11 changed files with 49 additions and 25 deletions

View File

@@ -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();

View File

@@ -27,7 +27,7 @@ class Deploy extends Component
$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()
{

View File

@@ -5,6 +5,7 @@ namespace App\Jobs;
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 Symfony\Component\Yaml\Yaml;
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 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
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}'";

View File

@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Log;
class DockerCleanupDanglingImagesJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 500;
/**
* Create a new job instance.
*/