fix: handle previously defined compose previews
This commit is contained in:
parent
7fd0deedb1
commit
a68951541c
@ -1708,11 +1708,29 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$preview = $resource->previews()->find($preview_id);
|
$preview = $resource->previews()->find($preview_id);
|
||||||
$docker_compose_domains = collect(json_decode(data_get($preview, 'docker_compose_domains')));
|
$docker_compose_domains = collect(json_decode(data_get($preview, 'docker_compose_domains')));
|
||||||
$found_fqdn = data_get($docker_compose_domains, "$serviceName.domain");
|
if ($docker_compose_domains->count() > 0) {
|
||||||
if ($found_fqdn) {
|
$found_fqdn = data_get($docker_compose_domains, "$serviceName.domain");
|
||||||
$fqdns = collect($found_fqdn);
|
if ($found_fqdn) {
|
||||||
|
$fqdns = collect($found_fqdn);
|
||||||
|
} else {
|
||||||
|
$fqdns = collect([]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$fqdns = collect([]);
|
$fqdns = $fqdns->map(function ($fqdn) use ($pull_request_id, $resource) {
|
||||||
|
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($resource->id, $pull_request_id);
|
||||||
|
$url = Url::fromString($fqdn);
|
||||||
|
$template = $resource->preview_url_template;
|
||||||
|
$host = $url->getHost();
|
||||||
|
$schema = $url->getScheme();
|
||||||
|
$random = new Cuid2(7);
|
||||||
|
$preview_fqdn = str_replace('{{random}}', $random, $template);
|
||||||
|
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
|
||||||
|
$preview_fqdn = str_replace('{{pr_id}}', $pull_request_id, $preview_fqdn);
|
||||||
|
$preview_fqdn = "$schema://$preview_fqdn";
|
||||||
|
$preview->fqdn = $preview_fqdn;
|
||||||
|
$preview->save();
|
||||||
|
return $preview_fqdn;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
|
||||||
|
@ -89,10 +89,21 @@ class="dark:text-warning">{{ $application->destination->server->name }}</span>.<
|
|||||||
|
|
||||||
@if ($application->build_pack === 'dockercompose')
|
@if ($application->build_pack === 'dockercompose')
|
||||||
<div class="flex flex-col gap-4 pt-4">
|
<div class="flex flex-col gap-4 pt-4">
|
||||||
@foreach (collect(json_decode($preview->docker_compose_domains)) as $serviceName => $service)
|
@if (collect(json_decode($preview->docker_compose_domains))->count() === 0)
|
||||||
<livewire:project.application.previews-compose wire:key="{{ $preview->id }}"
|
<form wire:submit="save_preview('{{ $preview->id }}')"
|
||||||
:service="$service" :serviceName="$serviceName" :preview="$preview" />
|
class="flex items-end gap-2 pt-4">
|
||||||
@endforeach
|
<x-forms.input label="Domain" helper="One domain per preview."
|
||||||
|
id="application.previews.{{ $previewName }}.fqdn"></x-forms.input>
|
||||||
|
<x-forms.button type="submit">Save</x-forms.button>
|
||||||
|
<x-forms.button wire:click="generate_preview('{{ $preview->id }}')">Generate
|
||||||
|
Domain</x-forms.button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
@foreach (collect(json_decode($preview->docker_compose_domains)) as $serviceName => $service)
|
||||||
|
<livewire:project.application.previews-compose wire:key="{{ $preview->id }}"
|
||||||
|
:service="$service" :serviceName="$serviceName" :preview="$preview" />
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
<form wire:submit="save_preview('{{ $preview->id }}')" class="flex items-end gap-2 pt-4">
|
<form wire:submit="save_preview('{{ $preview->id }}')" class="flex items-end gap-2 pt-4">
|
||||||
@ -104,7 +115,6 @@ class="dark:text-warning">{{ $application->destination->server->name }}</span>.<
|
|||||||
</form>
|
</form>
|
||||||
@endif
|
@endif
|
||||||
<div class="flex items-center gap-2 pt-6">
|
<div class="flex items-center gap-2 pt-6">
|
||||||
|
|
||||||
@if (count($parameters) > 0)
|
@if (count($parameters) > 0)
|
||||||
<a
|
<a
|
||||||
href="{{ route('project.application.deployment.index', [...$parameters, 'pull_request_id' => data_get($preview, 'pull_request_id')]) }}">
|
href="{{ route('project.application.deployment.index', [...$parameters, 'pull_request_id' => data_get($preview, 'pull_request_id')]) }}">
|
||||||
|
Loading…
Reference in New Issue
Block a user