chore: multi select on dockerimage build

This commit is contained in:
David Buday 2024-12-03 22:19:55 +01:00
parent f1873efaae
commit 08d46bc242
8 changed files with 44 additions and 27 deletions

View file

@ -396,7 +396,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
private function deploy_dockerimage_buildpack()
{
$useCustomRegistry = $this->application->docker_use_custom_registry;
try {
// setup
$this->dockerImage = $this->application->docker_registry_image_name;
@ -408,7 +407,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->dockerImage}:{$this->dockerImageTag} to {$this->server->name}.");
// login if use custom registry
if ($useCustomRegistry) {
if ($this->application->docker_use_custom_registry) {
$this->handleRegistryAuth();
}
@ -419,7 +418,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
} catch (Exception $e) {
throw $e;
} finally {
if ($useCustomRegistry) {
if ($this->application->docker_use_custom_registry) {
$this->application_deployment_queue->addLogEntry('Logging out from registry...');
$this->execute_remote_command([
'docker logout',
@ -2475,7 +2474,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
default => escapeshellarg($registry->url)
};
$this->application_deployment_queue->addLogEntry("Attempting to log into registry {$registry->name}...");
$this->application_deployment_queue->addLogEntry("Attempting to log into registry {$registry->name}");
$command = $registry->type === 'docker_hub'
? "echo {{secrets.token}} | docker login -u {$username} --password-stdin"

View file

@ -30,6 +30,8 @@ class General extends Component
public string $build_pack;
public array $selectedRegistries = [];
public ?string $ports_exposes = null;
public bool $is_preserve_repository_enabled = false;
@ -73,8 +75,6 @@ class General extends Component
'application.docker_registry_image_name' => 'nullable',
'application.docker_registry_image_tag' => 'nullable',
'application.docker_use_custom_registry' => 'boolean',
'application.selectedRegistries' => 'required_if:application.docker_use_custom_registry,true|array',
'application.selectedRegistries.*' => 'exists:docker_registries,id',
'application.dockerfile_location' => 'nullable',
'application.docker_compose_location' => 'nullable',
'application.docker_compose' => 'nullable',
@ -96,6 +96,8 @@ class General extends Component
'application.settings.is_preserve_repository_enabled' => 'boolean|required',
'application.watch_paths' => 'nullable',
'application.redirect' => 'string|required',
'selectedRegistries' => 'required_if:application.docker_use_custom_registry,true|array',
'selectedRegistries.*' => 'exists:docker_registries,id',
];
protected $validationAttributes = [
@ -118,7 +120,6 @@ class General extends Component
'application.docker_registry_image_name' => 'Docker registry image name',
'application.docker_registry_image_tag' => 'Docker registry image tag',
'application.docker_use_custom_registry' => 'Use private registry',
'application.selectedRegistries' => 'Registries',
'application.dockerfile_location' => 'Dockerfile location',
'application.docker_compose_location' => 'Docker compose location',
'application.docker_compose' => 'Docker compose',
@ -136,6 +137,7 @@ class General extends Component
'application.settings.is_preserve_repository_enabled' => 'Is preserve repository enabled',
'application.watch_paths' => 'Watch paths',
'application.redirect' => 'Redirect',
'selectedRegistries' => 'Registries',
];
public function mount()
@ -155,6 +157,9 @@ class General extends Component
$this->application->settings->save();
}
if ($this->application->docker_use_custom_registry) {
$this->selectedRegistries = $this->application->registries->pluck('id')->toArray();
}
$this->parsedServiceDomains = $this->application->docker_compose_domains ? json_decode($this->application->docker_compose_domains, true) : [];
$this->ports_exposes = $this->application->ports_exposes;
$this->is_preserve_repository_enabled = $this->application->settings->is_preserve_repository_enabled;
@ -174,10 +179,6 @@ class General extends Component
if (str($this->application->status)->startsWith('running') && is_null($this->application->config_hash)) {
$this->dispatch('configurationChanged');
}
if ($this->application->docker_use_custom_registry) {
$this->application->selectedRegistries = $this->application->registries->pluck('id')->toArray();
}
}
public function instantSave()
@ -400,7 +401,8 @@ class General extends Component
if (data_get($this->application, 'build_pack') === 'dockerimage') {
$this->validate([
'application.docker_registry_image_name' => 'required',
'application.docker_registry_id' => 'required_if:application.docker_use_custom_registry,true',
'selectedRegistries' => 'required_if:application.docker_use_custom_registry,true|array',
'selectedRegistries.*' => 'exists:docker_registries,id',
]);
}
@ -436,15 +438,14 @@ class General extends Component
}
}
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
if ($this->application->docker_use_custom_registry) {
$this->application->registries()->sync($this->application->selectedRegistries);
$this->application->registries()->sync($this->selectedRegistries);
} else {
$this->application->registries()->detach();
}
$this->application->save();
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
} catch (\Throwable $e) {
$originalFqdn = $this->application->getOriginal('fqdn');
if ($originalFqdn !== $this->application->fqdn) {

View file

@ -40,9 +40,11 @@ class DockerImage extends Component
try {
$image = str($this->dockerImage)->before(':');
$tag = str($this->dockerImage)->contains(':') ?
str($this->dockerImage)->after(':') :
'latest';
if (str($this->dockerImage)->contains(':')) {
$tag = str($this->dockerImage)->after(':');
} else {
$tag = 'latest';
}
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
@ -68,16 +70,16 @@ class DockerImage extends Component
'ports_exposes' => 80,
'docker_registry_image_name' => $image,
'docker_registry_image_tag' => $tag,
'docker_use_custom_registry' => $this->useCustomRegistry,
'environment_id' => $environment->id,
'destination_id' => $destination->id,
'destination_type' => $destination_class,
'health_check_enabled' => false,
'docker_use_custom_registry' => $this->useCustomRegistry,
]);
// if ($this->useCustomRegistry && !empty($this->selectedRegistries)) {
// $application->registries()->attach($this->selectedRegistries);
// }
if ($this->useCustomRegistry && !empty($this->selectedRegistries)) {
$application->registries()->sync($this->selectedRegistries);
}
error_log($application->uuid);
$fqdn = generateFqdn($destination->server, $application->uuid);

View file

@ -1664,6 +1664,6 @@ class Application extends BaseModel
public function registries()
{
return $this->belongsToMany(DockerRegistry::class, 'application_docker_registry');
return $this->belongsToMany(DockerRegistry::class, 'application_docker_registry', 'application_id');
}
}

View file

@ -11,4 +11,11 @@ return new class extends Migration {
$table->boolean('docker_use_custom_registry')->default(false);
});
}
public function down(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->dropColumn('docker_use_custom_registry');
});
}
};

View file

@ -13,6 +13,10 @@ body {
@apply text-sm antialiased scrollbar;
}
option[selected] {
@apply bg-coollabs;
}
.apexcharts-tooltip {
@apply dark:text-white dark:border-coolgray-300 dark:bg-coolgray-200 shadow-none !important;
}

View file

@ -154,12 +154,15 @@
@if ($application->docker_use_custom_registry)
<div class="pt-4">
<x-forms.select multiple wire:model.live="application.selectedRegistries"
id="application.selectedRegistries" label="Select Registries"
<x-forms.select multiple wire:model="selectedRegistries" id="selectedRegistries"
label="Select Registries"
required="required_if:application.docker_use_custom_registry,true"
helper="Select one or more registries to pull the image from">
@foreach ($registries as $registry)
<option value="{{ $registry->id }}">{{ $registry->name }}</option>
<option value="{{ $registry->id }}"
{{ in_array($registry->id, $selectedRegistries) ? 'selected' : '' }}>
{{ $registry->name }}
</option>
@endforeach
</x-forms.select>
</div>

View file

@ -18,7 +18,8 @@
<x-forms.select multiple name="selectedRegistries" id="selectedRegistries"
wire:model="selectedRegistries" label="Select Registries" required>
@foreach ($registries as $registry)
<option value="{{ $registry->id }}">{{ $registry->name }}</option>
<option {{ collect($selectedRegistries)->contains($registry->id) ? 'selected' : '' }}
value="{{ $registry->id }}">{{ $registry->name }}</option>
@endforeach
</x-forms.select>
</div>