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

View File

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

View File

@ -21,59 +21,12 @@ protected static function booted()
static::created(function ($database) { static::created(function ($database) {
LocalPersistentVolume::create([ LocalPersistentVolume::create([
'name' => 'clickhouse-data-' . $database->uuid, 'name' => 'clickhouse-data-' . $database->uuid,
'mount_path' => '/var/lib/clickhouse/', 'mount_path' => '/bitnami/clickhouse',
'host_path' => null, 'host_path' => null,
'resource_id' => $database->id, 'resource_id' => $database->id,
'resource_type' => $database->getMorphClass(), 'resource_type' => $database->getMorphClass(),
'is_readonly' => true '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) { static::deleting(function ($database) {
$storages = $database->persistentStorages()->get(); $storages = $database->persistentStorages()->get();

View File

@ -130,7 +130,7 @@ function create_standalone_clickhouse($environment_id, $destination_uuid): Stand
} }
return StandaloneClickhouse::create([ return StandaloneClickhouse::create([
'name' => generate_database_name('clickhouse'), 'name' => generate_database_name('clickhouse'),
'clickhouse_password' => \Illuminate\Support\Str::password(length: 64, symbols: false), 'clickhouse_admin_password' => \Illuminate\Support\Str::password(length: 64, symbols: false),
'environment_id' => $environment_id, 'environment_id' => $environment_id,
'destination_id' => $destination->id, 'destination_id' => $destination->id,
'destination_type' => $destination->getMorphClass(), 'destination_type' => $destination->getMorphClass(),

View File

@ -17,9 +17,8 @@ public function up(): void
$table->string('name'); $table->string('name');
$table->string('description')->nullable(); $table->string('description')->nullable();
$table->string('clickhouse_user')->default('clickhouse'); $table->string('clickhouse_admin_user')->default('default');
$table->text('clickhouse_password'); $table->text('clickhouse_admin_password');
$table->string('clickhouse_db')->default('default');
$table->boolean('is_log_drain_enabled')->default(false); $table->boolean('is_log_drain_enabled')->default(false);
$table->boolean('is_include_timestamps')->default(false); $table->boolean('is_include_timestamps')->default(false);
@ -27,7 +26,7 @@ public function up(): void
$table->string('status')->default('exited'); $table->string('status')->default('exited');
$table->string('image')->default('clickhouse/clickhouse-server'); $table->string('image')->default('bitnami/clickhouse');
$table->boolean('is_public')->default(false); $table->boolean('is_public')->default(false);
$table->integer('public_port')->nullable(); $table->integer('public_port')->nullable();

View File

@ -15,23 +15,18 @@
@if ($database->started_at) @if ($database->started_at)
<div class="flex gap-2"> <div class="flex gap-2">
<x-forms.input label="Initial Username" id="database.clickhouse_user" placeholder="If empty: clickhouse" <x-forms.input label="Initial Username" id="database.clickhouse_admin_user" placeholder="If empty: clickhouse"
readonly helper="You can only change this in the database." /> readonly helper="You can only change this in the database." />
<x-forms.input label="Initial Password" id="database.clickhouse_password" type="password" required <x-forms.input label="Initial Password" id="database.clickhouse_admin_password" type="password" required
readonly helper="You can only change this in the database." /> readonly helper="You can only change this in the database." />
<x-forms.input label="Initial Database" id="database.clickhouse_db"
placeholder="If empty, it will be the same as Username." readonly
helper="You can only change this in the database." />
</div> </div>
@else @else
<div class="pt-8 dark:text-warning">Please verify these values. You can only modify them before the initial <div class="pt-8 dark:text-warning">Please verify these values. You can only modify them before the initial
start. After that, you need to modify it in the database. start. After that, you need to modify it in the database.
</div> </div>
<div class="flex gap-2 pb-8"> <div class="flex gap-2 pb-8">
<x-forms.input label="Username" id="database.clickhouse_user" readonly /> <x-forms.input label="Username" id="database.clickhouse_admin_user" required />
<x-forms.input label="Password" id="database.clickhouse_password" type="password" required /> <x-forms.input label="Password" id="database.clickhouse_admin_password" type="password" required />
<x-forms.input label="Database" id="database.clickhouse_db"
placeholder="If empty, it will be the same as Username." />
</div> </div>
@endif @endif
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">