Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -5,7 +5,6 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Advanced extends Component
{
@@ -72,11 +71,9 @@ class Advanced extends Component
{
try {
$this->syncData();
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -130,12 +127,14 @@ class Advanced extends Component
public function instantSave()
{
try {
if ($this->isLogDrainEnabled && ! $this->application->destination->server->isLogDrainEnabled()) {
$this->isLogDrainEnabled = false;
$this->syncData(true);
$this->dispatch('error', 'Log drain is not enabled on this server.');
if ($this->isLogDrainEnabled) {
if (! $this->application->destination->server->isLogDrainEnabled()) {
$this->isLogDrainEnabled = false;
$this->syncData(true);
$this->dispatch('error', 'Log drain is not enabled on this server.');
return null;
return;
}
}
if ($this->application->isForceHttpsEnabled() !== $this->isForceHttpsEnabled ||
$this->application->isGzipEnabled() !== $this->isGzipEnabled ||
@@ -152,11 +151,9 @@ class Advanced extends Component
$this->syncData(true);
$this->dispatch('success', 'Settings saved.');
$this->dispatch('configurationChanged');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -168,15 +165,13 @@ class Advanced extends Component
$this->gpuDeviceIds = null;
$this->syncData(true);
return null;
return;
}
$this->syncData(true);
$this->dispatch('success', 'Settings saved.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function saveCustomName()

View File

@@ -49,8 +49,6 @@ class Index extends Component
$this->current_url = url()->current();
$this->show_pull_request_only();
$this->show_more();
return null;
}
private function show_pull_request_only()
@@ -80,9 +78,9 @@ class Index extends Component
public function previous_page(?int $take = null)
{
if ($take) {
$this->skip -= $take;
$this->skip = $this->skip - $take;
}
$this->skip -= $this->default_take;
$this->skip = $this->skip - $this->default_take;
if ($this->skip < 0) {
$this->show_prev = false;
$this->skip = 0;
@@ -93,7 +91,7 @@ class Index extends Component
public function next_page(?int $take = null)
{
if ($take) {
$this->skip += $take;
$this->skip = $this->skip + $take;
}
$this->show_prev = true;
$this->load_deployments();

View File

@@ -34,7 +34,7 @@ class Show extends Component
if (! $application) {
return redirect()->route('dashboard');
}
$application_deployment_queue = ApplicationDeploymentQueue::query()->where('deployment_uuid', $deploymentUuid)->first();
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (! $application_deployment_queue) {
return redirect()->route('project.application.deployment.index', [
'project_uuid' => $project->uuid,
@@ -45,8 +45,6 @@ class Show extends Component
$this->application = $application;
$this->application_deployment_queue = $application_deployment_queue;
$this->deployment_uuid = $deploymentUuid;
return null;
}
public function refreshQueue()

View File

@@ -8,7 +8,6 @@ use App\Models\ApplicationDeploymentQueue;
use App\Models\Server;
use Illuminate\Support\Carbon;
use Livewire\Component;
use Throwable;
class DeploymentNavbar extends Component
{
@@ -46,11 +45,9 @@ class DeploymentNavbar extends Component
{
try {
force_start_deployment($this->application_deployment_queue);
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function cancel()
@@ -60,9 +57,9 @@ class DeploymentNavbar extends Component
$server_id = $this->application_deployment_queue->server_id ?? $this->application->destination->server_id;
try {
if ($this->application->settings->is_build_server_enabled) {
$server = Server::query()->find($build_server_id);
$server = Server::find($build_server_id);
} else {
$server = Server::query()->find($server_id);
$server = Server::find($server_id);
}
if ($this->application_deployment_queue->logs) {
$previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR);
@@ -81,7 +78,7 @@ class DeploymentNavbar extends Component
]);
}
instant_remote_process([$kill_command], $server);
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
$this->application_deployment_queue->update([
@@ -90,7 +87,5 @@ class DeploymentNavbar extends Component
]);
next_after_cancel($server);
}
return null;
}
}

View File

@@ -6,9 +6,7 @@ use App\Actions\Application\GenerateConfig;
use App\Models\Application;
use Illuminate\Support\Collection;
use Livewire\Component;
use Livewire\Features\SupportEvents\Event;
use Spatie\Url\Url;
use Throwable;
use Visus\Cuid2\Cuid2;
class General extends Component
@@ -143,7 +141,7 @@ class General extends Component
return;
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->dispatch('error', $e->getMessage());
}
if ($this->application->build_pack === 'dockercompose') {
@@ -181,11 +179,13 @@ class General extends Component
if ($this->ports_exposes !== $this->application->ports_exposes || $this->is_container_label_escape_enabled !== $this->application->settings->is_container_label_escape_enabled) {
$this->resetDefaultLabels(false);
}
if ($this->is_preserve_repository_enabled !== $this->application->settings->is_preserve_repository_enabled && $this->application->settings->is_preserve_repository_enabled === false) {
$this->application->fileStorages->each(function ($storage) {
$storage->is_based_on_git = $this->application->settings->is_preserve_repository_enabled;
$storage->save();
});
if ($this->is_preserve_repository_enabled !== $this->application->settings->is_preserve_repository_enabled) {
if ($this->application->settings->is_preserve_repository_enabled === false) {
$this->application->fileStorages->each(function ($storage) {
$storage->is_based_on_git = $this->application->settings->is_preserve_repository_enabled;
$storage->save();
});
}
}
}
@@ -193,7 +193,7 @@ class General extends Component
{
try {
if ($isInit && $this->application->docker_compose_raw) {
return null;
return;
}
// Must reload the application to get the latest database changes
@@ -204,14 +204,14 @@ class General extends Component
if (is_null($this->parsedServices)) {
$this->dispatch('error', 'Failed to parse your docker-compose file. Please check the syntax and try again.');
return null;
return;
}
$this->application->parse();
$this->dispatch('success', 'Docker compose file loaded.');
$this->dispatch('compose_loaded');
$this->dispatch('refreshStorages');
$this->dispatch('refreshEnvs');
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->application->docker_compose_location = $this->initialDockerComposeLocation;
$this->application->save();
@@ -219,14 +219,12 @@ class General extends Component
} finally {
$this->initLoadingCompose = false;
}
return null;
}
public function generateDomain(string $serviceName)
{
$cuid2 = new Cuid2;
$domain = generateFqdn($this->application->destination->server, $cuid2);
$uuid = new Cuid2;
$domain = generateFqdn($this->application->destination->server, $uuid);
$this->parsedServiceDomains[$serviceName]['domain'] = $domain;
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
$this->application->save();
@@ -297,7 +295,7 @@ class General extends Component
{
try {
if ($this->application->settings->is_container_label_readonly_enabled && ! $manualReset) {
return null;
return;
}
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
$this->ports_exposes = $this->application->ports_exposes;
@@ -308,11 +306,9 @@ class General extends Component
$this->loadComposeFile();
}
$this->dispatch('configurationChanged');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function checkFqdns($showToaster = true)
@@ -338,16 +334,14 @@ class General extends Component
if ($has_www === 0 && $this->application->redirect === 'www') {
$this->dispatch('error', 'You want to redirect to www, but you do not have a www domain set.<br><br>Please add www to your domain list and as an A DNS record (if applicable).');
return null;
return;
}
$this->application->save();
$this->resetDefaultLabels();
$this->dispatch('success', 'Redirect updated.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit($showToaster = true)
@@ -383,8 +377,8 @@ class General extends Component
if ($this->application->build_pack === 'dockercompose' && $this->initialDockerComposeLocation !== $this->application->docker_compose_location) {
$compose_return = $this->loadComposeFile();
if ($compose_return instanceof Event) {
return null;
if ($compose_return instanceof \Livewire\Features\SupportEvents\Event) {
return;
}
}
$this->validate();
@@ -416,8 +410,8 @@ class General extends Component
if ($this->application->build_pack === 'dockercompose') {
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
foreach ($this->parsedServiceDomains as $parsedServiceDomain) {
$domain = data_get($parsedServiceDomain, 'domain');
foreach ($this->parsedServiceDomains as $serviceName => $service) {
$domain = data_get($service, 'domain');
if ($domain) {
if (! validate_dns_entry($domain, $this->application->destination->server)) {
$showToaster && $this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$domain->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
@@ -431,10 +425,8 @@ class General extends Component
}
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
if ($showToaster && ! $warning) {
$this->dispatch('success', 'Application settings updated!');
}
} catch (Throwable $e) {
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
} catch (\Throwable $e) {
$originalFqdn = $this->application->getOriginal('fqdn');
if ($originalFqdn !== $this->application->fqdn) {
$this->application->fqdn = $originalFqdn;
@@ -444,8 +436,6 @@ class General extends Component
} finally {
$this->dispatch('configurationChanged');
}
return null;
}
public function downloadConfig()

View File

@@ -66,22 +66,22 @@ class Heading extends Component
if ($this->application->build_pack === 'dockercompose' && is_null($this->application->docker_compose_raw)) {
$this->dispatch('error', 'Failed to deploy', 'Please load a Compose file first.');
return null;
return;
}
if ($this->application->destination->server->isSwarm() && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'To deploy to a Swarm cluster you must set a Docker image name first.');
return null;
return;
}
if (data_get($this->application, 'settings.is_build_server_enabled') && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'To use a build server, you must first set a Docker image.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/build-server">documentation</a>');
return null;
return;
}
if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return null;
return;
}
$this->setDeploymentUuid();
queue_application_deployment(
@@ -123,7 +123,7 @@ class Heading extends Component
if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return null;
return;
}
$this->setDeploymentUuid();
queue_application_deployment(

View File

@@ -6,7 +6,6 @@ use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
class Form extends Component
{
@@ -20,11 +19,9 @@ class Form extends Component
try {
$this->previewUrlTemplate = $this->application->preview_url_template;
$this->generateRealUrl();
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -36,11 +33,9 @@ class Form extends Component
$this->application->save();
$this->dispatch('success', 'Preview url template updated.');
$this->generateRealUrl();
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function resetToDefault()
@@ -51,11 +46,9 @@ class Form extends Component
$this->application->save();
$this->generateRealUrl();
$this->dispatch('success', 'Preview url template updated.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function generateRealUrl()

View File

@@ -6,13 +6,11 @@ use App\Actions\Docker\GetContainersStatus;
use App\Models\Application;
use App\Models\ApplicationPreview;
use Carbon\Carbon;
use Exception;
use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
use Visus\Cuid2\Cuid2;
class Previews extends Component
@@ -43,13 +41,11 @@ class Previews extends Component
['rate_limit_remaining' => $rate_limit_remaining, 'data' => $data] = githubApi(source: $this->application->source, endpoint: "/repos/{$this->application->git_repository}/pulls");
$this->rate_limit_remaining = $rate_limit_remaining;
$this->pull_requests = $data->sortBy('number')->values();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->rate_limit_remaining = 0;
return handleError($e, $this);
}
return null;
}
public function save_preview($preview_id)
@@ -69,19 +65,13 @@ class Previews extends Component
}
if (! $preview) {
throw new Exception('Preview not found');
throw new \Exception('Preview not found');
}
if ($success) {
$preview->save();
}
if ($success) {
$this->dispatch('success', 'Preview saved.<br><br>Do not forget to redeploy the preview to apply the changes.');
}
} catch (Throwable $e) {
$success && $preview->save();
$success && $this->dispatch('success', 'Preview saved.<br><br>Do not forget to redeploy the preview to apply the changes.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function generate_preview($preview_id)
@@ -105,8 +95,8 @@ class Previews extends Component
$template = $this->application->preview_url_template;
$host = $url->getHost();
$schema = $url->getScheme();
$cuid2 = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $cuid2, $template);
$random = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $random, $template);
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
$preview_fqdn = str_replace('{{pr_id}}', $preview->pull_request_id, $preview_fqdn);
$preview_fqdn = "$schema://$preview_fqdn";
@@ -120,9 +110,9 @@ class Previews extends Component
try {
if ($this->application->build_pack === 'dockercompose') {
$this->setDeploymentUuid();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::query()->create([
$found = ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -133,9 +123,9 @@ class Previews extends Component
$this->application->refresh();
} else {
$this->setDeploymentUuid();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::query()->create([
$found = ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -146,11 +136,9 @@ class Previews extends Component
$this->dispatch('update_links');
$this->dispatch('success', 'Preview added.');
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function add_and_deploy(int $pull_request_id, ?string $pull_request_html_url = null)
@@ -163,9 +151,9 @@ class Previews extends Component
{
try {
$this->setDeploymentUuid();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
ApplicationPreview::query()->create([
ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -185,7 +173,7 @@ class Previews extends Component
'deployment_uuid' => $this->deployment_uuid,
'environment_uuid' => $this->parameters['environment_uuid'],
]);
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
@@ -213,11 +201,9 @@ class Previews extends Component
$this->application->refresh();
$this->dispatch('containerStatusUpdated');
$this->dispatch('success', 'Preview Deployment stopped.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function delete(int $pull_request_id)
@@ -233,7 +219,7 @@ class Previews extends Component
$this->stopContainers($containers, $server, $timeout);
}
ApplicationPreview::query()->where('application_id', $this->application->id)
ApplicationPreview::where('application_id', $this->application->id)
->where('pull_request_id', $pull_request_id)
->first()
->delete();
@@ -241,11 +227,9 @@ class Previews extends Component
$this->application->refresh();
$this->dispatch('update_links');
$this->dispatch('success', 'Preview deleted.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
private function stopContainers(array $containers, $server, int $timeout)
@@ -257,7 +241,7 @@ class Previews extends Component
}
$startTime = Carbon::now()->getTimestamp();
while ($processes !== []) {
while (count($processes) > 0) {
$finishedProcesses = array_filter($processes, function ($process) {
return ! $process->running();
});

View File

@@ -44,8 +44,8 @@ class PreviewsCompose extends Component
$template = $this->preview->application->preview_url_template;
$host = $url->getHost();
$schema = $url->getScheme();
$cuid2 = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $cuid2, $template);
$random = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $random, $template);
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
$preview_fqdn = str_replace('{{pr_id}}', $this->preview->pull_request_id, $preview_fqdn);
$preview_fqdn = "$schema://$preview_fqdn";

View File

@@ -4,7 +4,6 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Component;
use Throwable;
use Visus\Cuid2\Cuid2;
class Rollback extends Component
@@ -24,11 +23,11 @@ class Rollback extends Component
public function rollbackImage($commit)
{
$cuid2 = new Cuid2;
$deployment_uuid = new Cuid2;
queue_application_deployment(
application: $this->application,
deployment_uuid: $cuid2,
deployment_uuid: $deployment_uuid,
commit: $commit,
rollback: true,
force_rebuild: false,
@@ -37,7 +36,7 @@ class Rollback extends Component
return redirect()->route('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $cuid2,
'deployment_uuid' => $deployment_uuid,
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
@@ -74,7 +73,7 @@ class Rollback extends Component
$showToast && $this->dispatch('success', 'Images loaded.');
return [];
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -7,7 +7,6 @@ use App\Models\PrivateKey;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Source extends Component
{
@@ -36,7 +35,7 @@ class Source extends Component
try {
$this->syncData();
$this->getPrivateKeys();
} catch (Throwable $e) {
} catch (\Throwable $e) {
handleError($e, $this);
}
}
@@ -76,11 +75,9 @@ class Source extends Component
$this->application->refresh();
$this->privateKeyName = $this->application->private_key->name;
$this->dispatch('success', 'Private key updated!');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -91,10 +88,8 @@ class Source extends Component
}
$this->syncData(true);
$this->dispatch('success', 'Application source updated!');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Swarm extends Component
{
@@ -24,11 +23,9 @@ class Swarm extends Component
{
try {
$this->syncData();
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -56,11 +53,9 @@ class Swarm extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Swarm settings updated.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -68,11 +63,9 @@ class Swarm extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Swarm settings updated.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()