wip: dockerimage

This commit is contained in:
Andras Bacsai 2023-10-09 15:49:48 +02:00
parent d1c47a4062
commit 9c22e01716
5 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,73 @@
<?php
namespace App\Http\Livewire\Project\New;
use App\Models\Application;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
use Illuminate\Support\Str;
class DockerImage extends Component
{
public string $dockerImage = '';
public array $parameters;
public array $query;
public function mount()
{
$this->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');
}
}

View File

@ -24,6 +24,7 @@
<x-forms.select id="application.build_pack" label="Build Pack" required> <x-forms.select id="application.build_pack" label="Build Pack" required>
<option value="nixpacks">Nixpacks</option> <option value="nixpacks">Nixpacks</option>
<option value="dockerfile">Dockerfile</option> <option value="dockerfile">Dockerfile</option>
<option value="dockerimage">Docker Image</option>
</x-forms.select> </x-forms.select>
@if ($application->settings->is_static) @if ($application->settings->is_static)
<x-forms.select id="application.static_image" label="Static Image" required> <x-forms.select id="application.static_image" label="Static Image" required>

View File

@ -0,0 +1,11 @@
<div>
<h1>Create a new Application</h1>
<div class="pb-4">You can deploy an existing Docker Image from any Registry.</div>
<form wire:submit.prevent="submit">
<div class="flex gap-2 pb-1">
<h2>Docker Image</h2>
<x-forms.button type="submit">Save</x-forms.button>
</div>
<x-forms.input rows="20" id="dockerImage" placeholder="nginx"></x-forms.textarea>
</form>
</div>

View File

@ -62,6 +62,16 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box group" wire:click="setType('docker-image')">
<div class="flex flex-col mx-6">
<div class="font-bold text-white group-hover:text-white">
Based on an existing Docker Image
</div>
<div class="text-xs group-hover:text-white">
You can deploy an existing Docker Image form any Registry.
</div>
</div>
</div>
</div> </div>
<h2 class="py-4">Databases</h2> <h2 class="py-4">Databases</h2>
<div class="grid justify-start grid-cols-1 gap-2 text-left xl:grid-cols-3"> <div class="grid justify-start grid-cols-1 gap-2 text-left xl:grid-cols-3">

View File

@ -9,6 +9,8 @@
<livewire:project.new.simple-dockerfile :type="$type" /> <livewire:project.new.simple-dockerfile :type="$type" />
@elseif ($type === 'docker-compose-empty') @elseif ($type === 'docker-compose-empty')
<livewire:project.new.docker-compose :type="$type" /> <livewire:project.new.docker-compose :type="$type" />
@elseif ($type === 'docker-image')
<livewire:project.new.docker-image :type="$type" />
@else @else
<livewire:project.new.select /> <livewire:project.new.select />
@endif @endif