Fix application image cleanup

This commit is contained in:
ayntk-ai
2024-09-04 14:54:43 +02:00
parent b314b08f25
commit bec974dca4
4 changed files with 32 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ class StopApplication
{ {
use AsAction; use AsAction;
public function handle(Application $application, bool $previewDeployments = false) public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true)
{ {
try { try {
$server = $application->destination->server; $server = $application->destination->server;
@@ -29,6 +29,9 @@ class StopApplication
if ($application->build_pack === 'dockercompose') { if ($application->build_pack === 'dockercompose') {
$application->delete_connected_networks($application->uuid); $application->delete_connected_networks($application->uuid);
}
if ($dockerCleanup) {
CleanupDocker::run($server, true); CleanupDocker::run($server, true);
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -21,6 +21,8 @@ class Heading extends Component
protected string $deploymentUuid; protected string $deploymentUuid;
public bool $docker_cleanup = true;
public function getListeners() public function getListeners()
{ {
$teamId = auth()->user()->currentTeam()->id; $teamId = auth()->user()->currentTeam()->id;
@@ -102,7 +104,7 @@ class Heading extends Component
public function stop() public function stop()
{ {
StopApplication::run($this->application); StopApplication::run($this->application, false, $this->docker_cleanup);
$this->application->status = 'exited'; $this->application->status = 'exited';
$this->application->save(); $this->application->save();
if ($this->application->additional_servers->count() > 0) { if ($this->application->additional_servers->count() > 0) {
@@ -135,4 +137,13 @@ class Heading extends Component
'environment_name' => $this->parameters['environment_name'], 'environment_name' => $this->parameters['environment_name'],
]); ]);
} }
public function render()
{
return view('livewire.project.application.heading', [
'checkboxes' => [
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'],
]
]);
}
} }

View File

@@ -72,7 +72,19 @@
</x-forms.button> </x-forms.button>
@endif @endif
@endif @endif
<x-modal-confirmation @click="$wire.dispatch('stopEvent')"> <x-modal-confirmation
title="Confirm Application Stopping?"
buttonTitle="Stop"
submitAction="stop"
:checkboxes="$checkboxes"
:actions="['This application will be stopped.', 'If the application is currently in use data could be lost.', 'All non-persistent data of this application (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the application again).']"
:confirmWithText="false"
:confirmWithPassword="false"
step1ButtonText="Continue Stopping Application"
step2ButtonText="Stop Application"
:dispatchEvent="true"
dispatchEventType="stopEvent"
>
<x-slot:button-title> <x-slot:button-title>
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24" <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
@@ -87,7 +99,6 @@
</svg> </svg>
Stop Stop
</x-slot:button-title> </x-slot:button-title>
This application will be stopped. <br>Please think again.
</x-modal-confirmation> </x-modal-confirmation>
@else @else
<x-forms.button wire:click='deploy'> <x-forms.button wire:click='deploy'>

View File

@@ -34,6 +34,7 @@
:actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']" :actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']"
:confirmWithText="false" :confirmWithText="false"
:confirmWithPassword="false" :confirmWithPassword="false"
step1ButtonText="Continue Stopping Service"
step2ButtonText="Stop Service" step2ButtonText="Stop Service"
:dispatchEvent="true" :dispatchEvent="true"
dispatchEventType="stopEvent" dispatchEventType="stopEvent"
@@ -67,6 +68,7 @@
:actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']" :actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']"
:confirmWithText="false" :confirmWithText="false"
:confirmWithPassword="false" :confirmWithPassword="false"
step1ButtonText="Continue Stopping Service"
step2ButtonText="Stop Service" step2ButtonText="Stop Service"
:dispatchEvent="true" :dispatchEvent="true"
dispatchEventType="stopEvent" dispatchEventType="stopEvent"
@@ -106,6 +108,7 @@
:actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']" :actions="['This service will be stopped.', 'If the service is currently in use data could be lost.', 'All non-persistent data of this service (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the service again).']"
:confirmWithText="false" :confirmWithText="false"
:confirmWithPassword="false" :confirmWithPassword="false"
step1ButtonText="Continue Stopping Service"
step2ButtonText="Stop Service" step2ButtonText="Stop Service"
:dispatchEvent="true" :dispatchEvent="true"
dispatchEventType="stopEvent" dispatchEventType="stopEvent"