diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index a750f4412..4fb75b3cb 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -34,7 +34,6 @@ class StartDragonfly $persistent_storages = $this->generate_local_persistent_volumes(); $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); $environment_variables = $this->generate_environment_variables(); - $this->add_custom_dragonfly(); $docker_compose = [ 'version' => '3.8', @@ -99,15 +98,6 @@ class StartDragonfly if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (!is_null($this->database->dragonfly_conf)) { - $docker_compose['services'][$container_name]['volumes'][] = [ - 'type' => 'bind', - 'source' => $this->configuration_dir . '/dragonfly.conf', - 'target' => '/etc/dragonfly/dragonfly.conf', - 'read_only' => true, - ]; - $docker_compose['services'][$container_name]['command'] = "dragonfly /etc/dragonfly/dragonfly.conf --requirepass {$this->database->dragonfly_password}"; - } $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d > $this->configuration_dir/docker-compose.yml"; @@ -163,15 +153,4 @@ class StartDragonfly return $environment_variables->all(); } - private function add_custom_dragonfly() - { - if (is_null($this->database->dragonfly_conf)) { - return; - } - $filename = 'dragonfly.conf'; - Storage::disk('local')->put("tmp/dragonfly.conf_{$this->database->uuid}", $this->database->dragonfly_conf); - $path = Storage::path("tmp/dragonfly.conf_{$this->database->uuid}"); - instant_scp($path, "{$this->configuration_dir}/{$filename}", $this->database->destination->server); - Storage::disk('local')->delete("tmp/dragonfly.conf_{$this->database->uuid}"); - } } diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index c2bbed5ff..7eb910533 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -24,7 +24,6 @@ class General extends Component public $customLabels; public bool $labelsChanged = false; - public bool $isConfigurationChanged = false; public bool $initLoadingCompose = false; public ?string $initialDockerComposeLocation = null; @@ -124,13 +123,8 @@ class General extends Component $this->application->settings->save(); } $this->parsedServiceDomains = $this->application->docker_compose_domains ? json_decode($this->application->docker_compose_domains, true) : []; - $this->ports_exposes = $this->application->ports_exposes; - if (str($this->application->status)->startsWith('running') && is_null($this->application->config_hash)) { - $this->application->isConfigurationChanged(true); - } - $this->isConfigurationChanged = $this->application->isConfigurationChanged(); - $this->customLabels = $this->application->parseContainerLabels(); + $this->customLabels = $this->application->parseContainerLabels(); if (!$this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') { $this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n"); $this->application->custom_labels = base64_encode($this->customLabels); @@ -141,6 +135,10 @@ class General extends Component $this->initLoadingCompose = true; $this->dispatch('info', 'Loading docker compose file...'); } + + if (str($this->application->status)->startsWith('running') && is_null($this->application->config_hash)) { + $this->dispatch('configurationChanged'); + } } public function instantSave() { @@ -316,7 +314,7 @@ class General extends Component } catch (\Throwable $e) { return handleError($e, $this); } finally { - $this->isConfigurationChanged = $this->application->isConfigurationChanged(); + $this->dispatch('configurationChanged'); } } } diff --git a/app/Livewire/Project/Database/Clickhouse/General.php b/app/Livewire/Project/Database/Clickhouse/General.php index 7ff687951..7fe9c1ce0 100644 --- a/app/Livewire/Project/Database/Clickhouse/General.php +++ b/app/Livewire/Project/Database/Clickhouse/General.php @@ -86,26 +86,6 @@ class General extends Component return handleError($e, $this); } } - // public function save_init_script($script) - // { - // $this->database->init_scripts = filter($this->database->init_scripts, fn ($s) => $s['filename'] !== $script['filename']); - // $this->database->init_scripts = array_merge($this->database->init_scripts, [$script]); - // $this->database->save(); - // $this->dispatch('success', 'Init script saved.'); - // } - - // public function delete_init_script($script) - // { - // $collection = collect($this->database->init_scripts); - // $found = $collection->firstWhere('filename', $script['filename']); - // if ($found) { - // $this->database->init_scripts = $collection->filter(fn ($s) => $s['filename'] !== $script['filename'])->toArray(); - // $this->database->save(); - // $this->refresh(); - // $this->dispatch('success', 'Init script deleted.'); - // return; - // } - // } public function refresh(): void { @@ -124,6 +104,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } } diff --git a/app/Livewire/Project/Database/Configuration.php b/app/Livewire/Project/Database/Configuration.php index c988477de..4ab8aa530 100644 --- a/app/Livewire/Project/Database/Configuration.php +++ b/app/Livewire/Project/Database/Configuration.php @@ -7,7 +7,8 @@ use Livewire\Component; class Configuration extends Component { public $database; - public function mount() { + public function mount() + { $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (!$project) { return redirect()->route('dashboard'); @@ -21,6 +22,10 @@ class Configuration extends Component return redirect()->route('dashboard'); } $this->database = $database; + if (str($this->database->status)->startsWith('running') && is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + $this->dispatch('configurationChanged'); + } } public function render() { diff --git a/app/Livewire/Project/Database/Dragonfly/General.php b/app/Livewire/Project/Database/Dragonfly/General.php index 6ba0a3a2d..0a4adf269 100644 --- a/app/Livewire/Project/Database/Dragonfly/General.php +++ b/app/Livewire/Project/Database/Dragonfly/General.php @@ -19,7 +19,6 @@ class General extends Component protected $rules = [ 'database.name' => 'required', 'database.description' => 'nullable', - 'database.dragonfly_conf' => 'nullable', 'database.dragonfly_password' => 'required', 'database.image' => 'required', 'database.ports_mappings' => 'nullable', @@ -30,7 +29,6 @@ class General extends Component protected $validationAttributes = [ 'database.name' => 'Name', 'database.description' => 'Description', - 'database.dragonfly_conf' => 'Redis Configuration', 'database.dragonfly_password' => 'Redis Password', 'database.image' => 'Image', 'database.ports_mappings' => 'Port Mapping', @@ -62,13 +60,16 @@ class General extends Component { try { $this->validate(); - if ($this->database->dragonfly_conf === "") { - $this->database->dragonfly_conf = null; - } $this->database->save(); $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function instantSave() diff --git a/app/Livewire/Project/Database/Heading.php b/app/Livewire/Project/Database/Heading.php index 406835871..960ff2689 100644 --- a/app/Livewire/Project/Database/Heading.php +++ b/app/Livewire/Project/Database/Heading.php @@ -34,6 +34,12 @@ class Heading extends Component ]); $this->dispatch('refresh'); $this->check_status(); + if (is_null($this->database->config_hash) || $this->database->isConfigurationChanged()) { + $this->database->isConfigurationChanged(true); + $this->dispatch('configurationChanged'); + } else { + $this->dispatch('configurationChanged'); + } } public function check_status($showNotification = false) diff --git a/app/Livewire/Project/Database/Keydb/General.php b/app/Livewire/Project/Database/Keydb/General.php index bd99d8ddc..536f743f2 100644 --- a/app/Livewire/Project/Database/Keydb/General.php +++ b/app/Livewire/Project/Database/Keydb/General.php @@ -69,6 +69,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function instantSave() diff --git a/app/Livewire/Project/Database/Mariadb/General.php b/app/Livewire/Project/Database/Mariadb/General.php index a4b6e1883..c0c67898f 100644 --- a/app/Livewire/Project/Database/Mariadb/General.php +++ b/app/Livewire/Project/Database/Mariadb/General.php @@ -76,6 +76,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function instantSave() diff --git a/app/Livewire/Project/Database/Mongodb/General.php b/app/Livewire/Project/Database/Mongodb/General.php index c1b55b1e7..3c1271065 100644 --- a/app/Livewire/Project/Database/Mongodb/General.php +++ b/app/Livewire/Project/Database/Mongodb/General.php @@ -78,6 +78,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function instantSave() diff --git a/app/Livewire/Project/Database/Mysql/General.php b/app/Livewire/Project/Database/Mysql/General.php index cab11e8ce..a1fb9201a 100644 --- a/app/Livewire/Project/Database/Mysql/General.php +++ b/app/Livewire/Project/Database/Mysql/General.php @@ -77,6 +77,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function instantSave() diff --git a/app/Livewire/Project/Database/Postgresql/General.php b/app/Livewire/Project/Database/Postgresql/General.php index 3237c1be3..79d91e7aa 100644 --- a/app/Livewire/Project/Database/Postgresql/General.php +++ b/app/Livewire/Project/Database/Postgresql/General.php @@ -58,7 +58,8 @@ class General extends Component $this->db_url_public = $this->database->get_db_url(); } } - public function instantSaveAdvanced() { + public function instantSaveAdvanced() + { try { if (!$this->database->destination->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; @@ -164,6 +165,12 @@ class General extends Component $this->dispatch('success', 'Database updated.'); } catch (Exception $e) { return handleError($e, $this); + } finally { + if (is_null($this->database->config_hash)) { + $this->database->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } } diff --git a/app/Livewire/Project/Service/EditDomain.php b/app/Livewire/Project/Service/EditDomain.php index 246d43421..87a4a0546 100644 --- a/app/Livewire/Project/Service/EditDomain.php +++ b/app/Livewire/Project/Service/EditDomain.php @@ -43,6 +43,7 @@ class EditDomain extends Component } finally { $this->dispatch('generateDockerCompose'); $this->dispatch('refresh'); + $this->dispatch('configurationChanged'); } } public function render() diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php index 3462a96e1..85a8da69f 100644 --- a/app/Livewire/Project/Service/Navbar.php +++ b/app/Livewire/Project/Service/Navbar.php @@ -17,6 +17,14 @@ class Navbar extends Component public array $query; public $isDeploymentProgress = false; + public function mount() + { + if (str($this->service->status())->contains('running') && is_null($this->service->config_hash)) { + ray('isConfigurationChanged init'); + $this->service->isConfigurationChanged(true); + $this->dispatch('configurationChanged'); + } + } public function getListeners() { $userId = auth()->user()->id; @@ -25,12 +33,19 @@ class Navbar extends Component "serviceStatusChanged" ]; } - public function serviceStarted() { + public function serviceStarted() + { $this->dispatch('success', 'Service status changed.'); } public function serviceStatusChanged() { $this->dispatch('refresh')->self(); + // if (is_null($this->service->config_hash) || $this->service->isConfigurationChanged()) { + // $this->service->isConfigurationChanged(true); + // $this->dispatch('configurationChanged'); + // } else { + // $this->dispatch('configurationChanged'); + // } } public function check_status() { diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.php index 1bfb70c5e..9c98c4d9f 100644 --- a/app/Livewire/Project/Service/StackForm.php +++ b/app/Livewire/Project/Service/StackForm.php @@ -69,6 +69,13 @@ class StackForm extends Component $this->dispatch('success', 'Service saved.'); } catch (\Throwable $e) { return handleError($e, $this); + } finally { + if (is_null($this->service->config_hash)) { + ray('asdf'); + $this->service->isConfigurationChanged(true); + } else { + $this->dispatch('configurationChanged'); + } } } public function render() diff --git a/app/Livewire/Project/Shared/ConfigurationChecker.php b/app/Livewire/Project/Shared/ConfigurationChecker.php new file mode 100644 index 000000000..930ac5fde --- /dev/null +++ b/app/Livewire/Project/Shared/ConfigurationChecker.php @@ -0,0 +1,34 @@ +configurationChanged(); + } + public function render() + { + return view('livewire.project.shared.configuration-checker'); + } + public function configurationChanged() + { + $this->isConfigurationChanged = $this->resource->isConfigurationChanged(); + } +} diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index ed6695b63..2ed764cd1 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -11,7 +11,7 @@ class Danger extends Component public $resource; public $projectUuid; public $environmentName; - public bool $delete_configurations = false; + public bool $delete_configurations = true; public ?string $modalId = null; public function mount() @@ -21,7 +21,6 @@ class Danger extends Component $this->projectUuid = data_get($parameters, 'project_uuid'); $this->environmentName = data_get($parameters, 'environment_name'); } - public function delete() { try { diff --git a/app/Models/Application.php b/app/Models/Application.php index adb26bb21..204cb96b2 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -509,7 +509,7 @@ class Application extends BaseModel } public function isConfigurationChanged(bool $save = false) { - $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->port_exposes . $this->port_mappings . $this->base_directory . $this->publish_directory . $this->dockerfile . $this->dockerfile_location . $this->custom_labels; + $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->ports_exposes . $this->ports_mappings . $this->base_directory . $this->publish_directory . $this->dockerfile . $this->dockerfile_location . $this->custom_labels . $this->custom_docker_run_options . $this->dockerfile_target_build; if ($this->pull_request_id === 0 || $this->pull_request_id === null) { $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); } else { diff --git a/app/Models/Service.php b/app/Models/Service.php index cb9d76831..9f0d2b67e 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -11,6 +11,46 @@ class Service extends BaseModel { use HasFactory, SoftDeletes; protected $guarded = []; + + public function isConfigurationChanged(bool $save = false) + { + $domains = $this->applications()->get()->pluck('fqdn')->toArray(); + $domains = implode(',', $domains); + + $applicationImages = $this->applications()->get()->pluck('image'); + $databaseImages = $this->databases()->get()->pluck('image'); + $images = $applicationImages->merge($databaseImages); + $images = implode(',', $images->toArray()); + + $applicationStorages = $this->applications()->get()->pluck('persistentStorages')->flatten(); + $databaseStorages = $this->databases()->get()->pluck('persistentStorages')->flatten(); + $storages = $applicationStorages->merge($databaseStorages)->implode('updated_at'); + + $newConfigHash = $images . $domains . $images . $storages; + $newConfigHash .= json_encode($this->environment_variables()->get('value')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status())->contains('exited'); + } public function type() { return 'service'; diff --git a/app/Models/StandaloneClickhouse.php b/app/Models/StandaloneClickhouse.php index 6016f5ca9..a3a7cea8f 100644 --- a/app/Models/StandaloneClickhouse.php +++ b/app/Models/StandaloneClickhouse.php @@ -42,6 +42,33 @@ class StandaloneClickhouse extends BaseModel $database->tags()->detach(); }); } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandaloneDragonfly.php b/app/Models/StandaloneDragonfly.php index d83b604f2..593b63506 100644 --- a/app/Models/StandaloneDragonfly.php +++ b/app/Models/StandaloneDragonfly.php @@ -41,7 +41,33 @@ class StandaloneDragonfly extends BaseModel $database->tags()->detach(); }); } - + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandaloneKeydb.php b/app/Models/StandaloneKeydb.php index 3bdbcfeff..be9e66992 100644 --- a/app/Models/StandaloneKeydb.php +++ b/app/Models/StandaloneKeydb.php @@ -41,7 +41,33 @@ class StandaloneKeydb extends BaseModel $database->tags()->detach(); }); } - + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->keydb_conf; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php index d5e14b3c5..4c143d9b8 100644 --- a/app/Models/StandaloneMariadb.php +++ b/app/Models/StandaloneMariadb.php @@ -43,6 +43,33 @@ class StandaloneMariadb extends BaseModel $database->tags()->detach(); }); } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->mariadb_conf; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index 268af9403..c23854376 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -46,6 +46,33 @@ class StandaloneMongodb extends BaseModel $database->tags()->detach(); }); } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->mongo_conf; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php index 6edbbe4b7..7885b8441 100644 --- a/app/Models/StandaloneMysql.php +++ b/app/Models/StandaloneMysql.php @@ -43,6 +43,33 @@ class StandaloneMysql extends BaseModel $database->tags()->detach(); }); } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->mysql_conf; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index ddf33f7ed..b42dbdcb8 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -55,6 +55,33 @@ class StandalonePostgresql extends BaseModel instant_remote_process(["rm -rf " . $this->workdir()], $server, false); } } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->postgres_initdb_args . $this->postgres_host_auth_method; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function realStatus() { return $this->getRawOriginal('status'); diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index 2ab189fa4..e6231be3c 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -38,6 +38,33 @@ class StandaloneRedis extends BaseModel $database->tags()->detach(); }); } + public function isConfigurationChanged(bool $save = false) + { + $newConfigHash = $this->image . $this->ports_mappings . $this->redis_conf; + $newConfigHash .= json_encode($this->environment_variables()->get('updated_at')); + $newConfigHash = md5($newConfigHash); + $oldConfigHash = data_get($this, 'config_hash'); + if ($oldConfigHash === null) { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + if ($oldConfigHash === $newConfigHash) { + return false; + } else { + if ($save) { + $this->config_hash = $newConfigHash; + $this->save(); + } + return true; + } + } + public function isExited() + { + return (bool) str($this->status)->startsWith('exited'); + } public function workdir() { return database_configuration_dir() . "/{$this->uuid}"; diff --git a/database/migrations/2024_04_10_082220_create_standalone_dragonflies_table.php b/database/migrations/2024_04_10_082220_create_standalone_dragonflies_table.php index 23b99b6d7..55f070a74 100644 --- a/database/migrations/2024_04_10_082220_create_standalone_dragonflies_table.php +++ b/database/migrations/2024_04_10_082220_create_standalone_dragonflies_table.php @@ -18,7 +18,6 @@ return new class extends Migration $table->string('description')->nullable(); $table->text('dragonfly_password'); - $table->longText('dragonfly_conf')->nullable(); $table->boolean('is_log_drain_enabled')->default(false); $table->boolean('is_include_timestamps')->default(false); diff --git a/database/migrations/2024_04_12_092337_add_config_hash_to_other_resources.php b/database/migrations/2024_04_12_092337_add_config_hash_to_other_resources.php new file mode 100644 index 000000000..83365f69e --- /dev/null +++ b/database/migrations/2024_04_12_092337_add_config_hash_to_other_resources.php @@ -0,0 +1,76 @@ +string('config_hash')->nullable(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_keydbs', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_dragonflies', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('standalone_clickhouses', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + Schema::table('services', function (Blueprint $table) { + $table->string('config_hash')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_keydbs', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_dragonflies', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('standalone_clickhouses', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + Schema::table('services', function (Blueprint $table) { + $table->dropColumn('config_hash'); + }); + } +}; diff --git a/resources/views/components/popup-small.blade.php b/resources/views/components/popup-small.blade.php index d623f3add..8370dcd07 100644 --- a/resources/views/components/popup-small.blade.php +++ b/resources/views/components/popup-small.blade.php @@ -1,8 +1,8 @@ @props(['title' => 'Default title', 'description' => 'Default Description', 'buttonText' => 'Default Button Text'])

Configuration

+
@@ -27,7 +28,7 @@ Source @endif - Servers @if (str($application->status)->contains('degraded')) diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.php index e47fab967..9c5e44080 100644 --- a/resources/views/livewire/project/application/deployment/index.blade.php +++ b/resources/views/livewire/project/application/deployment/index.blade.php @@ -1,5 +1,6 @@

Deployments

+ {{-- --}}

Deployment

+
Save - - @if ($isConfigurationChanged && !is_null($application->config_hash) && !$application->isExited()) - - - The latest configuration has not been applied. - - - - - - Please restart (or redeploy) to apply the new configuration, especially if you have changed your domains. - - - Disable This Popup - - - @endif +
General configuration for your application.
diff --git a/resources/views/livewire/project/database/backup/execution.blade.php b/resources/views/livewire/project/database/backup/execution.blade.php index 9a9a8733c..16a0ac493 100644 --- a/resources/views/livewire/project/database/backup/execution.blade.php +++ b/resources/views/livewire/project/database/backup/execution.blade.php @@ -1,5 +1,6 @@

Backups

+
diff --git a/resources/views/livewire/project/database/backup/index.blade.php b/resources/views/livewire/project/database/backup/index.blade.php index e26a28c3a..2208209c1 100644 --- a/resources/views/livewire/project/database/backup/index.blade.php +++ b/resources/views/livewire/project/database/backup/index.blade.php @@ -1,5 +1,6 @@

Backups

+
diff --git a/resources/views/livewire/project/database/configuration.blade.php b/resources/views/livewire/project/database/configuration.blade.php index f1b9f6e9e..1a69781da 100644 --- a/resources/views/livewire/project/database/configuration.blade.php +++ b/resources/views/livewire/project/database/configuration.blade.php @@ -1,5 +1,6 @@

Configuration

+
diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php index 709fa2032..f716b54f6 100644 --- a/resources/views/livewire/project/service/navbar.blade.php +++ b/resources/views/livewire/project/service/navbar.blade.php @@ -1,4 +1,5 @@
+ Service Startup diff --git a/resources/views/livewire/project/shared/configuration-checker.blade.php b/resources/views/livewire/project/shared/configuration-checker.blade.php new file mode 100644 index 000000000..a5c18039c --- /dev/null +++ b/resources/views/livewire/project/shared/configuration-checker.blade.php @@ -0,0 +1,22 @@ +
+ @if ($isConfigurationChanged && !is_null($resource->config_hash) && !$resource->isExited()) + + + The latest configuration has not been applied + + + + + + Please restart (or redeploy) to apply the new configuration. + + + Disable This Popup + + + @endif +
diff --git a/resources/views/livewire/project/shared/danger.blade.php b/resources/views/livewire/project/shared/danger.blade.php index 30d370ee6..3eb43380c 100644 --- a/resources/views/livewire/project/shared/danger.blade.php +++ b/resources/views/livewire/project/shared/danger.blade.php @@ -5,10 +5,11 @@
This will stop your containers, delete all related data, etc. Beware! There is no coming back!
- +
This resource will be deleted. It is not reversible. Please think again.

- +

Actions

+
diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index 7913b1cea..e71e0f269 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -1,4 +1,5 @@
+ @if ($type === 'application')

Execute Command

diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php index d681d0617..47942f452 100644 --- a/resources/views/livewire/project/shared/logs.blade.php +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -1,4 +1,5 @@
+ @if ($type === 'application')

Logs