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

@@ -7,11 +7,9 @@ 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
{
@@ -60,20 +58,20 @@ class DockerCompose extends Component
return $this->dispatch('error', "Invalid docker-compose file.\n$isValid");
}
$project = Project::query()->where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::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::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->create([
$service = Service::create([
'name' => 'service'.Str::random(10),
'docker_compose_raw' => $this->dockerComposeRaw,
'environment_id' => $environment->id,
@@ -84,7 +82,7 @@ class DockerCompose extends Component
$variables = parseEnvFormatToArray($this->envFile);
foreach ($variables as $key => $variable) {
EnvironmentVariable::query()->create([
EnvironmentVariable::create([
'key' => $key,
'value' => $variable,
'is_build_time' => false,
@@ -102,7 +100,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,7 +6,6 @@ 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;
@@ -29,28 +28,32 @@ class DockerImage extends Component
$this->validate([
'dockerImage' => 'required',
]);
$stringable = str($this->dockerImage)->before(':');
$tag = str($this->dockerImage)->contains(':') ? str($this->dockerImage)->after(':') : 'latest';
$image = str($this->dockerImage)->before(':');
if (str($this->dockerImage)->contains(':')) {
$tag = str($this->dockerImage)->after(':');
} else {
$tag = 'latest';
}
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$application = Application::query()->create([
$application = Application::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' => $stringable,
'docker_registry_image_name' => $image,
'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::query()->create([
$project = Project::create([
'name' => generate_random_name(),
'team_id' => currentTeam()->id,
'uuid' => (string) new Cuid2,

View File

@@ -7,11 +7,9 @@ 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
{
@@ -106,7 +104,7 @@ class GithubPrivateRepository extends Component
$this->repositories = collect();
$this->page = 1;
$this->selected_github_app_id = $github_app_id;
$this->github_app = GithubApp::query()->where('id', $github_app_id)->first();
$this->github_app = GithubApp::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) {
@@ -131,12 +129,10 @@ class GithubPrivateRepository extends Component
}
if ($json['total_count'] === 0) {
return null;
return;
}
$this->total_repositories_count = $json['total_count'];
$this->repositories = $this->repositories->concat(collect($json['repositories']));
return null;
}
public function loadBranches()
@@ -165,27 +161,25 @@ 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::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first();
$application = Application::query()->create([
$application = Application::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}",
@@ -220,7 +214,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,11 +9,9 @@ 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
{
@@ -83,9 +81,9 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->parameters = get_route_parameters();
$this->query = request()->query();
if (isDev()) {
$this->private_keys = PrivateKey::query()->where('team_id', currentTeam()->id)->get();
$this->private_keys = PrivateKey::where('team_id', currentTeam()->id)->get();
} else {
$this->private_keys = PrivateKey::query()->where('team_id', currentTeam()->id)->where('id', '!=', 0)->get();
$this->private_keys = PrivateKey::where('team_id', currentTeam()->id)->where('id', '!=', 0)->get();
}
}
@@ -126,18 +124,18 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->validate();
try {
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::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 = [
@@ -175,7 +173,7 @@ class GithubPrivateRepositoryDeployKey extends Component
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::query()->create($application_init);
$application = Application::create($application_init);
$application->settings->is_static = $this->is_static;
$application->settings->save();
@@ -189,7 +187,7 @@ class GithubPrivateRepositoryDeployKey extends Component
'environment_uuid' => $environment->uuid,
'project_uuid' => $project->uuid,
]);
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
@@ -201,7 +199,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::query()->where('name', 'Public GitHub')->first();
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;
}

View File

@@ -10,10 +10,8 @@ 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
{
@@ -95,7 +93,7 @@ class PublicGitRepository extends Component
public function updatedBaseDirectory()
{
if ($this->base_directory !== '' && $this->base_directory !== '0') {
if ($this->base_directory) {
$this->base_directory = rtrim($this->base_directory, '/');
if (! str($this->base_directory)->startsWith('/')) {
$this->base_directory = '/'.$this->base_directory;
@@ -155,12 +153,12 @@ class PublicGitRepository extends Component
(! str($this->repository_url)->contains('github.com') ||
! str($this->repository_url)->contains('git.sr.ht'))
) {
$this->repository_url .= '.git';
$this->repository_url = $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 {
@@ -168,26 +166,24 @@ 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 null;
return;
}
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()
@@ -201,7 +197,7 @@ class PublicGitRepository extends Component
$this->git_branch = 'main';
}
if ($this->git_host === 'github.com') {
$this->git_source = GithubApp::query()->where('name', 'Public GitHub')->first();
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;
}
@@ -216,7 +212,7 @@ class PublicGitRepository extends Component
return;
}
if ($this->git_source->getMorphClass() === GithubApp::class) {
if ($this->git_source->getMorphClass() === \App\Models\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;
@@ -231,16 +227,16 @@ class PublicGitRepository extends Component
$project_uuid = $this->parameters['project_uuid'];
$environment_uuid = $this->parameters['environment_uuid'];
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->where('uuid', $project_uuid)->first();
$project = Project::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) {
@@ -260,13 +256,15 @@ class PublicGitRepository extends Component
$new_service['source_id'] = $this->git_source->id;
$new_service['source_type'] = $this->git_source->getMorphClass();
}
$service = Service::query()->create($new_service);
$service = Service::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 = [
@@ -305,7 +303,7 @@ class PublicGitRepository extends Component
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::query()->create($application_init);
$application = Application::create($application_init);
$application->settings->is_static = $this->isStatic;
$application->settings->save();
@@ -324,7 +322,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,10 +205,12 @@ 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 {
$this->servers = $this->allServers;
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;
}
}
}
@@ -216,7 +218,7 @@ class Select extends Component
{
$type = str($type)->lower()->slug()->value();
if ($this->loading) {
return null;
return;
}
$this->loading = true;
$this->type = $type;
@@ -250,7 +252,7 @@ class Select extends Component
if ($type === 'existing-postgresql') {
$this->current_step = $type;
return null;
return;
}
if (count($this->servers) === 1) {
$server = $this->servers->first();
@@ -265,8 +267,6 @@ class Select extends Component
}
}
$this->current_step = 'servers';
return null;
}
public function setServer(Server $server)
@@ -285,8 +285,6 @@ class Select extends Component
}
}
$this->current_step = 'destinations';
return null;
}
public function setDestination(string $destination_uuid)
@@ -323,8 +321,6 @@ class Select extends Component
'server_id' => $this->server_id,
]);
}
return null;
}
public function loadServers()

View File

@@ -7,7 +7,6 @@ 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;
@@ -37,23 +36,23 @@ CMD ["nginx", "-g", "daemon off;"]
'dockerfile' => 'required',
]);
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::query()->where('uuid', $destination_uuid)->first();
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (! $destination) {
$destination = SwarmDocker::query()->where('uuid', $destination_uuid)->first();
$destination = SwarmDocker::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::query()->where('uuid', $this->parameters['project_uuid'])->first();
$project = Project::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::query()->create([
$application = Application::create([
'name' => 'dockerfile-'.new Cuid2,
'repository_project_id' => 0,
'git_repository' => 'coollabsio/coolify',