moar fixes

This commit is contained in:
Andras Bacsai 2023-11-27 15:25:15 +01:00
parent d4d2cc71a0
commit c1710c8f7b
10 changed files with 138 additions and 96 deletions

View File

@ -25,5 +25,15 @@ class StopApplication
// TODO: make notification for application // TODO: make notification for application
// $application->environment->project->team->notify(new StatusChanged($application)); // $application->environment->project->team->notify(new StatusChanged($application));
} }
// Delete Preview Deployments
$previewDeployments = $application->previews;
foreach ($previewDeployments as $previewDeployment) {
$containers = getCurrentApplicationContainerStatus($server, $application->id, $previewDeployment->pull_request_id);
foreach ($containers as $container) {
$name = str_replace('/', '', $container['Names']);
instant_remote_process(["docker rm -f $name"], $application->destination->server, throwError: false);
}
}
} }
} }

View File

@ -152,6 +152,10 @@ class General extends Component
$this->application->settings->is_static = $this->is_static = false; $this->application->settings->is_static = $this->is_static = false;
$this->application->settings->save(); $this->application->settings->save();
} }
if ($this->application->build_pack === 'dockercompose') {
$this->application->fqdn = null;
$this->application->settings->save();
}
$this->submit(); $this->submit();
} }
public function checkLabelUpdates() public function checkLabelUpdates()

View File

@ -41,7 +41,7 @@ class Heading extends Component
public function deploy(bool $force_rebuild = false) public function deploy(bool $force_rebuild = false)
{ {
if (!$this->application->deployableComposeBuildPack()) { if ($this->application->build_pack === 'dockercompose' && is_null($this->application->docker_compose_raw)) {
$this->emit('error', 'Please load a Compose file first.'); $this->emit('error', 'Please load a Compose file first.');
return; return;
} }

View File

@ -77,7 +77,7 @@ class Previews extends Component
$name = str_replace('/', '', $container['Names']); $name = str_replace('/', '', $container['Names']);
instant_remote_process(["docker rm -f $name"], $this->application->destination->server, throwError: false); instant_remote_process(["docker rm -f $name"], $this->application->destination->server, throwError: false);
} }
ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->delete(); ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first()->delete();
$this->application->refresh(); $this->application->refresh();
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);

View File

@ -949,7 +949,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
]; ];
} }
if ($this->application->settings->is_gpu_enabled) { if ($this->application->settings->is_gpu_enabled) {
ray('asd');
$docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'] = [ $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'] = [
[ [
'driver' => data_get($this->application, 'settings.gpu_driver', 'nvidia'), 'driver' => data_get($this->application, 'settings.gpu_driver', 'nvidia'),

View File

@ -48,10 +48,6 @@ class Application extends BaseModel
$application->environment_variables_preview()->delete(); $application->environment_variables_preview()->delete();
}); });
} }
public function deployableComposeBuildPack()
{
return $this->build_pack === 'dockercompose' && $this->docker_compose_raw;
}
public function link() public function link()
{ {
return route('project.application.configuration', [ return route('project.application.configuration', [
@ -262,7 +258,6 @@ class Application extends BaseModel
{ {
return $this->morphTo(); return $this->morphTo();
} }
public function isDeploymentInprogress() public function isDeploymentInprogress()
{ {
$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', 'in_progress')->count(); $deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', 'in_progress')->count();

View File

@ -5,7 +5,26 @@ namespace App\Models;
class ApplicationPreview extends BaseModel class ApplicationPreview extends BaseModel
{ {
protected $guarded = []; protected $guarded = [];
protected static function booted()
{
static::deleting(function ($preview) {
if ($preview->application->build_pack === 'dockercompose') {
$server = $preview->application->destination->server;
$composeFile = $preview->application->parseCompose(pull_request_id: $preview->pull_request_id);
$volumes = data_get($composeFile, 'volumes');
$networks = data_get($composeFile, 'networks');
$networkKeys = collect($networks)->keys();
$volumeKeys = collect($volumes)->keys();
$volumeKeys->each(function ($key) use ($server) {
instant_remote_process(["docker volume rm -f $key"], $server, false);
});
$networkKeys->each(function ($key) use ($server) {
instant_remote_process(["docker network disconnect $key coolify-proxy"], $server, false);
instant_remote_process(["docker network rm $key"], $server, false);
});
}
});
}
static function findPreviewByApplicationAndPullId(int $application_id, int $pull_request_id) static function findPreviewByApplicationAndPullId(int $application_id, int $pull_request_id)
{ {
return self::where('application_id', $application_id)->where('pull_request_id', $pull_request_id)->firstOrFail(); return self::where('application_id', $application_id)->where('pull_request_id', $pull_request_id)->firstOrFail();

View File

@ -1144,14 +1144,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if ($volume->contains(':')) { if ($volume->contains(':')) {
$name = $volume->before(':'); $name = $volume->before(':');
$mount = $volume->after(':'); $mount = $volume->after(':');
$newName = $name . "-{$resource->uuid}-$pull_request_id"; $newName = $resource->uuid . "-{$name}-pr-$pull_request_id";
$volume = str("$newName:$mount"); $volume = str("$newName:$mount");
$topLevelVolumes->put($newName, [ $topLevelVolumes->put($newName, [
'name' => $newName, 'name' => $newName,
]); ]);
} }
} else if (is_array($volume)) { } else if (is_array($volume)) {
$volume['source'] = str($volume['source'])->append("-{$resource->uuid}-$pull_request_id"); $source = data_get($volume, 'source');
if ($source) {
$newSource = $resource->uuid . "-{$source}-pr-$pull_request_id";
data_set($volume, 'source', $newSource);
$topLevelVolumes->put($newSource, [
'name' => $newSource,
]);
}
} }
@ -1159,6 +1166,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
}); });
data_set($service, 'volumes', $serviceVolumes->toArray()); data_set($service, 'volumes', $serviceVolumes->toArray());
} }
} else {
} }
// Decide if the service is a database // Decide if the service is a database
$isDatabase = isDatabaseImage(data_get_str($service, 'image')); $isDatabase = isDatabaseImage(data_get_str($service, 'image'));
@ -1202,7 +1211,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if ($pull_request_id !== 0) { if ($pull_request_id !== 0) {
$topLevelNetworks->put($network, [ $topLevelNetworks->put($network, [
'name' => $network, 'name' => $network,
'external' => false 'external' => true
]); ]);
} else { } else {
$topLevelNetworks->put($network, [ $topLevelNetworks->put($network, [

View File

@ -1,21 +1,25 @@
<div class="group"> <div class="group">
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Open Application @if (data_get($application, 'fqdn') ||
<x-chevron-down /> collect(json_decode($this->application->docker_compose_domains))->count() > 0 ||
</label> data_get($application, 'previews', collect([]))->count() > 0 ||
data_get($application, 'ports_mappings_array'))
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Open Application
<x-chevron-down />
</label>
<div class="absolute z-50 hidden group-hover:block"> <div class="absolute z-50 hidden group-hover:block">
<ul tabindex="0" class="relative -ml-24 text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200"> <ul tabindex="0"
@if (data_get($application, 'gitBrancLocation')) class="relative -ml-24 text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200">
<li> @if (data_get($application, 'gitBrancLocation'))
<a target="_blank" <li>
class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white" <a target="_blank"
href="{{ $application->gitBranchLocation }}"> class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
<x-git-icon git="{{ $application->source?->getMorphClass() }}" /> href="{{ $application->gitBranchLocation }}">
Git Repository <x-git-icon git="{{ $application->source?->getMorphClass() }}" />
</a> Git Repository
</li> </a>
@endif </li>
@if (data_get($application, 'fqdn')) @endif
@if (data_get($application, 'build_pack') === 'dockercompose') @if (data_get($application, 'build_pack') === 'dockercompose')
@foreach (collect(json_decode($this->application->docker_compose_domains)) as $fqdn) @foreach (collect(json_decode($this->application->docker_compose_domains)) as $fqdn)
@if (data_get($fqdn, 'domain')) @if (data_get($fqdn, 'domain'))
@ -35,8 +39,9 @@
</li> </li>
@endif @endif
@endforeach @endforeach
@else @endif
@foreach (Str::of(data_get($application, 'fqdn'))->explode(',') as $fqdn) @if (data_get($application, 'fqdn'))
@foreach (str(data_get($application, 'fqdn'))->explode(',') as $fqdn)
<li> <li>
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white" <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
target="_blank" href="{{ getFqdnWithoutPort($fqdn) }}"> target="_blank" href="{{ getFqdnWithoutPort($fqdn) }}">
@ -53,67 +58,67 @@
</li> </li>
@endforeach @endforeach
@endif @endif
@endif @if (data_get($application, 'previews', collect([]))->count() > 0)
@if (data_get($application, 'previews', collect([]))->count() > 0) @foreach (data_get($application, 'previews') as $preview)
@foreach (data_get($application, 'previews') as $preview) @if (data_get($preview, 'fqdn'))
@if (data_get($preview, 'fqdn')) <li>
<li> <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white" target="_blank" href="{{ getFqdnWithoutPort(data_get($preview, 'fqdn')) }}">
target="_blank" href="{{ getFqdnWithoutPort(data_get($preview, 'fqdn')) }}"> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path d="M9 15l6 -6" />
<path d="M9 15l6 -6" /> <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" /> <path
<path d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />
d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" /> </svg>
</svg> PR{{ data_get($preview, 'pull_request_id') }} |
PR{{ data_get($preview, 'pull_request_id') }} | {{ data_get($preview, 'fqdn') }}
{{ data_get($preview, 'fqdn') }} </a>
</a> </li>
</li> @endif
@endif @endforeach
@endforeach @endif
@endif @if (data_get($application, 'ports_mappings_array'))
@if (data_get($application, 'ports_mappings_array')) @foreach ($application->ports_mappings_array as $port)
@foreach ($application->ports_mappings_array as $port) @if (isDev())
@if (isDev()) <li>
<li> <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white" target="_blank" href="http://localhost:{{ explode(':', $port)[0] }}">
target="_blank" href="http://localhost:{{ explode(':', $port)[0] }}"> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path d="M9 15l6 -6" />
<path d="M9 15l6 -6" /> <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" /> <path
<path d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />
d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" /> </svg>
</svg> Port {{ $port }}
Port {{ $port }} </a>
</a> </li>
</li> @else
@else <li>
<li> <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white" target="_blank"
target="_blank" href="http://{{ $application->destination->server->ip }}:{{ explode(':', $port)[0] }}">
href="http://{{ $application->destination->server->ip }}:{{ explode(':', $port)[0] }}"> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path d="M9 15l6 -6" />
<path d="M9 15l6 -6" /> <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" /> <path
<path d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />
d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" /> </svg>
</svg> Port {{ $port }}
Port {{ $port }} </a>
</a> </li>
</li> @endif
@endif @endforeach
@endforeach @endif
@endif </ul>
</ul> </div>
</div> @endif
</div> </div>

View File

@ -71,15 +71,16 @@
</a> </a>
</div> </div>
<div class="flex items-center gap-2 pt-6"> <div class="flex items-center gap-2 pt-6">
<x-forms.button class="bg-coolgray-500" wire:click="deploy({{ data_get($preview, 'pull_request_id') }})"> <x-forms.button class="bg-coolgray-500"
wire:click="deploy({{ data_get($preview, 'pull_request_id') }})">
@if (data_get($preview, 'status') === 'exited') @if (data_get($preview, 'status') === 'exited')
Deploy Deploy
@else @else
Redeploy Redeploy
@endif @endif
</x-forms.button> </x-forms.button>
<x-forms.button class="bg-coolgray-500" wire:click="stop({{ data_get($preview, 'pull_request_id') }})">Remove <x-forms.button class="bg-coolgray-500"
Preview wire:click="stop({{ data_get($preview, 'pull_request_id') }})">Remove Preview
</x-forms.button> </x-forms.button>
<a <a
href="{{ route('project.application.deployments', [...$parameters, 'pull_request_id' => data_get($preview, 'pull_request_id')]) }}"> href="{{ route('project.application.deployments', [...$parameters, 'pull_request_id' => data_get($preview, 'pull_request_id')]) }}">