mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 16:52:45 -04:00
Container ownership labels now use UUIDs: coolify.applicationUuid, coolify.serviceUuid, coolify.service.subUuid and coolify.databaseUuid. Numeric ids differ between Coolify instances, so after a server transfer the target could not find existing containers: redeploys left the old container running and service statuses were wrong. Containers are matched by UUID label first, then by the compose project (Swarm: stack namespace), which is the resource UUID since July 2024, and last by the older numeric id label. Existing containers keep working without a redeploy and get the UUID labels on the next deploy or restart.
36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Application;
|
|
|
|
use App\Events\ServiceStatusChanged;
|
|
use App\Models\ApplicationPreview;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class StopApplicationPreview
|
|
{
|
|
use AsAction;
|
|
|
|
public function handle(ApplicationPreview $preview, bool $resetRestartCount = true, bool $removeContainer = true): void
|
|
{
|
|
$application = $preview->application;
|
|
$server = $application->destination->server;
|
|
$containers = getCurrentApplicationContainerStatus($server, $application, $preview->pull_request_id);
|
|
|
|
foreach ($containers->pluck('Names') as $containerName) {
|
|
$escapedContainerName = escapeshellarg($containerName);
|
|
$commands = [dockerStopCommand($application->settings->stopGracePeriodSeconds(), $escapedContainerName, $server)];
|
|
if ($removeContainer) {
|
|
$commands[] = "docker rm -f {$escapedContainerName}";
|
|
}
|
|
instant_remote_process($commands, $server, false);
|
|
}
|
|
|
|
$preview->update(['status' => 'exited']);
|
|
if ($resetRestartCount) {
|
|
$preview->resetRestartLimit();
|
|
}
|
|
|
|
ServiceStatusChanged::dispatch($application->environment->project->team->id);
|
|
}
|
|
}
|