2023-06-30 10:49:00 +02:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire\Project\Application;
|
2023-06-30 10:49:00 +02:00
|
|
|
|
2023-10-14 14:22:07 +02:00
|
|
|
use App\Actions\Application\StopApplication;
|
2023-09-14 12:45:50 +02:00
|
|
|
use App\Jobs\ContainerStatusJob;
|
2023-11-17 14:22:05 +01:00
|
|
|
use App\Jobs\ServerStatusJob;
|
2023-06-30 10:49:00 +02:00
|
|
|
use App\Models\Application;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
|
|
|
|
class Heading extends Component
|
|
|
|
{
|
|
|
|
public Application $application;
|
|
|
|
public array $parameters;
|
|
|
|
|
2023-12-04 21:37:30 +01:00
|
|
|
protected string $deploymentUuid;
|
|
|
|
|
2023-06-30 10:49:00 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 15:57:53 +02:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-06-30 10:49:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function check_status()
|
|
|
|
{
|
2023-10-09 15:08:28 +02:00
|
|
|
if ($this->application->destination->server->isFunctional()) {
|
|
|
|
dispatch(new ContainerStatusJob($this->application->destination->server));
|
|
|
|
$this->application->refresh();
|
|
|
|
$this->application->previews->each(function ($preview) {
|
|
|
|
$preview->refresh();
|
|
|
|
});
|
2023-11-17 14:22:05 +01:00
|
|
|
} else {
|
|
|
|
dispatch(new ServerStatusJob($this->application->destination->server));
|
2023-10-09 15:08:28 +02:00
|
|
|
}
|
2023-06-30 10:49:00 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function force_deploy_without_cache()
|
|
|
|
{
|
|
|
|
$this->deploy(force_rebuild: true);
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:08:24 +01:00
|
|
|
public function deployNew()
|
|
|
|
{
|
|
|
|
if ($this->application->build_pack === 'dockercompose' && is_null($this->application->docker_compose_raw)) {
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('error', 'Please load a Compose file first.');
|
2023-12-04 15:08:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->setDeploymentUuid();
|
|
|
|
queue_application_deployment(
|
|
|
|
application_id: $this->application->id,
|
|
|
|
deployment_uuid: $this->deploymentUuid,
|
|
|
|
force_rebuild: false,
|
|
|
|
is_new_deployment: true,
|
|
|
|
);
|
2023-12-07 22:56:55 +01:00
|
|
|
return $this->redirectRoute('project.application.deployment', [
|
2023-12-04 15:08:24 +01:00
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'deployment_uuid' => $this->deploymentUuid,
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
2023-12-07 22:56:55 +01:00
|
|
|
], navigate: true);
|
2023-12-04 15:08:24 +01:00
|
|
|
}
|
2023-06-30 10:49:00 +02:00
|
|
|
public function deploy(bool $force_rebuild = false)
|
|
|
|
{
|
2023-11-27 15:25:15 +01:00
|
|
|
if ($this->application->build_pack === 'dockercompose' && is_null($this->application->docker_compose_raw)) {
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('error', 'Please load a Compose file first.');
|
2023-11-27 11:54:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-06-30 10:49:00 +02:00
|
|
|
$this->setDeploymentUuid();
|
|
|
|
queue_application_deployment(
|
|
|
|
application_id: $this->application->id,
|
|
|
|
deployment_uuid: $this->deploymentUuid,
|
|
|
|
force_rebuild: $force_rebuild,
|
|
|
|
);
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->redirectRoute('project.application.deployment', [
|
2023-06-30 10:49:00 +02:00
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'deployment_uuid' => $this->deploymentUuid,
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
2023-12-07 19:06:32 +01:00
|
|
|
], navigate: true);
|
2023-06-30 10:49:00 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
protected function setDeploymentUuid()
|
2023-06-30 10:49:00 +02:00
|
|
|
{
|
2023-08-08 11:51:36 +02:00
|
|
|
$this->deploymentUuid = new Cuid2(7);
|
|
|
|
$this->parameters['deployment_uuid'] = $this->deploymentUuid;
|
2023-06-30 10:49:00 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-30 10:49:00 +02:00
|
|
|
public function stop()
|
|
|
|
{
|
2023-10-14 14:22:07 +02:00
|
|
|
StopApplication::run($this->application);
|
|
|
|
$this->application->status = 'exited';
|
|
|
|
$this->application->save();
|
2023-09-18 12:38:11 +02:00
|
|
|
$this->application->refresh();
|
2023-06-30 10:49:00 +02:00
|
|
|
}
|
2023-12-04 15:08:24 +01:00
|
|
|
public function restartNew()
|
|
|
|
{
|
|
|
|
$this->setDeploymentUuid();
|
|
|
|
queue_application_deployment(
|
|
|
|
application_id: $this->application->id,
|
|
|
|
deployment_uuid: $this->deploymentUuid,
|
|
|
|
restart_only: true,
|
|
|
|
is_new_deployment: true,
|
|
|
|
);
|
2023-12-07 22:56:55 +01:00
|
|
|
return $this->redirectRoute('project.application.deployment', [
|
2023-12-04 15:08:24 +01:00
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'deployment_uuid' => $this->deploymentUuid,
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
2023-12-07 22:56:55 +01:00
|
|
|
], navigate: true);
|
2023-12-04 15:08:24 +01:00
|
|
|
}
|
2023-11-27 11:54:55 +01:00
|
|
|
public function restart()
|
|
|
|
{
|
2023-11-01 12:19:08 +01:00
|
|
|
$this->setDeploymentUuid();
|
|
|
|
queue_application_deployment(
|
|
|
|
application_id: $this->application->id,
|
|
|
|
deployment_uuid: $this->deploymentUuid,
|
|
|
|
restart_only: true,
|
|
|
|
);
|
2023-12-07 22:56:55 +01:00
|
|
|
return $this->redirectRoute('project.application.deployment', [
|
2023-11-01 12:19:08 +01:00
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'deployment_uuid' => $this->deploymentUuid,
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
2023-12-07 22:56:55 +01:00
|
|
|
], navigate: true);
|
2023-11-01 12:19:08 +01:00
|
|
|
}
|
2023-08-07 22:14:21 +02:00
|
|
|
}
|