From 9c22e0171668ef32fc5be0c5c266d41ccd916fac Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 9 Oct 2023 15:49:48 +0200 Subject: [PATCH] wip: dockerimage --- app/Http/Livewire/Project/New/DockerImage.php | 73 +++++++++++++++++++ .../project/application/general.blade.php | 1 + .../project/new/docker-image.blade.php | 11 +++ .../livewire/project/new/select.blade.php | 10 +++ resources/views/project/new.blade.php | 2 + 5 files changed, 97 insertions(+) create mode 100644 app/Http/Livewire/Project/New/DockerImage.php create mode 100644 resources/views/livewire/project/new/docker-image.blade.php diff --git a/app/Http/Livewire/Project/New/DockerImage.php b/app/Http/Livewire/Project/New/DockerImage.php new file mode 100644 index 000000000..5e1107e4d --- /dev/null +++ b/app/Http/Livewire/Project/New/DockerImage.php @@ -0,0 +1,73 @@ +parameters = get_route_parameters(); + $this->query = request()->query(); + } + public function submit() + { + $this->validate([ + 'dockerImage' => 'required' + ]); + $image = Str::of($this->dockerImage)->before(':'); + $tag = Str::of($this->dockerImage)->after(':') ?: 'latest'; + $destination_uuid = $this->query['destination']; + $destination = StandaloneDocker::where('uuid', $destination_uuid)->first(); + if (!$destination) { + $destination = SwarmDocker::where('uuid', $destination_uuid)->first(); + } + if (!$destination) { + throw new \Exception('Destination not found. What?!'); + } + $destination_class = $destination->getMorphClass(); + + $project = Project::where('uuid', $this->parameters['project_uuid'])->first(); + $environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first(); + $application = Application::create([ + 'name' => 'docker-image-' . new Cuid2(7), + '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_tag' => $tag, + 'environment_id' => $environment->id, + 'destination_id' => $destination->id, + 'destination_type' => $destination_class, + 'health_check_enabled' => false, + ]); + + $fqdn = generateFqdn($destination->server, $application->uuid); + $application->update([ + 'name' => 'docker-image-' . $application->uuid, + 'fqdn' => $fqdn + ]); + + redirect()->route('project.application.configuration', [ + 'application_uuid' => $application->uuid, + 'environment_name' => $environment->name, + 'project_uuid' => $project->uuid, + ]); + } + public function render() + { + return view('livewire.project.new.docker-image'); + } +} diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index fb525a8dd..3654bd50b 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -24,6 +24,7 @@ + @if ($application->settings->is_static) diff --git a/resources/views/livewire/project/new/docker-image.blade.php b/resources/views/livewire/project/new/docker-image.blade.php new file mode 100644 index 000000000..3927247c7 --- /dev/null +++ b/resources/views/livewire/project/new/docker-image.blade.php @@ -0,0 +1,11 @@ +
+

Create a new Application

+
You can deploy an existing Docker Image from any Registry.
+
+
+

Docker Image

+ Save +
+ + +
diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.php index 376f143dc..4e96cdf76 100644 --- a/resources/views/livewire/project/new/select.blade.php +++ b/resources/views/livewire/project/new/select.blade.php @@ -62,6 +62,16 @@ +
+
+
+ Based on an existing Docker Image +
+
+ You can deploy an existing Docker Image form any Registry. +
+
+

Databases

diff --git a/resources/views/project/new.blade.php b/resources/views/project/new.blade.php index 8d69f95e0..5b6ee1029 100644 --- a/resources/views/project/new.blade.php +++ b/resources/views/project/new.blade.php @@ -9,6 +9,8 @@ @elseif ($type === 'docker-compose-empty') + @elseif ($type === 'docker-image') + @else @endif