From f106e6e37bb03fdbe24d80f9844e61bd9b51fff2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 16 Aug 2024 13:56:47 +0200 Subject: [PATCH] feat: add custom docker container options to all databases --- app/Actions/Database/StartClickhouse.php | 17 ++-- app/Actions/Database/StartDragonfly.php | 15 ++- app/Actions/Database/StartKeydb.php | 18 ++-- app/Actions/Database/StartMariadb.php | 25 +++-- app/Actions/Database/StartMongodb.php | 26 ++--- app/Actions/Database/StartMysql.php | 25 +++-- app/Actions/Database/StartPostgresql.php | 5 + app/Actions/Database/StartRedis.php | 19 ++-- .../Project/Database/Clickhouse/General.php | 10 +- .../Project/Database/Dragonfly/General.php | 10 +- .../Project/Database/Keydb/General.php | 10 +- .../Project/Database/Mariadb/General.php | 10 +- .../Project/Database/Mongodb/General.php | 10 +- .../Project/Database/Mysql/General.php | 10 +- .../Project/Database/Postgresql/General.php | 2 + .../Project/Database/Redis/General.php | 10 +- bootstrap/helpers/docker.php | 95 +++++++++++-------- ...05649_add_custom_docker_options_to_dbs.php | 70 ++++++++++++++ .../database/clickhouse/general.blade.php | 8 +- .../database/dragonfly/general.blade.php | 4 + .../project/database/keydb/general.blade.php | 4 + .../database/mariadb/general.blade.php | 14 ++- .../database/mongodb/general.blade.php | 8 +- .../project/database/mysql/general.blade.php | 14 ++- .../database/postgresql/general.blade.php | 8 +- .../project/database/redis/general.blade.php | 4 + 26 files changed, 319 insertions(+), 132 deletions(-) create mode 100644 database/migrations/2024_08_16_105649_add_custom_docker_options_to_dbs.php diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index e97c55930..7cac97dd4 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -21,7 +21,7 @@ class StartClickhouse $this->database = $database; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -75,7 +75,7 @@ class StartClickhouse ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -102,6 +102,11 @@ class StartClickhouse if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -120,10 +125,10 @@ class StartClickhouse $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -154,11 +159,11 @@ class StartClickhouse $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('CLICKHOUSE_ADMIN_USER'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('CLICKHOUSE_ADMIN_USER'))->isEmpty()) { $environment_variables->push("CLICKHOUSE_ADMIN_USER={$this->database->clickhouse_admin_user}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('CLICKHOUSE_ADMIN_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('CLICKHOUSE_ADMIN_PASSWORD'))->isEmpty()) { $environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}"); } diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index 862fc54fc..b71e12e8e 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -23,7 +23,7 @@ class StartDragonfly $startCommand = "dragonfly --requirepass {$this->database->dragonfly_password}"; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -75,7 +75,7 @@ class StartDragonfly ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -102,6 +102,11 @@ class StartDragonfly if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -120,10 +125,10 @@ class StartDragonfly $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -154,7 +159,7 @@ class StartDragonfly $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { $environment_variables->push("REDIS_PASSWORD={$this->database->dragonfly_password}"); } diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index 85cb89c1c..46a6a760e 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -24,7 +24,7 @@ class StartKeydb $startCommand = "keydb-server --requirepass {$this->database->keydb_password} --appendonly yes"; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -74,7 +74,7 @@ class StartKeydb ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -101,15 +101,19 @@ class StartKeydb if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (! is_null($this->database->keydb_conf) || ! empty($this->database->keydb_conf)) { + if (!is_null($this->database->keydb_conf) || !empty($this->database->keydb_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/keydb.conf', + 'source' => $this->configuration_dir . '/keydb.conf', 'target' => '/etc/keydb/keydb.conf', 'read_only' => true, ]; $docker_compose['services'][$container_name]['command'] = "keydb-server /etc/keydb/keydb.conf --requirepass {$this->database->keydb_password} --appendonly yes"; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -128,10 +132,10 @@ class StartKeydb $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -162,7 +166,7 @@ class StartKeydb $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { $environment_variables->push("REDIS_PASSWORD={$this->database->keydb_password}"); } diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 33948192b..4868a5d33 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -21,7 +21,7 @@ class StartMariadb $this->database = $database; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -69,7 +69,7 @@ class StartMariadb ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -96,14 +96,19 @@ class StartMariadb if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (! is_null($this->database->mariadb_conf) || ! empty($this->database->mariadb_conf)) { + if (!is_null($this->database->mariadb_conf) || !empty($this->database->mariadb_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/custom-config.cnf', + 'source' => $this->configuration_dir . '/custom-config.cnf', 'target' => '/etc/mysql/conf.d/custom-config.cnf', 'read_only' => true, ]; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -122,10 +127,10 @@ class StartMariadb $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -156,18 +161,18 @@ class StartMariadb $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MARIADB_ROOT_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MARIADB_ROOT_PASSWORD'))->isEmpty()) { $environment_variables->push("MARIADB_ROOT_PASSWORD={$this->database->mariadb_root_password}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MARIADB_DATABASE'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MARIADB_DATABASE'))->isEmpty()) { $environment_variables->push("MARIADB_DATABASE={$this->database->mariadb_database}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MARIADB_USER'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MARIADB_USER'))->isEmpty()) { $environment_variables->push("MARIADB_USER={$this->database->mariadb_user}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MARIADB_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MARIADB_PASSWORD'))->isEmpty()) { $environment_variables->push("MARIADB_PASSWORD={$this->database->mariadb_password}"); } diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 911054f5e..b606cfe9e 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -23,7 +23,7 @@ class StartMongodb $startCommand = 'mongod'; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -77,7 +77,7 @@ class StartMongodb ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -104,23 +104,27 @@ class StartMongodb if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (! is_null($this->database->mongo_conf) || ! empty($this->database->mongo_conf)) { + if (!is_null($this->database->mongo_conf) || !empty($this->database->mongo_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/mongod.conf', + 'source' => $this->configuration_dir . '/mongod.conf', 'target' => '/etc/mongo/mongod.conf', 'read_only' => true, ]; - $docker_compose['services'][$container_name]['command'] = $startCommand.' --config /etc/mongo/mongod.conf'; + $docker_compose['services'][$container_name]['command'] = $startCommand . ' --config /etc/mongo/mongod.conf'; } $this->add_default_database(); $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/docker-entrypoint-initdb.d', + 'source' => $this->configuration_dir . '/docker-entrypoint-initdb.d', 'target' => '/docker-entrypoint-initdb.d', 'read_only' => true, ]; + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -139,10 +143,10 @@ class StartMongodb $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -173,15 +177,15 @@ class StartMongodb $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MONGO_INITDB_ROOT_USERNAME'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MONGO_INITDB_ROOT_USERNAME'))->isEmpty()) { $environment_variables->push("MONGO_INITDB_ROOT_USERNAME={$this->database->mongo_initdb_root_username}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MONGO_INITDB_ROOT_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MONGO_INITDB_ROOT_PASSWORD'))->isEmpty()) { $environment_variables->push("MONGO_INITDB_ROOT_PASSWORD={$this->database->mongo_initdb_root_password}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MONGO_INITDB_DATABASE'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MONGO_INITDB_DATABASE'))->isEmpty()) { $environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}"); } diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index b55d9dead..003a853f8 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -21,7 +21,7 @@ class StartMysql $this->database = $database; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -69,7 +69,7 @@ class StartMysql ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -96,14 +96,19 @@ class StartMysql if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (! is_null($this->database->mysql_conf) || ! empty($this->database->mysql_conf)) { + if (!is_null($this->database->mysql_conf) || !empty($this->database->mysql_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/custom-config.cnf', + 'source' => $this->configuration_dir . '/custom-config.cnf', 'target' => '/etc/mysql/conf.d/custom-config.cnf', 'read_only' => true, ]; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -122,10 +127,10 @@ class StartMysql $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -156,18 +161,18 @@ class StartMysql $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MYSQL_ROOT_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MYSQL_ROOT_PASSWORD'))->isEmpty()) { $environment_variables->push("MYSQL_ROOT_PASSWORD={$this->database->mysql_root_password}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MYSQL_DATABASE'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MYSQL_DATABASE'))->isEmpty()) { $environment_variables->push("MYSQL_DATABASE={$this->database->mysql_database}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MYSQL_USER'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MYSQL_USER'))->isEmpty()) { $environment_variables->push("MYSQL_USER={$this->database->mysql_user}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('MYSQL_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('MYSQL_PASSWORD'))->isEmpty()) { $environment_variables->push("MYSQL_PASSWORD={$this->database->mysql_password}"); } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 909f4c893..5f13471b6 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -37,6 +37,7 @@ class StartPostgresql $this->generate_init_scripts(); $this->add_custom_conf(); + $docker_compose = [ 'services' => [ $container_name => [ @@ -126,6 +127,10 @@ class StartPostgresql 'config_file=/etc/postgresql/postgresql.conf', ]; } + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index f10afef5e..3e1181522 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -24,7 +24,7 @@ class StartRedis $startCommand = "redis-server --requirepass {$this->database->redis_password} --appendonly yes"; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -78,7 +78,7 @@ class StartRedis ], ], ]; - if (! is_null($this->database->limits_cpuset)) { + if (!is_null($this->database->limits_cpuset)) { data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { @@ -105,15 +105,20 @@ class StartRedis if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - if (! is_null($this->database->redis_conf) || ! empty($this->database->redis_conf)) { + if (!is_null($this->database->redis_conf) || !empty($this->database->redis_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/redis.conf', + 'source' => $this->configuration_dir . '/redis.conf', 'target' => '/usr/local/etc/redis/redis.conf', 'read_only' => true, ]; $docker_compose['services'][$container_name]['command'] = "redis-server /usr/local/etc/redis/redis.conf --requirepass {$this->database->redis_password} --appendonly yes"; } + + // Add custom docker run options + $docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options); + $docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network); + $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null"; @@ -132,10 +137,10 @@ class StartRedis $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -166,7 +171,7 @@ class StartRedis $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('REDIS_PASSWORD'))->isEmpty()) { $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}"); } diff --git a/app/Livewire/Project/Database/Clickhouse/General.php b/app/Livewire/Project/Database/Clickhouse/General.php index ffdbe95c3..a6e2a1320 100644 --- a/app/Livewire/Project/Database/Clickhouse/General.php +++ b/app/Livewire/Project/Database/Clickhouse/General.php @@ -31,6 +31,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -42,6 +43,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() @@ -54,7 +56,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -71,14 +73,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -93,7 +95,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Dragonfly/General.php b/app/Livewire/Project/Database/Dragonfly/General.php index f81f4a2f0..00e0ff09f 100644 --- a/app/Livewire/Project/Database/Dragonfly/General.php +++ b/app/Livewire/Project/Database/Dragonfly/General.php @@ -30,6 +30,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -40,6 +41,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() @@ -52,7 +54,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -86,14 +88,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -108,7 +110,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Keydb/General.php b/app/Livewire/Project/Database/Keydb/General.php index 2b78c9f10..320feeac7 100644 --- a/app/Livewire/Project/Database/Keydb/General.php +++ b/app/Livewire/Project/Database/Keydb/General.php @@ -31,6 +31,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -42,6 +43,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() @@ -55,7 +57,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -92,14 +94,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -114,7 +116,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Mariadb/General.php b/app/Livewire/Project/Database/Mariadb/General.php index 858d7b383..70545910c 100644 --- a/app/Livewire/Project/Database/Mariadb/General.php +++ b/app/Livewire/Project/Database/Mariadb/General.php @@ -34,6 +34,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -48,6 +49,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Options', ]; public function mount() @@ -61,7 +63,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -98,14 +100,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -120,7 +122,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Mongodb/General.php b/app/Livewire/Project/Database/Mongodb/General.php index 5a5ef8a62..d23b66c00 100644 --- a/app/Livewire/Project/Database/Mongodb/General.php +++ b/app/Livewire/Project/Database/Mongodb/General.php @@ -33,6 +33,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -46,6 +47,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() @@ -59,7 +61,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -99,14 +101,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -121,7 +123,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Mysql/General.php b/app/Livewire/Project/Database/Mysql/General.php index 58d8e03a8..29a9cbae2 100644 --- a/app/Livewire/Project/Database/Mysql/General.php +++ b/app/Livewire/Project/Database/Mysql/General.php @@ -34,6 +34,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -48,6 +49,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() @@ -60,7 +62,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -97,14 +99,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -119,7 +121,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/app/Livewire/Project/Database/Postgresql/General.php b/app/Livewire/Project/Database/Postgresql/General.php index eabbbd679..c12fa49f3 100644 --- a/app/Livewire/Project/Database/Postgresql/General.php +++ b/app/Livewire/Project/Database/Postgresql/General.php @@ -49,6 +49,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -65,6 +66,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Run Options', ]; public function mount() diff --git a/app/Livewire/Project/Database/Redis/General.php b/app/Livewire/Project/Database/Redis/General.php index a7ce0161a..fd2f9834f 100644 --- a/app/Livewire/Project/Database/Redis/General.php +++ b/app/Livewire/Project/Database/Redis/General.php @@ -31,6 +31,7 @@ class General extends Component 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', 'database.is_log_drain_enabled' => 'nullable|boolean', + 'database.custom_docker_run_options' => 'nullable', ]; protected $validationAttributes = [ @@ -42,6 +43,7 @@ class General extends Component 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', 'database.public_port' => 'Public Port', + 'database.custom_docker_run_options' => 'Custom Docker Options', ]; public function mount() @@ -55,7 +57,7 @@ class General extends Component public function instantSaveAdvanced() { try { - if (! $this->server->isLogDrainEnabled()) { + if (!$this->server->isLogDrainEnabled()) { $this->database->is_log_drain_enabled = false; $this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.'); @@ -86,14 +88,14 @@ class General extends Component public function instantSave() { try { - if ($this->database->is_public && ! $this->database->public_port) { + if ($this->database->is_public && !$this->database->public_port) { $this->dispatch('error', 'Public port is required.'); $this->database->is_public = false; return; } if ($this->database->is_public) { - if (! str($this->database->status)->startsWith('running')) { + if (!str($this->database->status)->startsWith('running')) { $this->dispatch('error', 'Database must be started to be publicly accessible.'); $this->database->is_public = false; @@ -108,7 +110,7 @@ class General extends Component $this->db_url_public = $this->database->external_db_url; $this->database->save(); } catch (\Throwable $e) { - $this->database->is_public = ! $this->database->is_public; + $this->database->is_public = !$this->database->is_public; return handleError($e, $this); } diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index bfb61b4d4..0333e8660 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -13,13 +13,13 @@ use Visus\Cuid2\Cuid2; function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pullRequestId = null, ?bool $includePullrequests = false): Collection { $containers = collect([]); - if (! $server->isSwarm()) { + if (!$server->isSwarm()) { $containers = instant_remote_process(["docker ps -a --filter='label=coolify.applicationId={$id}' --format '{{json .}}' "], $server); $containers = format_docker_command_output_to_json($containers); $containers = $containers->map(function ($container) use ($pullRequestId, $includePullrequests) { $labels = data_get($container, 'Labels'); - if (! str($labels)->contains('coolify.pullRequestId=')) { - data_set($container, 'Labels', $labels.",coolify.pullRequestId={$pullRequestId}"); + if (!str($labels)->contains('coolify.pullRequestId=')) { + data_set($container, 'Labels', $labels . ",coolify.pullRequestId={$pullRequestId}"); return $container; } @@ -51,14 +51,14 @@ function format_docker_command_output_to_json($rawOutput): Collection try { return $outputLines - ->reject(fn ($line) => empty($line)) - ->map(fn ($outputLine) => json_decode($outputLine, true, flags: JSON_THROW_ON_ERROR)); + ->reject(fn($line) => empty($line)) + ->map(fn($outputLine) => json_decode($outputLine, true, flags: JSON_THROW_ON_ERROR)); } catch (\Throwable $e) { return collect([]); } } -function format_docker_labels_to_json(string|array $rawOutput): Collection +function format_docker_labels_to_json(string | array $rawOutput): Collection { if (is_array($rawOutput)) { return collect($rawOutput); @@ -66,7 +66,7 @@ function format_docker_labels_to_json(string|array $rawOutput): Collection $outputLines = explode(PHP_EOL, $rawOutput); return collect($outputLines) - ->reject(fn ($line) => empty($line)) + ->reject(fn($line) => empty($line)) ->map(function ($outputLine) { $outputArray = explode(',', $outputLine); @@ -116,7 +116,7 @@ function getContainerStatus(Server $server, string $container_id, bool $all_data } else { $container = instant_remote_process(["docker inspect --format '{{json .}}' {$container_id}"], $server, $throwError); } - if (! $container) { + if (!$container) { return 'exited'; } $container = format_docker_command_output_to_json($container); @@ -143,13 +143,13 @@ function generateApplicationContainerName(Application $application, $pull_reques $consistent_container_name = $application->settings->is_consistent_container_name_enabled; $now = now()->format('Hisu'); if ($pull_request_id !== 0 && $pull_request_id !== null) { - return $application->uuid.'-pr-'.$pull_request_id; + return $application->uuid . '-pr-' . $pull_request_id; } else { if ($consistent_container_name) { return $application->uuid; } - return $application->uuid.'-'.$now; + return $application->uuid . '-' . $now; } } function get_port_from_dockerfile($dockerfile): ?int @@ -174,19 +174,19 @@ function defaultLabels($id, $name, $pull_request_id = 0, string $type = 'applica { $labels = collect([]); $labels->push('coolify.managed=true'); - $labels->push('coolify.version='.config('version')); - $labels->push('coolify.'.$type.'Id='.$id); + $labels->push('coolify.version=' . config('version')); + $labels->push('coolify.' . $type . 'Id=' . $id); $labels->push("coolify.type=$type"); - $labels->push('coolify.name='.$name); - $labels->push('coolify.pullRequestId='.$pull_request_id); + $labels->push('coolify.name=' . $name); + $labels->push('coolify.pullRequestId=' . $pull_request_id); if ($type === 'service') { - $subId && $labels->push('coolify.service.subId='.$subId); - $subType && $labels->push('coolify.service.subType='.$subType); + $subId && $labels->push('coolify.service.subId=' . $subId); + $subType && $labels->push('coolify.service.subType=' . $subType); } return $labels; } -function generateServiceSpecificFqdns(ServiceApplication|Application $resource) +function generateServiceSpecificFqdns(ServiceApplication | Application $resource) { if ($resource->getMorphClass() === 'App\Models\ServiceApplication') { $uuid = data_get($resource, 'uuid'); @@ -213,17 +213,17 @@ function generateServiceSpecificFqdns(ServiceApplication|Application $resource) } if (is_null($MINIO_BROWSER_REDIRECT_URL?->value)) { $MINIO_BROWSER_REDIRECT_URL?->update([ - 'value' => generateFqdn($server, 'console-'.$uuid), + 'value' => generateFqdn($server, 'console-' . $uuid), ]); } if (is_null($MINIO_SERVER_URL?->value)) { $MINIO_SERVER_URL?->update([ - 'value' => generateFqdn($server, 'minio-'.$uuid), + 'value' => generateFqdn($server, 'minio-' . $uuid), ]); } $payload = collect([ - $MINIO_BROWSER_REDIRECT_URL->value.':9001', - $MINIO_SERVER_URL->value.':9000', + $MINIO_BROWSER_REDIRECT_URL->value . ':9001', + $MINIO_SERVER_URL->value . ':9000', ]); break; case $type?->contains('logto'): @@ -234,17 +234,17 @@ function generateServiceSpecificFqdns(ServiceApplication|Application $resource) } if (is_null($LOGTO_ENDPOINT?->value)) { $LOGTO_ENDPOINT?->update([ - 'value' => generateFqdn($server, 'logto-'.$uuid), + 'value' => generateFqdn($server, 'logto-' . $uuid), ]); } if (is_null($LOGTO_ADMIN_ENDPOINT?->value)) { $LOGTO_ADMIN_ENDPOINT?->update([ - 'value' => generateFqdn($server, 'logto-admin-'.$uuid), + 'value' => generateFqdn($server, 'logto-admin-' . $uuid), ]); } $payload = collect([ - $LOGTO_ENDPOINT->value.':3001', - $LOGTO_ADMIN_ENDPOINT->value.':3002', + $LOGTO_ENDPOINT->value . ':3001', + $LOGTO_ADMIN_ENDPOINT->value . ':3002', ]); break; } @@ -267,7 +267,7 @@ function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, $host_without_www = str($host)->replace('www.', ''); $schema = $url->getScheme(); $port = $url->getPort(); - if (is_null($port) && ! is_null($onlyPort)) { + if (is_null($port) && !is_null($onlyPort)) { $port = $onlyPort; } $labels->push("caddy_{$loop}={$schema}://{$host}"); @@ -283,7 +283,7 @@ function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, if ($is_gzip_enabled) { $labels->push("caddy_{$loop}.encode=zstd gzip"); } - if ($redirect_direction === 'www' && ! str($host)->startsWith('www.')) { + if ($redirect_direction === 'www' && !str($host)->startsWith('www.')) { $labels->push("caddy_{$loop}.redir={$schema}://www.{$host}{uri}"); } if ($redirect_direction === 'non-www' && str($host)->startsWith('www.')) { @@ -347,7 +347,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $path = $url->getPath(); $schema = $url->getScheme(); $port = $url->getPort(); - if (is_null($port) && ! is_null($onlyPort)) { + if (is_null($port) && !is_null($onlyPort)) { $port = $onlyPort; } $http_label = "http-{$loop}-{$uuid}"; @@ -383,7 +383,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ } if ($path !== '/') { $middlewares = collect([]); - if ($is_stripprefix_enabled && ! str($image)->contains('ghost')) { + if ($is_stripprefix_enabled && !str($image)->contains('ghost')) { $labels->push("traefik.http.middlewares.{$https_label}-stripprefix.stripprefix.prefixes={$path}"); $middlewares->push("{$https_label}-stripprefix"); } @@ -403,7 +403,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels = $labels->merge($redirect_to_non_www); $middlewares->push($to_non_www_name); } - if ($redirect_direction === 'www' && ! str($host)->startsWith('www.')) { + if ($redirect_direction === 'www' && !str($host)->startsWith('www.')) { $labels = $labels->merge($redirect_to_www); $middlewares->push($to_www_name); } @@ -429,7 +429,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels = $labels->merge($redirect_to_non_www); $middlewares->push($to_non_www_name); } - if ($redirect_direction === 'www' && ! str($host)->startsWith('www.')) { + if ($redirect_direction === 'www' && !str($host)->startsWith('www.')) { $labels = $labels->merge($redirect_to_www); $middlewares->push($to_www_name); } @@ -461,7 +461,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ } if ($path !== '/') { $middlewares = collect([]); - if ($is_stripprefix_enabled && ! str($image)->contains('ghost')) { + if ($is_stripprefix_enabled && !str($image)->contains('ghost')) { $labels->push("traefik.http.middlewares.{$http_label}-stripprefix.stripprefix.prefixes={$path}"); $middlewares->push("{$http_label}-stripprefix"); } @@ -481,7 +481,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels = $labels->merge($redirect_to_non_www); $middlewares->push($to_non_www_name); } - if ($redirect_direction === 'www' && ! str($host)->startsWith('www.')) { + if ($redirect_direction === 'www' && !str($host)->startsWith('www.')) { $labels = $labels->merge($redirect_to_www); $middlewares->push($to_www_name); } @@ -507,7 +507,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels = $labels->merge($redirect_to_non_www); $middlewares->push($to_non_www_name); } - if ($redirect_direction === 'www' && ! str($host)->startsWith('www.')) { + if ($redirect_direction === 'www' && !str($host)->startsWith('www.')) { $labels = $labels->merge($redirect_to_www); $middlewares->push($to_www_name); } @@ -534,7 +534,7 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview $pull_request_id = data_get($preview, 'pull_request_id', 0); $appUuid = $application->uuid; if ($pull_request_id !== 0) { - $appUuid = $appUuid.'-pr-'.$pull_request_id; + $appUuid = $appUuid . '-pr-' . $pull_request_id; } $labels = collect([]); if ($pull_request_id === 0) { @@ -706,7 +706,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null // Easily get mappings from https://github.com/composerize/composerize/blob/master/packages/composerize/src/mappings.js foreach ($options as $option => $value) { // ray($option,$value); - if (! data_get($mapping, $option)) { + if (!data_get($mapping, $option)) { continue; } if ($option === '--ulimit') { @@ -737,7 +737,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null } else { if ($list_options->contains($option)) { if ($compose_options->has($mapping[$option])) { - $compose_options->put($mapping[$option], $options->get($mapping[$option]).','.$value); + $compose_options->put($mapping[$option], $options->get($mapping[$option]) . ',' . $value); } else { $compose_options->put($mapping[$option], $value); } @@ -755,7 +755,26 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null return $compose_options->toArray(); } -function validateComposeFile(string $compose, int $server_id): string|Throwable +function generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $network) +{ + $ipv4 = data_get($docker_run_options, 'ip.0'); + $ipv6 = data_get($docker_run_options, 'ip6.0'); + data_forget($docker_run_options, 'ip'); + data_forget($docker_run_options, 'ip6'); + if ($ipv4 || $ipv6) { + data_forget($docker_compose['services'][$container_name], 'networks'); + } + if ($ipv4) { + $docker_compose['services'][$container_name]['networks'][$network]['ipv4_address'] = $ipv4; + } + if ($ipv6) { + $docker_compose['services'][$container_name]['networks'][$network]['ipv6_address'] = $ipv6; + } + $docker_compose['services'][$container_name] = array_merge_recursive($docker_compose['services'][$container_name], $docker_run_options); + return $docker_compose; +} + +function validateComposeFile(string $compose, int $server_id): string | Throwable { return 'OK'; try { diff --git a/database/migrations/2024_08_16_105649_add_custom_docker_options_to_dbs.php b/database/migrations/2024_08_16_105649_add_custom_docker_options_to_dbs.php new file mode 100644 index 000000000..dbca8c10a --- /dev/null +++ b/database/migrations/2024_08_16_105649_add_custom_docker_options_to_dbs.php @@ -0,0 +1,70 @@ +text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_clickhouses', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_dragonflies', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_keydbs', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->text('custom_docker_run_options')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_clickhouses', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_dragonflies', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_keydbs', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->dropColumn('custom_docker_run_options'); + }); + } +}; diff --git a/resources/views/livewire/project/database/clickhouse/general.blade.php b/resources/views/livewire/project/database/clickhouse/general.blade.php index 78a2c4952..f94d79ff4 100644 --- a/resources/views/livewire/project/database/clickhouse/general.blade.php +++ b/resources/views/livewire/project/database/clickhouse/general.blade.php @@ -21,14 +21,18 @@ readonly helper="You can only change this in the database." /> @else -
Please verify these values. You can only modify them before the initial +
Please verify these values. You can only modify them before the initial start. After that, you need to modify it in the database.
-
+
@endif +

Network

diff --git a/resources/views/livewire/project/database/dragonfly/general.blade.php b/resources/views/livewire/project/database/dragonfly/general.blade.php index c6ee13fa3..e1ce5ddaf 100644 --- a/resources/views/livewire/project/database/dragonfly/general.blade.php +++ b/resources/views/livewire/project/database/dragonfly/general.blade.php @@ -11,6 +11,10 @@
+

Network

diff --git a/resources/views/livewire/project/database/keydb/general.blade.php b/resources/views/livewire/project/database/keydb/general.blade.php index d1134d73d..cf8955a2f 100644 --- a/resources/views/livewire/project/database/keydb/general.blade.php +++ b/resources/views/livewire/project/database/keydb/general.blade.php @@ -12,6 +12,10 @@
+

Network

diff --git a/resources/views/livewire/project/database/mariadb/general.blade.php b/resources/views/livewire/project/database/mariadb/general.blade.php index ddb35a6bc..7c0a6bcba 100644 --- a/resources/views/livewire/project/database/mariadb/general.blade.php +++ b/resources/views/livewire/project/database/mariadb/general.blade.php @@ -16,30 +16,40 @@ automations (like backups) won't work.
@if ($database->started_at) -
+
+
+
@else -
+
+
+
@endif +
+ +

Network

diff --git a/resources/views/livewire/project/database/mongodb/general.blade.php b/resources/views/livewire/project/database/mongodb/general.blade.php index a5017b21f..8fc86ae1c 100644 --- a/resources/views/livewire/project/database/mongodb/general.blade.php +++ b/resources/views/livewire/project/database/mongodb/general.blade.php @@ -16,7 +16,7 @@ automations (like backups) won't work.
@if ($database->started_at) -
+
@@ -28,7 +28,7 @@ helper="You can only change this in the database." />
@else -
+
@@ -36,6 +36,10 @@ placeholder="If empty, it will be the same as Username." />
@endif +

Network

diff --git a/resources/views/livewire/project/database/mysql/general.blade.php b/resources/views/livewire/project/database/mysql/general.blade.php index 85cbef0dd..40fcca1e8 100644 --- a/resources/views/livewire/project/database/mysql/general.blade.php +++ b/resources/views/livewire/project/database/mysql/general.blade.php @@ -16,30 +16,40 @@ automations (like backups) won't work.
@if ($database->started_at) -
+
+
+
@else -
+
+
+
@endif +
+ +

Network

diff --git a/resources/views/livewire/project/database/postgresql/general.blade.php b/resources/views/livewire/project/database/postgresql/general.blade.php index 718c44f97..c39f968d8 100644 --- a/resources/views/livewire/project/database/postgresql/general.blade.php +++ b/resources/views/livewire/project/database/postgresql/general.blade.php @@ -30,7 +30,7 @@ automations (like backups) won't work.
@if ($database->started_at) -
+
@else -
+
+

Network

diff --git a/resources/views/livewire/project/database/redis/general.blade.php b/resources/views/livewire/project/database/redis/general.blade.php index ceb12a802..7d4de27cd 100644 --- a/resources/views/livewire/project/database/redis/general.blade.php +++ b/resources/views/livewire/project/database/redis/general.blade.php @@ -12,6 +12,10 @@
+

Network