rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Advanced extends Component
{
@@ -71,9 +72,11 @@ 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)
@@ -127,14 +130,12 @@ class Advanced extends Component
public function instantSave()
{
try {
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.');
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.');
return;
}
return null;
}
if ($this->application->isForceHttpsEnabled() !== $this->isForceHttpsEnabled ||
$this->application->isGzipEnabled() !== $this->isGzipEnabled ||
@@ -151,9 +152,11 @@ 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()
@@ -165,13 +168,15 @@ class Advanced extends Component
$this->gpuDeviceIds = null;
$this->syncData(true);
return;
return null;
}
$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,6 +49,8 @@ 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()
@@ -78,9 +80,9 @@ class Index extends Component
public function previous_page(?int $take = null)
{
if ($take) {
$this->skip = $this->skip - $take;
$this->skip -= $take;
}
$this->skip = $this->skip - $this->default_take;
$this->skip -= $this->default_take;
if ($this->skip < 0) {
$this->show_prev = false;
$this->skip = 0;
@@ -91,7 +93,7 @@ class Index extends Component
public function next_page(?int $take = null)
{
if ($take) {
$this->skip = $this->skip + $take;
$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::where('deployment_uuid', $deploymentUuid)->first();
$application_deployment_queue = ApplicationDeploymentQueue::query()->where('deployment_uuid', $deploymentUuid)->first();
if (! $application_deployment_queue) {
return redirect()->route('project.application.deployment.index', [
'project_uuid' => $project->uuid,
@@ -45,6 +45,8 @@ 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,6 +8,7 @@ use App\Models\ApplicationDeploymentQueue;
use App\Models\Server;
use Illuminate\Support\Carbon;
use Livewire\Component;
use Throwable;
class DeploymentNavbar extends Component
{
@@ -45,9 +46,11 @@ 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()
@@ -57,9 +60,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::find($build_server_id);
$server = Server::query()->find($build_server_id);
} else {
$server = Server::find($server_id);
$server = Server::query()->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);
@@ -78,7 +81,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([
@@ -87,5 +90,7 @@ class DeploymentNavbar extends Component
]);
next_after_cancel($server);
}
return null;
}
}

View File

@@ -6,7 +6,9 @@ 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
@@ -141,7 +143,7 @@ class General extends Component
return;
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->dispatch('error', $e->getMessage());
}
if ($this->application->build_pack === 'dockercompose') {
@@ -179,13 +181,11 @@ 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) {
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();
});
}
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();
});
}
}
@@ -193,7 +193,7 @@ class General extends Component
{
try {
if ($isInit && $this->application->docker_compose_raw) {
return;
return null;
}
// 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;
return null;
}
$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,12 +219,14 @@ class General extends Component
} finally {
$this->initLoadingCompose = false;
}
return null;
}
public function generateDomain(string $serviceName)
{
$uuid = new Cuid2;
$domain = generateFqdn($this->application->destination->server, $uuid);
$cuid2 = new Cuid2;
$domain = generateFqdn($this->application->destination->server, $cuid2);
$this->parsedServiceDomains[$serviceName]['domain'] = $domain;
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
$this->application->save();
@@ -295,7 +297,7 @@ class General extends Component
{
try {
if ($this->application->settings->is_container_label_readonly_enabled && ! $manualReset) {
return;
return null;
}
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
$this->ports_exposes = $this->application->ports_exposes;
@@ -306,9 +308,11 @@ 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)
@@ -334,14 +338,16 @@ 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;
return null;
}
$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)
@@ -377,8 +383,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 \Livewire\Features\SupportEvents\Event) {
return;
if ($compose_return instanceof Event) {
return null;
}
}
$this->validate();
@@ -410,8 +416,8 @@ class General extends Component
if ($this->application->build_pack === 'dockercompose') {
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
foreach ($this->parsedServiceDomains as $serviceName => $service) {
$domain = data_get($service, 'domain');
foreach ($this->parsedServiceDomains as $parsedServiceDomain) {
$domain = data_get($parsedServiceDomain, '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.");
@@ -425,8 +431,10 @@ class General extends Component
}
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
} catch (\Throwable $e) {
if ($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;
@@ -436,6 +444,8 @@ 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;
return null;
}
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;
return null;
}
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;
return null;
}
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;
return null;
}
$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;
return null;
}
$this->setDeploymentUuid();
queue_application_deployment(

View File

@@ -6,6 +6,7 @@ use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
class Form extends Component
{
@@ -19,9 +20,11 @@ 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()
@@ -33,9 +36,11 @@ 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()
@@ -46,9 +51,11 @@ 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,11 +6,13 @@ 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
@@ -41,11 +43,13 @@ 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)
@@ -65,13 +69,19 @@ class Previews extends Component
}
if (! $preview) {
throw new \Exception('Preview not found');
throw new Exception('Preview not found');
}
$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) {
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) {
return handleError($e, $this);
}
return null;
}
public function generate_preview($preview_id)
@@ -95,8 +105,8 @@ class Previews extends Component
$template = $this->application->preview_url_template;
$host = $url->getHost();
$schema = $url->getScheme();
$random = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $random, $template);
$cuid2 = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $cuid2, $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";
@@ -110,9 +120,9 @@ class Previews extends Component
try {
if ($this->application->build_pack === 'dockercompose') {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
$found = ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -123,9 +133,9 @@ class Previews extends Component
$this->application->refresh();
} else {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
$found = ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -136,9 +146,11 @@ 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)
@@ -151,9 +163,9 @@ class Previews extends Component
{
try {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
ApplicationPreview::create([
ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -173,7 +185,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);
}
}
@@ -201,9 +213,11 @@ 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)
@@ -219,7 +233,7 @@ class Previews extends Component
$this->stopContainers($containers, $server, $timeout);
}
ApplicationPreview::where('application_id', $this->application->id)
ApplicationPreview::query()->where('application_id', $this->application->id)
->where('pull_request_id', $pull_request_id)
->first()
->delete();
@@ -227,9 +241,11 @@ 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)
@@ -241,7 +257,7 @@ class Previews extends Component
}
$startTime = Carbon::now()->getTimestamp();
while (count($processes) > 0) {
while ($processes !== []) {
$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();
$random = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $random, $template);
$cuid2 = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $cuid2, $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,6 +4,7 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Component;
use Throwable;
use Visus\Cuid2\Cuid2;
class Rollback extends Component
@@ -23,11 +24,11 @@ class Rollback extends Component
public function rollbackImage($commit)
{
$deployment_uuid = new Cuid2;
$cuid2 = new Cuid2;
queue_application_deployment(
application: $this->application,
deployment_uuid: $deployment_uuid,
deployment_uuid: $cuid2,
commit: $commit,
rollback: true,
force_rebuild: false,
@@ -36,7 +37,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' => $deployment_uuid,
'deployment_uuid' => $cuid2,
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
@@ -73,7 +74,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,6 +7,7 @@ use App\Models\PrivateKey;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Source extends Component
{
@@ -35,7 +36,7 @@ class Source extends Component
try {
$this->syncData();
$this->getPrivateKeys();
} catch (\Throwable $e) {
} catch (Throwable $e) {
handleError($e, $this);
}
}
@@ -75,9 +76,11 @@ 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()
@@ -88,8 +91,10 @@ 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,6 +5,7 @@ namespace App\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Swarm extends Component
{
@@ -23,9 +24,11 @@ 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)
@@ -53,9 +56,11 @@ 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()
@@ -63,9 +68,11 @@ 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()