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

@@ -7,9 +7,11 @@ use App\Models\Project;
use App\Models\Service;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Exception;
use Illuminate\Support\Str;
use Livewire\Component;
use Symfony\Component\Yaml\Yaml;
use Throwable;
class DockerCompose extends Component
{
@@ -58,20 +60,20 @@ class DockerCompose extends Component
return $this->dispatch('error', "Invalid docker-compose file.\n$isValid");
}
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$service = Service::create([
$service = Service::query()->create([
'name' => 'service'.Str::random(10),
'docker_compose_raw' => $this->dockerComposeRaw,
'environment_id' => $environment->id,
@@ -82,7 +84,7 @@ class DockerCompose extends Component
$variables = parseEnvFormatToArray($this->envFile);
foreach ($variables as $key => $variable) {
EnvironmentVariable::create([
EnvironmentVariable::query()->create([
'key' => $key,
'value' => $variable,
'is_build_time' => false,
@@ -100,7 +102,7 @@ class DockerCompose extends Component
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Application;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Exception;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@@ -28,32 +29,28 @@ class DockerImage extends Component
$this->validate([
'dockerImage' => 'required',
]);
$image = str($this->dockerImage)->before(':');
if (str($this->dockerImage)->contains(':')) {
$tag = str($this->dockerImage)->after(':');
} else {
$tag = 'latest';
}
$stringable = str($this->dockerImage)->before(':');
$tag = str($this->dockerImage)->contains(':') ? str($this->dockerImage)->after(':') : 'latest';
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$application = Application::create([
$application = Application::query()->create([
'name' => 'docker-image-'.new Cuid2,
'repository_project_id' => 0,
'git_repository' => 'coollabsio/coolify',
'git_branch' => 'main',
'build_pack' => 'dockerimage',
'ports_exposes' => 80,
'docker_registry_image_name' => $image,
'docker_registry_image_name' => $stringable,
'docker_registry_image_tag' => $tag,
'environment_id' => $environment->id,
'destination_id' => $destination->id,

View File

@@ -10,7 +10,7 @@ class EmptyProject extends Component
{
public function createEmptyProject()
{
$project = Project::create([
$project = Project::query()->create([
'name' => generate_random_name(),
'team_id' => currentTeam()->id,
'uuid' => (string) new Cuid2,

View File

@@ -7,9 +7,11 @@ use App\Models\GithubApp;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
use Throwable;
class GithubPrivateRepository extends Component
{
@@ -104,7 +106,7 @@ class GithubPrivateRepository extends Component
$this->repositories = collect();
$this->page = 1;
$this->selected_github_app_id = $github_app_id;
$this->github_app = GithubApp::where('id', $github_app_id)->first();
$this->github_app = GithubApp::query()->where('id', $github_app_id)->first();
$this->token = generate_github_installation_token($this->github_app);
$this->loadRepositoryByPage();
if ($this->repositories->count() < $this->total_repositories_count) {
@@ -129,10 +131,12 @@ class GithubPrivateRepository extends Component
}
if ($json['total_count'] === 0) {
return;
return null;
}
$this->total_repositories_count = $json['total_count'];
$this->repositories = $this->repositories->concat(collect($json['repositories']));
return null;
}
public function loadBranches()
@@ -161,25 +165,27 @@ class GithubPrivateRepository extends Component
$this->total_branches_count = count($json);
$this->branches = $this->branches->concat(collect($json));
return null;
}
public function submit()
{
try {
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$application = Application::create([
$application = Application::query()->create([
'name' => generate_application_name($this->selected_repository_owner.'/'.$this->selected_repository_repo, $this->selected_branch_name),
'repository_project_id' => $this->selected_repository_id,
'git_repository' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}",
@@ -214,7 +220,7 @@ class GithubPrivateRepository extends Component
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -9,9 +9,11 @@ use App\Models\PrivateKey;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Exception;
use Illuminate\Support\Str;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
class GithubPrivateRepositoryDeployKey extends Component
{
@@ -81,9 +83,9 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->parameters = get_route_parameters();
$this->query = request()->query();
if (isDev()) {
$this->private_keys = PrivateKey::where('team_id', currentTeam()->id)->get();
$this->private_keys = PrivateKey::query()->where('team_id', currentTeam()->id)->get();
} else {
$this->private_keys = PrivateKey::where('team_id', currentTeam()->id)->where('id', '!=', 0)->get();
$this->private_keys = PrivateKey::query()->where('team_id', currentTeam()->id)->where('id', '!=', 0)->get();
}
}
@@ -124,18 +126,18 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->validate();
try {
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$this->get_git_source();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
if ($this->git_source === 'other') {
$application_init = [
@@ -173,7 +175,7 @@ class GithubPrivateRepositoryDeployKey extends Component
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::create($application_init);
$application = Application::query()->create($application_init);
$application->settings->is_static = $this->is_static;
$application->settings->save();
@@ -187,7 +189,7 @@ class GithubPrivateRepositoryDeployKey extends Component
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}
@@ -199,7 +201,7 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
if ($this->git_host === 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
$this->git_source = GithubApp::query()->where('name', 'Public GitHub')->first();
return;
}

View File

@@ -10,8 +10,10 @@ use App\Models\Service;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Carbon\Carbon;
use Exception;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
class PublicGitRepository extends Component
{
@@ -93,7 +95,7 @@ class PublicGitRepository extends Component
public function updatedBaseDirectory()
{
if ($this->base_directory) {
if ($this->base_directory !== '' && $this->base_directory !== '0') {
$this->base_directory = rtrim($this->base_directory, '/');
if (! str($this->base_directory)->startsWith('/')) {
$this->base_directory = '/'.$this->base_directory;
@@ -153,12 +155,12 @@ class PublicGitRepository extends Component
(! str($this->repository_url)->contains('github.com') ||
! str($this->repository_url)->contains('git.sr.ht'))
) {
$this->repository_url = $this->repository_url.'.git';
$this->repository_url .= '.git';
}
if (str($this->repository_url)->contains('github.com') && str($this->repository_url)->endsWith('.git')) {
$this->repository_url = str($this->repository_url)->beforeLast('.git')->value();
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
try {
@@ -166,24 +168,26 @@ class PublicGitRepository extends Component
$this->getGitSource();
$this->getBranch();
$this->selectedBranch = $this->git_branch;
} catch (\Throwable $e) {
} catch (Throwable $e) {
if ($this->rate_limit_remaining == 0) {
$this->selectedBranch = $this->git_branch;
$this->branchFound = true;
return;
return null;
}
if (! $this->branchFound && $this->git_branch === 'main') {
try {
$this->git_branch = 'master';
$this->getBranch();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
} else {
return handleError($e, $this);
}
}
return null;
}
private function getGitSource()
@@ -197,7 +201,7 @@ class PublicGitRepository extends Component
$this->git_branch = 'main';
}
if ($this->git_host === 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
$this->git_source = GithubApp::query()->where('name', 'Public GitHub')->first();
return;
}
@@ -212,7 +216,7 @@ class PublicGitRepository extends Component
return;
}
if ($this->git_source->getMorphClass() === \App\Models\GithubApp::class) {
if ($this->git_source->getMorphClass() === GithubApp::class) {
['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = githubApi(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}");
$this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
$this->branchFound = true;
@@ -227,16 +231,16 @@ class PublicGitRepository extends Component
$project_uuid = $this->parameters['project_uuid'];
$environment_uuid = $this->parameters['environment_uuid'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $project_uuid)->first();
$project = Project::query()->where('uuid', $project_uuid)->first();
$environment = $project->load(['environments'])->environments->where('uuid', $environment_uuid)->first();
if ($this->build_pack === 'dockercompose' && isDev() && $this->new_compose_services) {
@@ -256,15 +260,13 @@ class PublicGitRepository extends Component
$new_service['source_id'] = $this->git_source->id;
$new_service['source_type'] = $this->git_source->getMorphClass();
}
$service = Service::create($new_service);
$service = Service::query()->create($new_service);
return redirect()->route('project.service.configuration', [
'service_uuid' => $service->uuid,
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
return;
}
if ($this->git_source === 'other') {
$application_init = [
@@ -303,7 +305,7 @@ class PublicGitRepository extends Component
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::create($application_init);
$application = Application::query()->create($application_init);
$application->settings->is_static = $this->isStatic;
$application->settings->save();
@@ -322,7 +324,7 @@ class PublicGitRepository extends Component
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -205,12 +205,10 @@ class Select extends Component
{
if ($this->includeSwarm) {
$this->servers = $this->allServers;
} elseif ($this->allServers instanceof Collection) {
$this->servers = $this->allServers->where('settings.is_swarm_worker', false)->where('settings.is_swarm_manager', false)->where('settings.is_build_server', false);
} else {
if ($this->allServers instanceof Collection) {
$this->servers = $this->allServers->where('settings.is_swarm_worker', false)->where('settings.is_swarm_manager', false)->where('settings.is_build_server', false);
} else {
$this->servers = $this->allServers;
}
$this->servers = $this->allServers;
}
}
@@ -218,7 +216,7 @@ class Select extends Component
{
$type = str($type)->lower()->slug()->value();
if ($this->loading) {
return;
return null;
}
$this->loading = true;
$this->type = $type;
@@ -252,7 +250,7 @@ class Select extends Component
if ($type === 'existing-postgresql') {
$this->current_step = $type;
return;
return null;
}
if (count($this->servers) === 1) {
$server = $this->servers->first();
@@ -267,6 +265,8 @@ class Select extends Component
}
}
$this->current_step = 'servers';
return null;
}
public function setServer(Server $server)
@@ -285,6 +285,8 @@ class Select extends Component
}
}
$this->current_step = 'destinations';
return null;
}
public function setDestination(string $destination_uuid)
@@ -321,6 +323,8 @@ class Select extends Component
'server_id' => $this->server_id,
]);
}
return null;
}
public function loadServers()

View File

@@ -7,6 +7,7 @@ use App\Models\GithubApp;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Exception;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@@ -36,23 +37,23 @@ CMD ["nginx", "-g", "daemon off;"]
'dockerfile' => 'required',
]);
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
}
if (! $destination) {
throw new \Exception('Destination not found. What?!');
throw new Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$port = get_port_from_dockerfile($this->dockerfile);
if (! $port) {
$port = 80;
}
$application = Application::create([
$application = Application::query()->create([
'name' => 'dockerfile-'.new Cuid2,
'repository_project_id' => 0,
'git_repository' => 'coollabsio/coolify',