2023-06-30 08:49:00 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
namespace App\Http\Livewire\Project\Application;
|
2023-06-30 08:49:00 +00:00
|
|
|
|
2023-09-14 10:45:50 +00:00
|
|
|
use App\Jobs\ContainerStatusJob;
|
2023-06-30 08:49:00 +00:00
|
|
|
use App\Models\Application;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
|
|
|
|
class Heading extends Component
|
|
|
|
{
|
|
|
|
public Application $application;
|
|
|
|
public array $parameters;
|
|
|
|
|
|
|
|
protected string $deploymentUuid;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-06-30 08:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function check_status()
|
|
|
|
{
|
2023-09-19 13:51:13 +00:00
|
|
|
dispatch(new ContainerStatusJob($this->application->destination->server));
|
2023-06-30 08:49:00 +00:00
|
|
|
$this->application->refresh();
|
2023-09-14 13:52:04 +00:00
|
|
|
$this->application->previews->each(function ($preview) {
|
|
|
|
$preview->refresh();
|
|
|
|
});
|
2023-06-30 08:49:00 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function force_deploy_without_cache()
|
|
|
|
{
|
|
|
|
$this->deploy(force_rebuild: true);
|
|
|
|
}
|
|
|
|
|
2023-06-30 08:49:00 +00:00
|
|
|
public function deploy(bool $force_rebuild = false)
|
|
|
|
{
|
|
|
|
$this->setDeploymentUuid();
|
|
|
|
queue_application_deployment(
|
|
|
|
application_id: $this->application->id,
|
|
|
|
deployment_uuid: $this->deploymentUuid,
|
|
|
|
force_rebuild: $force_rebuild,
|
|
|
|
);
|
|
|
|
return redirect()->route('project.application.deployment', [
|
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'deployment_uuid' => $this->deploymentUuid,
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
protected function setDeploymentUuid()
|
2023-06-30 08:49:00 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
$this->deploymentUuid = new Cuid2(7);
|
|
|
|
$this->parameters['deployment_uuid'] = $this->deploymentUuid;
|
2023-06-30 08:49:00 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-30 08:49:00 +00:00
|
|
|
public function stop()
|
|
|
|
{
|
2023-08-21 16:00:12 +00:00
|
|
|
$containers = getCurrentApplicationContainerStatus($this->application->destination->server, $this->application->id);
|
|
|
|
if ($containers->count() === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach ($containers as $container) {
|
|
|
|
$containerName = data_get($container, 'Names');
|
|
|
|
if ($containerName) {
|
2023-09-20 13:42:41 +00:00
|
|
|
instant_remote_process(
|
2023-08-21 16:00:12 +00:00
|
|
|
["docker rm -f {$containerName}"],
|
|
|
|
$this->application->destination->server
|
|
|
|
);
|
2023-09-18 10:38:11 +00:00
|
|
|
$this->application->status = 'exited';
|
2023-08-21 16:00:12 +00:00
|
|
|
$this->application->save();
|
2023-08-27 12:53:16 +00:00
|
|
|
// $this->application->environment->project->team->notify(new StatusChanged($this->application));
|
2023-08-21 16:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 10:38:11 +00:00
|
|
|
$this->application->refresh();
|
2023-06-30 08:49:00 +00:00
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|