Update Clickhouse database credentials and variables

This commit is contained in:
Andras Bacsai
2024-04-11 13:45:02 +02:00
parent e71032a8fc
commit 1e7a5562ab
6 changed files with 19 additions and 81 deletions

View File

@@ -19,7 +19,6 @@ class StartClickhouse
{
$this->database = $database;
$startCommand = "clickhouse-server";
$container_name = $this->database->uuid;
$this->configuration_dir = database_configuration_dir() . '/' . $container_name;
@@ -32,13 +31,12 @@ class StartClickhouse
$persistent_storages = $this->generate_local_persistent_volumes();
$volume_names = $this->generate_local_persistent_volumes_only_volume_names();
$environment_variables = $this->generate_environment_variables();
ray($environment_variables);
$docker_compose = [
'version' => '3.8',
'services' => [
$container_name => [
'image' => $this->database->image,
'command' => $startCommand,
'container_name' => $container_name,
'environment' => $environment_variables,
'restart' => RESTART_MODE,
@@ -54,9 +52,8 @@ class StartClickhouse
'labels' => [
'coolify.managed' => 'true',
],
'user' => $this->database->clickhouse_user,
'healthcheck' => [
'test' => "wget -qO- http://localhost:8123/ping || exit 1",
'test' => "clickhouse-client --password {$this->database->clickhouse_admin_password} --query 'SELECT 1'",
'interval' => '5s',
'timeout' => '5s',
'retries' => 10,
@@ -149,16 +146,12 @@ class StartClickhouse
$environment_variables->push("$env->key=$env->real_value");
}
if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('CLICKHOUSE_DB'))->isEmpty()) {
$environment_variables->push("CLICKHOUSE_DB={$this->database->clickhouse_db}");
if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('CLICKHOUSE_ADMIN_USER'))->isEmpty()) {
$environment_variables->push("CLICKHOUSE_ADMIN_USER={$this->database->clickhouse_admin_user}");
}
if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('CLICKHOUSE_USER'))->isEmpty()) {
$environment_variables->push("CLICKHOUSE_USER={$this->database->clickhouse_user}");
}
if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('CLICKHOUSE_PASSWORD'))->isEmpty()) {
$environment_variables->push("CLICKHOUSE_PASSWORD={$this->database->clickhouse_password}");
if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('CLICKHOUSE_ADMIN_PASSWORD'))->isEmpty()) {
$environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}");
}
return $environment_variables->all();

View File

@@ -19,9 +19,8 @@ class General extends Component
protected $rules = [
'database.name' => 'required',
'database.description' => 'nullable',
'database.clickhouse_user' => 'required',
'database.clickhouse_password' => 'required',
'database.clickhouse_db' => 'required',
'database.clickhouse_admin_user' => 'required',
'database.clickhouse_admin_password' => 'required',
'database.image' => 'required',
'database.ports_mappings' => 'nullable',
'database.is_public' => 'nullable|boolean',
@@ -31,9 +30,8 @@ class General extends Component
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
'database.clickhouse_user' => 'Postgres User',
'database.clickhouse_password' => 'Postgres Password',
'database.clickhouse_db' => 'Postgres DB',
'database.clickhouse_admin_user' => 'Postgres User',
'database.clickhouse_admin_password' => 'Postgres Password',
'database.image' => 'Image',
'database.ports_mappings' => 'Port Mapping',
'database.is_public' => 'Is Public',

View File

@@ -21,59 +21,12 @@ class StandaloneClickhouse extends BaseModel
static::created(function ($database) {
LocalPersistentVolume::create([
'name' => 'clickhouse-data-' . $database->uuid,
'mount_path' => '/var/lib/clickhouse/',
'mount_path' => '/bitnami/clickhouse',
'host_path' => null,
'resource_id' => $database->id,
'resource_type' => $database->getMorphClass(),
'is_readonly' => true
]);
LocalPersistentVolume::create([
'name' => 'clickhouse-logs-' . $database->uuid,
'mount_path' => '/var/log/clickhouse-server/',
'host_path' => null,
'resource_id' => $database->id,
'resource_type' => $database->getMorphClass(),
'is_readonly' => true
]);
// LocalFileVolume::create(
// [
// 'mount_path' => '/etc/clickhouse-server/config.d/docker_related_config.xml',
// 'resource_id' => $database->id,
// 'resource_type' => $database->getMorphClass(),
// 'chown' => '101:101',
// 'chmod' => '644',
// 'fs_path' => database_configuration_dir() . '/' . $database->uuid . '/config.d/docker_related_config.xml',
// 'content' => '<clickhouse>
// <!-- Listen wildcard address to allow accepting connections from other containers and host network. -->
// <listen_host>::</listen_host>
// <listen_host>0.0.0.0</listen_host>
// <listen_try>1</listen_try>
// <!--
// <logger>
// <console>1</console>
// </logger>
// -->
// </clickhouse>',
// 'is_directory' => 'false',
// ]
// );
// LocalPersistentVolume::create([
// 'name' => 'clickhouse-config-' . $database->uuid,
// 'mount_path' => '/etc/clickhouse-server/config.d',
// 'host_path' => database_configuration_dir() . '/' . $database->uuid . '/config.d',
// 'resource_id' => $database->id,
// 'resource_type' => $database->getMorphClass(),
// 'is_readonly' => true
// ]);
// LocalPersistentVolume::create([
// 'name' => 'clickhouse-config-users-' . $database->uuid,
// 'mount_path' => '/etc/clickhouse-server/users.d',
// 'host_path' => database_configuration_dir() . '/' . $database->uuid . '/users.d',
// 'resource_id' => $database->id,
// 'resource_type' => $database->getMorphClass(),
// 'is_readonly' => true
// ]);
});
static::deleting(function ($database) {
$storages = $database->persistentStorages()->get();