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.

fix(storage): split S3 endpoint input and persist stopped status

Andras Bacsai2677e471387e
diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.php
index 81148e3d8d..66ceb95f64 100644
--- a/app/Actions/Application/StopApplication.php
+++ b/app/Actions/Application/StopApplication.php
@@ -28,7 +28,7 @@ class StopApplication
if ($server->isSwarm()) {
instant_remote_process(["docker stack rm {$application->uuid}"], $server);
- return;
+ continue;
}
$containers = $previewDeployments
@@ -57,17 +57,15 @@ class StopApplication
}
}
+ $status = ['status' => 'exited'];
if ($resetRestartCount) {
- $application->update([
+ $status = array_merge($status, [
'restart_count' => 0,
'last_restart_at' => null,
'last_restart_type' => null,
]);
- } else {
- $application->update([
- 'status' => 'exited',
- ]);
}
+ $application->update($status);
ServiceStatusChanged::dispatch($application->environment->project->team->id);
}
diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.php
index 5bbef7d7df..a3a7f16ef0 100644
--- a/app/Actions/Database/StopDatabase.php
+++ b/app/Actions/Database/StopDatabase.php
@@ -30,6 +30,7 @@ class StopDatabase
// Reset restart tracking when database is manually stopped
$database->update([
+ 'status' => 'exited',
'restart_count' => 0,
'last_restart_at' => null,
'last_restart_type' => null,
diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.php
index 9817bf32d4..5e34c8e6a2 100644
--- a/app/Actions/Service/StopService.php
+++ b/app/Actions/Service/StopService.php
@@ -49,6 +49,9 @@ class StopService
$this->stopContainersInParallel($containersToStop, $server);
}
+ $applications->each->update(['status' => 'exited']);
+ $dbs->each->update(['status' => 'exited']);
+
if ($deleteConnectedNetworks) {
$service->deleteConnectedNetworks();
}
diff --git a/app/Actions/Service/StopServiceApplication.php b/app/Actions/Service/StopServiceApplication.php
index 724e1a254f..184dcb4919 100644
--- a/app/Actions/Service/StopServiceApplication.php
+++ b/app/Actions/Service/StopServiceApplication.php
@@ -2,6 +2,7 @@
namespace App\Actions\Service;
+use App\Events\ServiceStatusChanged;
use App\Models\ServiceApplication;
use App\Models\ServiceDatabase;
use Lorisleiva\Actions\Concerns\AsAction;
@@ -21,5 +22,8 @@ class StopServiceApplication
instant_remote_process([
"docker stop {$containerName}",
], $server);
+
+ $serviceApplication->update(['status' => 'exited']);
+ ServiceStatusChanged::dispatch($service->environment->project->team->id);
}
}
diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.php
index e706366288..e07a985b40 100644
--- a/app/Livewire/Project/Application/Previews.php
+++ b/app/Livewire/Project/Application/Previews.php
@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Application;
use App\Actions\Docker\GetContainersStatus;
+use App\Events\ServiceStatusChanged;
use App\Jobs\DeleteResourceJob;
use App\Models\Application;
use App\Models\ApplicationPreview;
@@ -373,6 +374,11 @@ class Previews extends Component
$this->stopContainers($containers, $server);
}
+ ApplicationPreview::where('application_id', $this->application->id)
+ ->where('pull_request_id', $pull_request_id)
+ ->update(['status' => 'exited']);
+ ServiceStatusChanged::dispatch($this->application->environment->project->team->id);
+
GetContainersStatus::run($server);
$this->application->refresh();
$this->dispatch('containerStatusUpdated');
diff --git a/app/Livewire/Storage/Create.php b/app/Livewire/Storage/Create.php
index 49da0ef68a..d741e69180 100644
--- a/app/Livewire/Storage/Create.php
+++ b/app/Livewire/Storage/Create.php
@@ -26,7 +26,7 @@ class Create extends Component
public string $bucket;
- public string $endpoint;
+ public string $endpoint = '';
public S3Storage $storage;
diff --git a/resources/views/components/forms/domain-input.blade.php b/resources/views/components/forms/domain-input.blade.php
index 030fc0f5f5..e7fc1c0630 100644
--- a/resources/views/components/forms/domain-input.blade.php
+++ b/resources/views/components/forms/domain-input.blade.php
@@ -3,6 +3,8 @@
'wire' => true,
'value' => '',
'errorId' => null,
+ 'hostLabel' => 'Domain',
+ 'hostPlaceholder' => 'app.example.com',
])
<div class="grid gap-4 sm:grid-cols-[8rem_minmax(0,1fr)_8rem]" x-data="{
@@ -51,13 +53,24 @@
<div class="min-w-0">
<div class="mb-1.5 flex h-4 w-full items-center gap-1.5">
<label for="{{ $id }}" class="mb-0! flex items-center gap-1.5 leading-4">
- Domain <x-highlighted text="*" />
+ {{ $hostLabel }} <x-highlighted text="*" />
</label>
</div>
- <input id="{{ $id }}" type="text" class="input" x-model="host" placeholder="app.example.com"
+ <input id="{{ $id }}" type="text" class="input" x-model="host" placeholder="{{ $hostPlaceholder }}"
autocomplete="off" required />
@error($errorId ?? $id)
- <p class="mt-1 text-[12px] text-red-500">{{ $message }}</p>
+ @php
+ preg_match('/(https?:\/\/\S+)$/', $message, $validationLinkMatches);
+ $validationLink = $validationLinkMatches[1] ?? null;
+ @endphp
+ <p class="mt-1 text-[12px] text-red-500">
+ @if ($validationLink)
+ {{ str($message)->beforeLast($validationLink)->trim() }}
+ <a class="font-medium underline" href="{{ $validationLink }}">Set them here.</a>
+ @else
+ {{ $message }}
+ @endif
+ </p>
@enderror
</div>
diff --git a/resources/views/livewire/storage/create.blade.php b/resources/views/livewire/storage/create.blade.php
index dd6b1d687b..1154a7e90b 100644
--- a/resources/views/livewire/storage/create.blade.php
+++ b/resources/views/livewire/storage/create.blade.php
@@ -7,18 +7,8 @@
<x-forms.input required label="Name" id="name" />
<x-forms.input label="Description" id="description" />
</div>
- <x-forms.input required type="url" label="Endpoint" id="endpoint"
- x-on:blur="
- let value = $el.value.trim();
- const hasScheme = /^https?:/i.test(value) || /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
- if (value && !hasScheme) {
- value = `https://${value}`;
- }
- if ($el.value !== value) {
- $el.value = value;
- $el.dispatchEvent(new Event('input', { bubbles: true }));
- }
- " />
+ <x-forms.domain-input id="endpoint" host-label="Host"
+ host-placeholder="minio.internal or 192.168.1.50" />
<div class="flex gap-2">
<x-forms.input required label="Bucket" id="bucket" />
<x-forms.input required helper="Region only required for AWS. Leave it as-is for other providers."
diff --git a/resources/views/livewire/storage/form.blade.php b/resources/views/livewire/storage/form.blade.php
index a37e728cc9..2a76e7cc61 100644
--- a/resources/views/livewire/storage/form.blade.php
+++ b/resources/views/livewire/storage/form.blade.php
@@ -16,8 +16,12 @@
<x-forms.input canGate="update" :canResource="$storage" label="Name" id="name" />
<x-forms.input canGate="update" :canResource="$storage" label="Description" id="description" />
<div class="lg:col-span-2">
- <x-forms.input canGate="update" :canResource="$storage" required label="Endpoint"
- id="endpoint" />
+ @can('update', $storage)
+ <x-forms.domain-input id="endpoint" host-label="Host"
+ host-placeholder="minio.internal or 192.168.1.50" />
+ @else
+ <x-forms.input label="Endpoint" :value="$endpoint" disabled />
+ @endcan
</div>
<x-forms.input canGate="update" :canResource="$storage" required label="Bucket" id="bucket" />
<x-forms.input canGate="update" :canResource="$storage" required label="Region" id="region" />
diff --git a/tests/Feature/SplitUrlInputTest.php b/tests/Feature/SplitUrlInputTest.php
new file mode 100644
index 0000000000..5bfa0feb60
--- /dev/null
+++ b/tests/Feature/SplitUrlInputTest.php
@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Support\Facades\Blade;
+use Illuminate\Support\Facades\View;
+use Illuminate\Support\MessageBag;
+use Illuminate\Support\ViewErrorBag;
+
+it('renders configurable host copy for S3 endpoints', function () {
+ View::share('errors', new ViewErrorBag);
+
+ $html = Blade::render(<<<'BLADE'
+ <x-forms.domain-input id="endpoint" :wire="false" value="http://192.168.1.50:9000/s3"
+ host-label="Host" host-placeholder="minio.internal or 192.168.1.50" />
+ BLADE);
+
+ expect($html)
+ ->toContain('Host')
+ ->toContain('minio.internal or 192.168.1.50')
+ ->toContain("scheme: 'https'")
+ ->toContain("host: ''")
+ ->toContain("port: ''")
+ ->toContain("path: ''");
+});
+
+it('keeps validation errors attached to the composed endpoint', function () {
+ $settingsUrl = route('settings.advanced').'#endpoint-section';
+ $errors = new ViewErrorBag;
+ $errors->put('default', new MessageBag([
+ 'endpoint' => "The endpoint is invalid. Configure allowed internal targets: {$settingsUrl}",
+ ]));
+ View::share('errors', $errors);
+
+ $html = Blade::render('<x-forms.domain-input id="endpoint" :wire="false" />');
+
+ expect($html)
+ ->toContain('The endpoint is invalid.')
+ ->toContain('href="'.$settingsUrl.'"')
+ ->toContain('Set them here.');
+});
diff --git a/tests/Unit/S3StorageEndpointNormalizationTest.php b/tests/Unit/S3StorageEndpointNormalizationTest.php
index 860fbe7311..ee2ecc04a4 100644
--- a/tests/Unit/S3StorageEndpointNormalizationTest.php
+++ b/tests/Unit/S3StorageEndpointNormalizationTest.php
@@ -5,14 +5,18 @@ use Tests\TestCase;
uses(TestCase::class);
-it('normalizes S3 endpoints without a Livewire blur request', function () {
- $view = file_get_contents(resource_path('views/livewire/storage/create.blade.php'));
+it('uses the shared split URL input without a Livewire blur request', function () {
+ $createView = file_get_contents(resource_path('views/livewire/storage/create.blade.php'));
+ $editView = file_get_contents(resource_path('views/livewire/storage/form.blade.php'));
- expect($view)
+ expect($createView)
->not->toContain('wire:model.blur="endpoint"')
- ->toContain('x-on:blur')
- ->toContain('const hasScheme')
- ->toContain('dispatchEvent');
+ ->toContain('<x-forms.domain-input id="endpoint"')
+ ->toContain('host-label="Host"')
+ ->toContain('host-placeholder="minio.internal or 192.168.1.50"')
+ ->and($editView)
+ ->toContain('<x-forms.domain-input id="endpoint"')
+ ->toContain('@can(\'update\', $storage)');
});
it('normalizes endpoints again on the backend', function (string $endpoint, string $expected) {
diff --git a/tests/Unit/StopActionsPersistStatusTest.php b/tests/Unit/StopActionsPersistStatusTest.php
new file mode 100644
index 0000000000..a924381bb9
--- /dev/null
+++ b/tests/Unit/StopActionsPersistStatusTest.php
@@ -0,0 +1,40 @@
+<?php
+
+it('persists exited status when stopping standalone databases', function () {
+ $action = file_get_contents(__DIR__.'/../../app/Actions/Database/StopDatabase.php');
+
+ expect($action)->toContain("'status' => 'exited'");
+});
+
+it('persists exited status for every full application stop path', function () {
+ $action = file_get_contents(__DIR__.'/../../app/Actions/Application/StopApplication.php');
+
+ expect($action)
+ ->toContain("\$status = ['status' => 'exited'];")
+ ->toContain('$application->update($status);')
+ ->not->toMatch('/docker stack rm .*?return;/s');
+});
+
+it('persists exited status for all children when stopping a service', function () {
+ $action = file_get_contents(__DIR__.'/../../app/Actions/Service/StopService.php');
+
+ expect($action)
+ ->toContain("\$applications->each->update(['status' => 'exited']);")
+ ->toContain("\$dbs->each->update(['status' => 'exited']);");
+});
+
+it('persists exited status when stopping an individual service resource', function () {
+ $action = file_get_contents(__DIR__.'/../../app/Actions/Service/StopServiceApplication.php');
+
+ expect($action)
+ ->toContain("\$serviceApplication->update(['status' => 'exited']);")
+ ->toContain('ServiceStatusChanged::dispatch($service->environment->project->team->id);');
+});
+
+it('persists exited status when stopping a preview deployment', function () {
+ $component = file_get_contents(__DIR__.'/../../app/Livewire/Project/Application/Previews.php');
+
+ expect($component)
+ ->toContain("->update(['status' => 'exited']);")
+ ->toContain('ServiceStatusChanged::dispatch($this->application->environment->project->team->id);');
+});