Fix: DB image cleanup

This commit is contained in:
ayntk-ai
2024-09-04 14:59:44 +02:00
parent bec974dca4
commit c16e914be4
3 changed files with 18 additions and 3 deletions

View File

@@ -18,7 +18,7 @@ class StopDatabase
{ {
use AsAction; use AsAction;
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false) public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true)
{ {
$server = $database->destination->server; $server = $database->destination->server;
if (!$server->isFunctional()) { if (!$server->isFunctional()) {
@@ -28,7 +28,9 @@ class StopDatabase
$this->stopContainer($database, $database->uuid, 300); $this->stopContainer($database, $database->uuid, 300);
if (!$isDeleteOperation) { if (!$isDeleteOperation) {
$this->deleteConnectedNetworks($database->uuid, $server); //Probably not needed as DBs do not have a network normally $this->deleteConnectedNetworks($database->uuid, $server); //Probably not needed as DBs do not have a network normally
CleanupDocker::run($server, true); if ($dockerCleanup) {
CleanupDocker::run($server, true);
}
} }
if ($database->is_public) { if ($database->is_public) {

View File

@@ -14,6 +14,8 @@ class Heading extends Component
public array $parameters; public array $parameters;
public $docker_cleanup = true;
public function getListeners() public function getListeners()
{ {
$userId = auth()->user()->id; $userId = auth()->user()->id;
@@ -54,7 +56,7 @@ class Heading extends Component
public function stop() public function stop()
{ {
StopDatabase::run($this->database); StopDatabase::run($this->database, false, $this->docker_cleanup);
$this->database->status = 'exited'; $this->database->status = 'exited';
$this->database->save(); $this->database->save();
$this->check_status(); $this->check_status();
@@ -71,4 +73,13 @@ class Heading extends Component
$activity = StartDatabase::run($this->database); $activity = StartDatabase::run($this->database);
$this->dispatch('activityMonitor', $activity->id); $this->dispatch('activityMonitor', $activity->id);
} }
public function render()
{
return view('livewire.project.database.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

@@ -54,9 +54,11 @@
title="Confirm Database Stopping?" title="Confirm Database Stopping?"
buttonTitle="Stop" buttonTitle="Stop"
submitAction="stop" submitAction="stop"
:checkboxes="$checkboxes"
:actions="['This database will be stopped.', 'If the database is currently in use data could be lost.', 'All non-persistent data of this database (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the database again).']" :actions="['This database will be stopped.', 'If the database is currently in use data could be lost.', 'All non-persistent data of this database (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the database again).']"
:confirmWithText="false" :confirmWithText="false"
:confirmWithPassword="false" :confirmWithPassword="false"
step1ButtonText="Continue Stopping Database"
step2ButtonText="Stop Database" step2ButtonText="Stop Database"
:dispatchEvent="true" :dispatchEvent="true"
dispatchEventType="stopEvent" dispatchEventType="stopEvent"