feat: image tag for services

This commit is contained in:
Andras Bacsai 2023-09-25 17:51:04 +02:00
parent 0f8ccac775
commit 0fbc382467
7 changed files with 27 additions and 6 deletions

View File

@ -15,6 +15,7 @@ class Application extends Component
'application.human_name' => 'nullable',
'application.description' => 'nullable',
'application.fqdn' => 'nullable',
'application.image_tag' => 'required',
'application.ignore_from_status' => 'required|boolean',
];
public function render()

View File

@ -2,7 +2,6 @@
namespace App\Http\Livewire\Project\Service;
use App\Models\ServiceApplication;
use App\Models\ServiceDatabase;
use Livewire\Component;
@ -12,6 +11,7 @@ class Database extends Component
protected $rules = [
'database.human_name' => 'nullable',
'database.description' => 'nullable',
'database.image_tag' => 'required',
'database.ignore_from_status' => 'required|boolean',
];

View File

@ -139,6 +139,7 @@ public function parse(bool $isNew = false): Collection
$image = data_get($service, 'image');
if ($image) {
$imageName = Str::of($image)->before(':');
$imageTag = Str::of($image)->after(':') ?? 'latest';
if (collect(DATABASE_DOCKER_IMAGES)->contains($imageName)) {
$isDatabase = true;
data_set($service, 'is_database', true);
@ -159,12 +160,14 @@ public function parse(bool $isNew = false): Collection
if ($isDatabase) {
$savedService = ServiceDatabase::create([
'name' => $serviceName,
'image_tag' => $imageTag,
'service_id' => $this->id
]);
} else {
$savedService = ServiceApplication::create([
'name' => $serviceName,
'fqdn' => $this->generateFqdn($serviceVariables, $serviceName),
'image_tag' => $imageTag,
'service_id' => $this->id
]);
}
@ -182,6 +185,8 @@ public function parse(bool $isNew = false): Collection
$savedService->save();
}
}
// Set image tag
$fqdns = data_get($savedService, 'fqdn');
if ($fqdns) {
$fqdns = collect(Str::of($fqdns)->explode(','));
@ -495,6 +500,8 @@ public function parse(bool $isNew = false): Collection
$labels = $labels->merge(fqdnLabelsForTraefik($fqdns, $container_name, true));
}
}
data_set($service, 'labels', $labels->toArray());
data_forget($service, 'is_database');
data_set($service, 'restart', RESTART_MODE);

View File

@ -13,6 +13,7 @@ public function up(): void
{
Schema::table('service_applications', function (Blueprint $table) {
$table->boolean('ignore_from_status')->default(false);
$table->string('image_tag')->nullable();
});
}
@ -23,6 +24,7 @@ public function down(): void
{
Schema::table('service_applications', function (Blueprint $table) {
$table->dropColumn('ignore_from_status');
$table->dropColumn('image_tag');
});
}
};

View File

@ -13,7 +13,7 @@ public function up(): void
{
Schema::table('service_databases', function (Blueprint $table) {
$table->boolean('ignore_from_status')->default(false);
$table->string('image_tag')->nullable();
});
}
@ -24,6 +24,7 @@ public function down(): void
{
Schema::table('service_databases', function (Blueprint $table) {
$table->dropColumn('ignore_from_status');
$table->dropColumn('image_tag');
});
}
};

View File

@ -16,7 +16,11 @@
placeholder="Human readable name"></x-forms.input>
<x-forms.input label="Description" id="application.description"></x-forms.input>
</div>
<x-forms.input placeholder="https://app.coolify.io" label="Domains" id="application.fqdn"></x-forms.input>
<div class="flex gap-2">
<x-forms.input placeholder="https://app.coolify.io" label="Domains"
id="application.fqdn"></x-forms.input>
<x-forms.input required helper="You can change the image tag you would like to deploy.<br><br><span class='text-warning'>WARNING. You could corrupt your data. Only do it if you know what you are doing.</span>" label="Image Tag" id="application.image_tag"></x-forms.input>
</div>
</div>
<h3 class="pt-2">Advanced</h3>
<div class="w-64">

View File

@ -9,10 +9,16 @@
<x-forms.button type="submit">Save</x-forms.button>
<a target="_blank" href="{{ $database->documentation() }}">Documentation <x-external-link /></a>
</div>
<div class="flex flex-col gap-2">
<div class="flex gap-2">
<x-forms.input label="Name" id="database.human_name" placeholder="Name"></x-forms.input>
<x-forms.input label="Description" id="database.description"></x-forms.input>
</div>
<div class="flex gap-2">
<x-forms.input required helper="You can change the image tag you would like to deploy.<br><br><span class='text-warning'>WARNING. You could corrupt your data. Only do it if you know what you are doing.</span>" label="Image Tag"
id="database.image_tag"></x-forms.input>
</div>
</div>
<h3 class="pt-2">Advanced</h3>
<div class="w-64">
<x-forms.checkbox instantSave label="Ignore from service status"