diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php index da09403cc..d6ae7eec8 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -2,6 +2,7 @@ namespace App\Actions\Proxy; +use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Support\Str; use Lorisleiva\Actions\Concerns\AsAction; @@ -14,7 +15,7 @@ class StartProxy { $commands = collect([]); $proxyType = $server->proxyType(); - if ($proxyType === 'none') { + if ($proxyType === ProxyTypes::NONE->value) { return 'OK'; } $proxy_path = get_proxy_path(); diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php index 3203f9b05..6fd74025c 100644 --- a/app/Actions/Server/UpdateCoolify.php +++ b/app/Actions/Server/UpdateCoolify.php @@ -2,16 +2,18 @@ namespace App\Actions\Server; +use Lorisleiva\Actions\Concerns\AsAction; use App\Models\InstanceSettings; use App\Models\Server; class UpdateCoolify { + use AsAction; public ?Server $server = null; public ?string $latestVersion = null; public ?string $currentVersion = null; - public function __invoke(bool $force) + public function handle(bool $force) { try { $settings = InstanceSettings::get(); diff --git a/app/Console/Commands/ResourcesDelete.php b/app/Console/Commands/ResourcesDelete.php index 56e680642..3b0134f47 100644 --- a/app/Console/Commands/ResourcesDelete.php +++ b/app/Console/Commands/ResourcesDelete.php @@ -58,8 +58,8 @@ class ResourcesDelete extends Command $servers->pluck('id')->sort()->toArray(), ); - foreach ($serversToDelete as $server) { - $toDelete = $servers->where('id', $server)->first(); + foreach ($serversToDelete as $id) { + $toDelete = Server::find($id); $this->info($toDelete); $confirmed = confirm("Are you sure you want to delete all selected resources?"); if (!$confirmed) { diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.php index 687732540..fba473250 100644 --- a/app/Http/Livewire/Project/Service/Index.php +++ b/app/Http/Livewire/Project/Service/Index.php @@ -13,13 +13,7 @@ class Index extends Component public $databases; public array $parameters; public array $query; - protected $rules = [ - 'service.docker_compose_raw' => 'required', - 'service.docker_compose' => 'required', - 'service.name' => 'required', - 'service.description' => 'nullable', - ]; - protected $listeners = ["saveCompose"]; + protected $listeners = ["refreshStacks","checkStatus"]; public function render() { return view('livewire.project.service.index'); @@ -32,17 +26,12 @@ class Index extends Component $this->applications = $this->service->applications->sort(); $this->databases = $this->service->databases->sort(); } - public function saveCompose($raw) - { - $this->service->docker_compose_raw = $raw; - $this->submit(); - } public function checkStatus() { dispatch_sync(new ContainerStatusJob($this->service->server)); - $this->refreshStack(); + $this->refreshStacks(); } - public function refreshStack() + public function refreshStacks() { $this->applications = $this->service->applications->sort(); $this->applications->each(function ($application) { @@ -53,21 +42,4 @@ class Index extends Component $database->refresh(); }); } - - - public function submit() - { - try { - $this->validate(); - $this->service->save(); - $this->service->parse(); - $this->service->refresh(); - $this->service->saveComposeConfigs(); - $this->refreshStack(); - $this->emit('refreshEnvs'); - $this->emit('success', 'Service saved successfully.'); - } catch (\Throwable $e) { - return handleError($e, $this); - } - } } diff --git a/app/Http/Livewire/Project/Service/Modal.php b/app/Http/Livewire/Project/Service/Modal.php index a5fd759e7..7092070f6 100644 --- a/app/Http/Livewire/Project/Service/Modal.php +++ b/app/Http/Livewire/Project/Service/Modal.php @@ -6,8 +6,8 @@ use Livewire\Component; class Modal extends Component { - public function serviceStatusUpdated() { - $this->emit('serviceStatusUpdated'); + public function checkStatus() { + $this->emit('checkStatus'); } public function render() { diff --git a/app/Http/Livewire/Project/Service/Navbar.php b/app/Http/Livewire/Project/Service/Navbar.php index 3f7679c56..d85c6f435 100644 --- a/app/Http/Livewire/Project/Service/Navbar.php +++ b/app/Http/Livewire/Project/Service/Navbar.php @@ -13,20 +13,15 @@ class Navbar extends Component public Service $service; public array $parameters; public array $query; - protected $listeners = ['serviceStatusUpdated']; public function render() { return view('livewire.project.service.navbar'); } - public function serviceStatusUpdated() + + public function checkStatus() { - $this->check_status(); - } - public function check_status() - { - dispatch_sync(new ContainerStatusJob($this->service->server)); - $this->service->refresh(); + $this->emit('checkStatus'); } public function deploy() { diff --git a/app/Http/Livewire/Project/Service/StackForm.php b/app/Http/Livewire/Project/Service/StackForm.php new file mode 100644 index 000000000..1518e3d22 --- /dev/null +++ b/app/Http/Livewire/Project/Service/StackForm.php @@ -0,0 +1,42 @@ + 'required', + 'service.docker_compose' => 'required', + 'service.name' => 'required', + 'service.description' => 'nullable', + ]; + public $service; + public function saveCompose($raw) + { + $this->service->docker_compose_raw = $raw; + $this->submit(); + } + + public function submit() + { + try { + $this->validate(); + $this->service->save(); + $this->service->parse(); + $this->service->refresh(); + $this->service->saveComposeConfigs(); + $this->emit('refreshStacks'); + $this->emit('refreshEnvs'); + $this->emit('success', 'Service saved successfully.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.project.service.stack-form'); + } +} diff --git a/app/Http/Livewire/Upgrade.php b/app/Http/Livewire/Upgrade.php index ca5f7df30..fc930a997 100644 --- a/app/Http/Livewire/Upgrade.php +++ b/app/Http/Livewire/Upgrade.php @@ -37,7 +37,7 @@ class Upgrade extends Component return; } $this->showProgress = true; - resolve(UpdateCoolify::class)(true); + UpdateCoolify::run(true); $this->emit('success', "Upgrading to {$this->latestVersion} version..."); } catch (\Throwable $e) { return handleError($e, $this); diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 33324620a..2993a4630 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -184,41 +184,42 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } } - private function deploy_docker_compose() - { - $dockercompose_base64 = base64_encode($this->application->dockercompose); - $this->execute_remote_command( - [ - "echo 'Starting deployment of {$this->application->name}.'" - ], - ); - $this->prepare_builder_image(); - $this->execute_remote_command( - [ - executeInDocker($this->deployment_uuid, "echo '$dockercompose_base64' | base64 -d > $this->workdir/docker-compose.yaml") - ], - ); - $this->build_image_name = Str::lower("{$this->application->git_repository}:build"); - $this->production_image_name = Str::lower("{$this->application->uuid}:latest"); - $this->save_environment_variables(); - $containers = getCurrentApplicationContainerStatus($this->application->destination->server, $this->application->id); - if ($containers->count() > 0) { - foreach ($containers as $container) { - $containerName = data_get($container, 'Names'); - if ($containerName) { - instant_remote_process( - ["docker rm -f {$containerName}"], - $this->application->destination->server - ); - } - } - } + // private function deploy_docker_compose() + // { + // $dockercompose_base64 = base64_encode($this->application->dockercompose); + // $this->execute_remote_command( + // [ + // "echo 'Starting deployment of {$this->application->name}.'" + // ], + // ); + // $this->prepare_builder_image(); + // $this->execute_remote_command( + // [ + // executeInDocker($this->deployment_uuid, "echo '$dockercompose_base64' | base64 -d > $this->workdir/docker-compose.yaml") + // ], + // ); + // $this->build_image_name = Str::lower("{$this->application->git_repository}:build"); + // $this->production_image_name = Str::lower("{$this->application->uuid}:latest"); + // $this->save_environment_variables(); + // $containers = getCurrentApplicationContainerStatus($this->application->destination->server, $this->application->id); + // ray($containers); + // if ($containers->count() > 0) { + // foreach ($containers as $container) { + // $containerName = data_get($container, 'Names'); + // if ($containerName) { + // instant_remote_process( + // ["docker rm -f {$containerName}"], + // $this->application->destination->server + // ); + // } + // } + // } - $this->execute_remote_command( - ["echo -n 'Starting services (could take a while)...'"], - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up -d"), "hidden" => true], - ); - } + // $this->execute_remote_command( + // ["echo -n 'Starting services (could take a while)...'"], + // [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up -d"), "hidden" => true], + // ); + // } private function save_environment_variables() { $envs = collect([]); diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index c5c455472..9b4ef5699 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -29,7 +29,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function __construct(public Server $server) { - $this->handle(); + } public function middleware(): array @@ -44,7 +44,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function handle() { try { - ray("checking server status for {$this->server->name}"); + ray("checking server status for {$this->server->id}"); // ray()->clearAll(); $serverUptimeCheckNumber = $this->server->unreachable_count; $serverUptimeCheckNumberMax = 3; @@ -114,7 +114,6 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted return data_get($value, 'Name') === '/coolify-proxy'; })->first(); if (!$foundProxyContainer) { - ray('Proxy not found, starting it...'); if ($this->server->isProxyShouldRun()) { StartProxy::run($this->server, false); $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server)); diff --git a/app/Jobs/InstanceAutoUpdateJob.php b/app/Jobs/InstanceAutoUpdateJob.php index 814ae9cc9..99e0a34f3 100644 --- a/app/Jobs/InstanceAutoUpdateJob.php +++ b/app/Jobs/InstanceAutoUpdateJob.php @@ -23,6 +23,6 @@ class InstanceAutoUpdateJob implements ShouldQueue, ShouldBeUnique, ShouldBeEncr public function handle(): void { - resolve(UpdateCoolify::class)($this->force); + UpdateCoolify::run($this->force); } } diff --git a/app/Models/Server.php b/app/Models/Server.php index a53d6ffe5..313040afa 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -93,8 +93,11 @@ class Server extends BaseModel public function proxyType() { - $type = $this->proxy->get('type'); - if (is_null($type)) { + $proxyType = $this->proxy->get('type'); + if ($proxyType === ProxyTypes::NONE->value) { + return $proxyType; + } + if (is_null($proxyType)) { $this->proxy->type = ProxyTypes::TRAEFIK_V2->value; $this->proxy->status = ProxyStatus::EXITED->value; $this->save(); diff --git a/config/sentry.php b/config/sentry.php index 6db015a9e..dce75c07d 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.79', + 'release' => '4.0.0-beta.80', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 06159e722..62840667b 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ "coolify-testing-host", 'team_id' => 0, 'private_key_id' => 0, - // 'proxy' => ServerMetadata::from([ - // 'type' => ProxyTypes::TRAEFIK_V2->value, - // 'status' => ProxyStatus::EXITED->value - // ]), ]); } } diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index 8230c3a7c..fbbdc545b 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -2,7 +2,9 @@

Server

- + @if ($server->proxyType() !== 'NONE') + + @endif
{{ data_get($server, 'name') }}