diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 1dfaf6c49..d48594e62 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -12,19 +12,24 @@ class StartService public string $jobQueue = 'high'; - public function handle(Service $service) + public function handle(Service $service, bool $pullLatestImages = false, bool $stopBeforeStart = false) { + $service->parse(); + if ($stopBeforeStart) { + StopService::run(service: $service, dockerCleanup: false); + } $service->saveComposeConfigs(); $commands[] = 'cd '.$service->workdir(); $commands[] = "echo 'Saved configuration files to {$service->workdir()}.'"; + if ($pullLatestImages) { + $commands[] = "echo 'Pulling images.'"; + $commands[] = 'docker compose pull'; + } if ($service->networks()->count() > 0) { $commands[] = "echo 'Creating Docker network.'"; $commands[] = "docker network inspect $service->uuid >/dev/null 2>&1 || docker network create --attachable $service->uuid"; } $commands[] = 'echo Starting service.'; - $commands[] = "echo 'Pulling images.'"; - $commands[] = 'docker compose pull'; - $commands[] = "echo 'Starting containers.'"; $commands[] = 'docker compose up -d --remove-orphans --force-recreate --build'; $commands[] = "docker network connect $service->uuid coolify-proxy >/dev/null 2>&1 || true"; if (data_get($service, 'connect_to_docker_network')) { diff --git a/app/Actions/Shared/PullImage.php b/app/Actions/Shared/PullImage.php deleted file mode 100644 index 4bd1cf453..000000000 --- a/app/Actions/Shared/PullImage.php +++ /dev/null @@ -1,28 +0,0 @@ -saveComposeConfigs(); - - $commands[] = 'cd '.$resource->workdir(); - $commands[] = "echo 'Saved configuration files to {$resource->workdir()}.'"; - $commands[] = 'docker compose pull'; - - $server = data_get($resource, 'server'); - - if (! $server) { - return; - } - - instant_remote_process($commands, $resource->server); - } -} diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php index 915fb54c6..e6a1271e1 100644 --- a/app/Livewire/Project/Service/Navbar.php +++ b/app/Livewire/Project/Service/Navbar.php @@ -4,7 +4,6 @@ namespace App\Livewire\Project\Service; use App\Actions\Service\StartService; use App\Actions\Service\StopService; -use App\Actions\Shared\PullImage; use App\Enums\ProcessStatus; use App\Events\ServiceStatusChanged; use App\Models\Service; @@ -85,8 +84,7 @@ class Navbar extends Component public function start() { - $this->service->parse(); - $activity = StartService::run($this->service); + $activity = StartService::run($this->service, pullLatestImages: true); $this->dispatch('activityMonitor', $activity->id); } @@ -98,8 +96,7 @@ class Navbar extends Component $activity->properties->status = ProcessStatus::ERROR->value; $activity->save(); } - $this->service->parse(); - $activity = StartService::run($this->service); + $activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true); $this->dispatch('activityMonitor', $activity->id); } catch (\Exception $e) { $this->dispatch('error', $e->getMessage()); @@ -129,10 +126,7 @@ class Navbar extends Component return; } - StopService::run(service: $this->service, dockerCleanup: false); - $this->service->parse(); - $this->dispatch('imagePulled'); - $activity = StartService::run($this->service); + $activity = StartService::run($this->service, stopBeforeStart: true); $this->dispatch('activityMonitor', $activity->id); } @@ -144,11 +138,7 @@ class Navbar extends Component return; } - PullImage::run($this->service); - StopService::run(service: $this->service, dockerCleanup: false); - $this->service->parse(); - $this->dispatch('imagePulled'); - $activity = StartService::run($this->service); + $activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true); $this->dispatch('activityMonitor', $activity->id); } diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php index 4629f1625..7424f0940 100644 --- a/resources/views/livewire/project/service/navbar.blade.php +++ b/resources/views/livewire/project/service/navbar.blade.php @@ -165,10 +165,12 @@ return; } $wire.$dispatch('info', 'Service restart in progress.'); + window.dispatchEvent(new CustomEvent('startservice')); $wire.$call('restart'); }); $wire.$on('pullAndRestartEvent', () => { - $wire.$dispatch('info', 'Pulling new images.'); + $wire.$dispatch('info', 'Pulling new images and restarting service.'); + window.dispatchEvent(new CustomEvent('startservice')); $wire.$call('pullAndRestartEvent'); }); $wire.on('imagePulled', () => {