Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

moar fixes

Andras Bacsaic1710c8f7bd2
diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.php
index a98384f451..1d09f0daf3 100644
--- a/app/Actions/Application/StopApplication.php
+++ b/app/Actions/Application/StopApplication.php
@@ -25,5 +25,15 @@ class StopApplication
// TODO: make notification for 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);
+ }
+ }
+
}
}
diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php
index d108bca149..0284b40a94 100644
--- a/app/Http/Livewire/Project/Application/General.php
+++ b/app/Http/Livewire/Project/Application/General.php
@@ -152,6 +152,10 @@ class General extends Component
$this->application->settings->is_static = $this->is_static = false;
$this->application->settings->save();
}
+ if ($this->application->build_pack === 'dockercompose') {
+ $this->application->fqdn = null;
+ $this->application->settings->save();
+ }
$this->submit();
}
public function checkLabelUpdates()
diff --git a/app/Http/Livewire/Project/Application/Heading.php b/app/Http/Livewire/Project/Application/Heading.php
index dae105cd62..14bdf1db0d 100644
--- a/app/Http/Livewire/Project/Application/Heading.php
+++ b/app/Http/Livewire/Project/Application/Heading.php
@@ -41,7 +41,7 @@ class Heading extends Component
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.');
return;
}
diff --git a/app/Http/Livewire/Project/Application/Previews.php b/app/Http/Livewire/Project/Application/Previews.php
index fd471a007d..effdd7f7c3 100644
--- a/app/Http/Livewire/Project/Application/Previews.php
+++ b/app/Http/Livewire/Project/Application/Previews.php
@@ -77,7 +77,7 @@ class Previews extends Component
$name = str_replace('/', '', $container['Names']);
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();
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 6dca962bb9..36907a9177 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -949,7 +949,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
];
}
if ($this->application->settings->is_gpu_enabled) {
- ray('asd');
$docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'] = [
[
'driver' => data_get($this->application, 'settings.gpu_driver', 'nvidia'),
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 809d5ff6fd..2e58d18917 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -48,10 +48,6 @@ class Application extends BaseModel
$application->environment_variables_preview()->delete();
});
}
- public function deployableComposeBuildPack()
- {
- return $this->build_pack === 'dockercompose' && $this->docker_compose_raw;
- }
public function link()
{
return route('project.application.configuration', [
@@ -262,7 +258,6 @@ class Application extends BaseModel
{
return $this->morphTo();
}
-
public function isDeploymentInprogress()
{
$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', 'in_progress')->count();
diff --git a/app/Models/ApplicationPreview.php b/app/Models/ApplicationPreview.php
index 13775abae2..87dce056e7 100644
--- a/app/Models/ApplicationPreview.php
+++ b/app/Models/ApplicationPreview.php
@@ -5,7 +5,26 @@ namespace App\Models;
class ApplicationPreview extends BaseModel
{
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)
{
return self::where('application_id', $application_id)->where('pull_request_id', $pull_request_id)->firstOrFail();
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index df562d5ffe..ecb67cd0ca 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -1144,14 +1144,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if ($volume->contains(':')) {
$name = $volume->before(':');
$mount = $volume->after(':');
- $newName = $name . "-{$resource->uuid}-$pull_request_id";
+ $newName = $resource->uuid . "-{$name}-pr-$pull_request_id";
$volume = str("$newName:$mount");
$topLevelVolumes->put($newName, [
'name' => $newName,
]);
}
} 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());
}
+ } else {
+
}
// Decide if the service is a database
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
@@ -1202,7 +1211,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if ($pull_request_id !== 0) {
$topLevelNetworks->put($network, [
'name' => $network,
- 'external' => false
+ 'external' => true
]);
} else {
$topLevelNetworks->put($network, [
diff --git a/resources/views/components/applications/links.blade.php b/resources/views/components/applications/links.blade.php
index 44d69df62b..c5bdc4a481 100644
--- a/resources/views/components/applications/links.blade.php
+++ b/resources/views/components/applications/links.blade.php
@@ -1,21 +1,25 @@
<div class="group">
- <label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Open Application
- <x-chevron-down />
- </label>
+ @if (data_get($application, 'fqdn') ||
+ collect(json_decode($this->application->docker_compose_domains))->count() > 0 ||
+ 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">
- <ul tabindex="0" class="relative -ml-24 text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200">
- @if (data_get($application, 'gitBrancLocation'))
- <li>
- <a target="_blank"
- class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
- href="{{ $application->gitBranchLocation }}">
- <x-git-icon git="{{ $application->source?->getMorphClass() }}" />
- Git Repository
- </a>
- </li>
- @endif
- @if (data_get($application, 'fqdn'))
+ <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">
+ @if (data_get($application, 'gitBrancLocation'))
+ <li>
+ <a target="_blank"
+ class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
+ href="{{ $application->gitBranchLocation }}">
+ <x-git-icon git="{{ $application->source?->getMorphClass() }}" />
+ Git Repository
+ </a>
+ </li>
+ @endif
@if (data_get($application, 'build_pack') === 'dockercompose')
@foreach (collect(json_decode($this->application->docker_compose_domains)) as $fqdn)
@if (data_get($fqdn, 'domain'))
@@ -35,8 +39,9 @@
</li>
@endif
@endforeach
- @else
- @foreach (Str::of(data_get($application, 'fqdn'))->explode(',') as $fqdn)
+ @endif
+ @if (data_get($application, 'fqdn'))
+ @foreach (str(data_get($application, 'fqdn'))->explode(',') as $fqdn)
<li>
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
target="_blank" href="{{ getFqdnWithoutPort($fqdn) }}">
@@ -53,67 +58,67 @@
</li>
@endforeach
@endif
- @endif
- @if (data_get($application, 'previews', collect([]))->count() > 0)
- @foreach (data_get($application, 'previews') as $preview)
- @if (data_get($preview, 'fqdn'))
- <li>
- <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')) }}">
- <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-linejoin="round">
- <path stroke="none" d="M0 0h24v24H0z" fill="none" />
- <path d="M9 15l6 -6" />
- <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
- <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" />
- </svg>
- PR{{ data_get($preview, 'pull_request_id') }} |
- {{ data_get($preview, 'fqdn') }}
- </a>
- </li>
- @endif
- @endforeach
- @endif
- @if (data_get($application, 'ports_mappings_array'))
- @foreach ($application->ports_mappings_array as $port)
- @if (isDev())
- <li>
- <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] }}">
- <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-linejoin="round">
- <path stroke="none" d="M0 0h24v24H0z" fill="none" />
- <path d="M9 15l6 -6" />
- <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
- <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" />
- </svg>
- Port {{ $port }}
- </a>
- </li>
- @else
- <li>
- <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
- target="_blank"
- 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"
- stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
- stroke-linejoin="round">
- <path stroke="none" d="M0 0h24v24H0z" fill="none" />
- <path d="M9 15l6 -6" />
- <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
- <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" />
- </svg>
- Port {{ $port }}
- </a>
- </li>
- @endif
- @endforeach
- @endif
- </ul>
- </div>
+ @if (data_get($application, 'previews', collect([]))->count() > 0)
+ @foreach (data_get($application, 'previews') as $preview)
+ @if (data_get($preview, 'fqdn'))
+ <li>
+ <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')) }}">
+ <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-linejoin="round">
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
+ <path d="M9 15l6 -6" />
+ <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
+ <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" />
+ </svg>
+ PR{{ data_get($preview, 'pull_request_id') }} |
+ {{ data_get($preview, 'fqdn') }}
+ </a>
+ </li>
+ @endif
+ @endforeach
+ @endif
+ @if (data_get($application, 'ports_mappings_array'))
+ @foreach ($application->ports_mappings_array as $port)
+ @if (isDev())
+ <li>
+ <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] }}">
+ <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-linejoin="round">
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
+ <path d="M9 15l6 -6" />
+ <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
+ <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" />
+ </svg>
+ Port {{ $port }}
+ </a>
+ </li>
+ @else
+ <li>
+ <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
+ target="_blank"
+ 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"
+ stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
+ stroke-linejoin="round">
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
+ <path d="M9 15l6 -6" />
+ <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
+ <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" />
+ </svg>
+ Port {{ $port }}
+ </a>
+ </li>
+ @endif
+ @endforeach
+ @endif
+ </ul>
+ </div>
+ @endif
</div>
diff --git a/resources/views/livewire/project/application/previews.blade.php b/resources/views/livewire/project/application/previews.blade.php
index b02acc4ab7..6663c71d38 100644
--- a/resources/views/livewire/project/application/previews.blade.php
+++ b/resources/views/livewire/project/application/previews.blade.php
@@ -71,15 +71,16 @@
</a>
</div>
<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')
Deploy
@else
Redeploy
@endif
</x-forms.button>
- <x-forms.button class="bg-coolgray-500" wire:click="stop({{ data_get($preview, 'pull_request_id') }})">Remove
- Preview
+ <x-forms.button class="bg-coolgray-500"
+ wire:click="stop({{ data_get($preview, 'pull_request_id') }})">Remove Preview
</x-forms.button>
<a
href="{{ route('project.application.deployments', [...$parameters, 'pull_request_id' => data_get($preview, 'pull_request_id')]) }}">