diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php index 981b81378..926d30fe6 100644 --- a/app/Actions/CoolifyTask/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -91,16 +91,9 @@ class RunRemoteProcess } else { if ($processResult->exitCode() == 0) { $status = ProcessStatus::FINISHED; - } - if ($processResult->exitCode() != 0 && ! $this->ignore_errors) { + } else { $status = ProcessStatus::ERROR; } - // if (($processResult->exitCode() == 0 && $this->is_finished) || $this->activity->properties->get('status') === ProcessStatus::FINISHED->value) { - // $status = ProcessStatus::FINISHED; - // } - // if ($processResult->exitCode() != 0 && !$this->ignore_errors) { - // $status = ProcessStatus::ERROR; - // } } $this->activity->properties = $this->activity->properties->merge([ @@ -110,9 +103,6 @@ class RunRemoteProcess 'status' => $status->value, ]); $this->activity->save(); - if ($processResult->exitCode() != 0 && ! $this->ignore_errors) { - throw new \RuntimeException($processResult->errorOutput(), $processResult->exitCode()); - } if ($this->call_event_on_finish) { try { if ($this->call_event_data) { @@ -128,6 +118,9 @@ class RunRemoteProcess Log::error('Error calling event: '.$e->getMessage()); } } + if ($processResult->exitCode() != 0 && ! $this->ignore_errors) { + throw new \RuntimeException($processResult->errorOutput(), $processResult->exitCode()); + } return $processResult; } diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index ffdf771d8..49660f4a8 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -166,8 +166,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue private bool $preserveRepository = false; - public $tries = 1; - public function tags() { // Do not remove this one, it needs to properly identify which worker is running the job diff --git a/app/Livewire/ActivityMonitor.php b/app/Livewire/ActivityMonitor.php index 2e36f34ee..024f53c3d 100644 --- a/app/Livewire/ActivityMonitor.php +++ b/app/Livewire/ActivityMonitor.php @@ -42,14 +42,8 @@ class ActivityMonitor extends Component public function polling() { $this->hydrateActivity(); - // $this->setStatus(ProcessStatus::IN_PROGRESS); $exit_code = data_get($this->activity, 'properties.exitCode'); if ($exit_code !== null) { - // if ($exit_code === 0) { - // // $this->setStatus(ProcessStatus::FINISHED); - // } else { - // // $this->setStatus(ProcessStatus::ERROR); - // } $this->isPollingActive = false; if ($exit_code === 0) { if ($this->eventToDispatch !== null) { @@ -70,12 +64,4 @@ class ActivityMonitor extends Component } } } - - // protected function setStatus($status) - // { - // $this->activity->properties = $this->activity->properties->merge([ - // 'status' => $status, - // ]); - // $this->activity->save(); - // } } diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php index 4a5e8627f..d1744b178 100644 --- a/app/Livewire/Project/Service/Configuration.php +++ b/app/Livewire/Project/Service/Configuration.php @@ -99,7 +99,7 @@ class Configuration extends Component $this->service->databases->each(function ($database) { $database->refresh(); }); - $this->dispatch('$refresh'); + $this->dispatch('refresh'); } catch (\Exception $e) { return handleError($e, $this); } diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php index 22fc1c0d6..915fb54c6 100644 --- a/app/Livewire/Project/Service/Navbar.php +++ b/app/Livewire/Project/Service/Navbar.php @@ -5,6 +5,7 @@ namespace App\Livewire\Project\Service; use App\Actions\Service\StartService; use App\Actions\Service\StopService; use App\Actions\Shared\PullImage; +use App\Enums\ProcessStatus; use App\Events\ServiceStatusChanged; use App\Models\Service; use Illuminate\Support\Facades\Auth; @@ -68,11 +69,9 @@ class Navbar extends Component public function checkDeployments() { try { - // TODO: This is a temporary solution. We need to refactor this. - // We need to delete null bytes somehow. $activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first(); $status = data_get($activity, 'properties.status'); - if ($status === 'queued' || $status === 'in_progress') { + if ($status === ProcessStatus::QUEUED->value || $status === ProcessStatus::IN_PROGRESS->value) { $this->isDeploymentProgress = true; } else { $this->isDeploymentProgress = false; @@ -80,25 +79,46 @@ class Navbar extends Component } catch (\Throwable) { $this->isDeploymentProgress = false; } + + return $this->isDeploymentProgress; } public function start() { - $this->checkDeployments(); - if ($this->isDeploymentProgress) { - $this->dispatch('error', 'There is a deployment in progress.'); - - return; - } $this->service->parse(); $activity = StartService::run($this->service); $this->dispatch('activityMonitor', $activity->id); } - public function stop() + public function forceDeploy() { - StopService::run($this->service, false, $this->docker_cleanup); - ServiceStatusChanged::dispatch(); + try { + $activities = Activity::where('properties->type_uuid', $this->service->uuid)->where('properties->status', ProcessStatus::IN_PROGRESS->value)->orWhere('properties->status', ProcessStatus::QUEUED->value)->get(); + foreach ($activities as $activity) { + $activity->properties->status = ProcessStatus::ERROR->value; + $activity->save(); + } + $this->service->parse(); + $activity = StartService::run($this->service); + $this->dispatch('activityMonitor', $activity->id); + } catch (\Exception $e) { + $this->dispatch('error', $e->getMessage()); + } + } + + public function stop($cleanupContainers = false) + { + try { + StopService::run($this->service, false, $this->docker_cleanup); + ServiceStatusChanged::dispatch(); + if ($cleanupContainers) { + $this->dispatch('success', 'Containers cleaned up.'); + } else { + $this->dispatch('success', 'Service stopped.'); + } + } catch (\Exception $e) { + $this->dispatch('error', $e->getMessage()); + } } public function restart() diff --git a/app/Models/Service.php b/app/Models/Service.php index 1df579802..25e6b92ea 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -1050,10 +1050,11 @@ class Service extends BaseModel $fields->put('MySQL', $data->toArray()); break; case $image->contains('mariadb'): - $userVariables = ['SERVICE_USER_MARIADB', 'SERVICE_USER_WORDPRESS', '_APP_DB_USER', 'SERVICE_USER_MYSQL', 'MYSQL_USER']; + $userVariables = ['SERVICE_USER_MARIADB', 'SERVICE_USER_WORDPRESS', 'SERVICE_USER_MYSQL', 'MYSQL_USER']; $passwordVariables = ['SERVICE_PASSWORD_MARIADB', 'SERVICE_PASSWORD_WORDPRESS', '_APP_DB_PASS', 'MYSQL_PASSWORD']; $rootPasswordVariables = ['SERVICE_PASSWORD_MARIADBROOT', 'SERVICE_PASSWORD_ROOT', '_APP_DB_ROOT_PASS', 'MYSQL_ROOT_PASSWORD']; $dbNameVariables = ['SERVICE_DATABASE_MARIADB', 'SERVICE_DATABASE_WORDPRESS', '_APP_DB_SCHEMA', 'MYSQL_DATABASE']; + $mariadb_user = $this->environment_variables()->whereIn('key', $userVariables)->first(); $mariadb_password = $this->environment_variables()->whereIn('key', $passwordVariables)->first(); $mariadb_root_password = $this->environment_variables()->whereIn('key', $rootPasswordVariables)->first(); @@ -1102,6 +1103,23 @@ class Service extends BaseModel break; } } + $fields = collect($fields)->map(function ($extraFields) { + if (is_array($extraFields)) { + $extraFields = collect($extraFields)->map(function ($field) { + if (filled($field['value']) && str($field['value'])->startsWith('$SERVICE_')) { + $searchValue = str($field['value'])->after('$')->value; + $newValue = $this->environment_variables()->where('key', $searchValue)->first(); + if ($newValue) { + $field['value'] = $newValue->value; + } + } + + return $field; + }); + } + + return $extraFields; + }); return $fields; } diff --git a/app/View/Components/services/advanced.php b/app/View/Components/services/advanced.php new file mode 100644 index 000000000..7e68c6dda --- /dev/null +++ b/app/View/Components/services/advanced.php @@ -0,0 +1,26 @@ + + + Advanced + + @if (str($service->status)->contains('running')) + + @elseif (str($service->status)->contains('degraded')) + + @else + + + @endif + diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php index b90d9e81d..405a6957e 100644 --- a/resources/views/livewire/project/service/navbar.blade.php +++ b/resources/views/livewire/project/service/navbar.blade.php @@ -8,7 +8,7 @@

{{ $title }}

-