diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index fbdf0bba4..645ed6ee9 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -94,6 +94,14 @@ class StartMongodb ]; $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', + 'target' => '/docker-entrypoint-initdb.d', + 'read_only' => true, + ]; + $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"; @@ -160,4 +168,11 @@ class StartMongodb $content_base64 = base64_encode($content); $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/{$filename}"; } + private function add_default_database() + { + $content = "db = db.getSiblingDB(\"{$this->database->mongo_initdb_database}\");db.createCollection('init_collection');db.createUser({user: \"{$this->database->mongo_initdb_root_username}\", pwd: \"{$this->database->mongo_initdb_root_password}\",roles: [{role:\"readWrite\",db:\"{$this->database->mongo_initdb_database}\"}]});"; + $content_base64 = base64_encode($content); + $this->commands[] = "mkdir -p $this->configuration_dir/docker-entrypoint-initdb.d"; + $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/docker-entrypoint-initdb.d/01-default-database.js"; + } } diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php index 9104434ea..84aad1b6c 100644 --- a/app/Jobs/DatabaseBackupJob.php +++ b/app/Jobs/DatabaseBackupJob.php @@ -170,7 +170,7 @@ class DatabaseBackupJob implements ShouldQueue, ShouldBeEncrypted private function backup_standalone_mongodb(string $databaseWithCollections): void { try { - $url = $this->database->getDbUrl(); + $url = $this->database->getDbUrl(useInternal: true); if ($databaseWithCollections === 'all') { $commands[] = "mkdir -p " . $this->backup_dir; $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --gzip --archive > $this->backup_location"; diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index 56c644481..6d9158a64 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -15,8 +15,16 @@ class StandaloneMongodb extends BaseModel { static::created(function ($database) { LocalPersistentVolume::create([ - 'name' => 'mongodb-data-' . $database->uuid, - 'mount_path' => '/data', + 'name' => 'mongodb-configdb-' . $database->uuid, + 'mount_path' => '/data/configdb', + 'host_path' => null, + 'resource_id' => $database->id, + 'resource_type' => $database->getMorphClass(), + 'is_readonly' => true + ]); + LocalPersistentVolume::create([ + 'name' => 'mongodb-db-' . $database->uuid, + 'mount_path' => '/data/db', 'host_path' => null, 'resource_id' => $database->id, 'resource_type' => $database->getMorphClass(), @@ -55,8 +63,8 @@ class StandaloneMongodb extends BaseModel { return 'standalone-mongodb'; } - public function getDbUrl() { - if ($this->is_public) { + public function getDbUrl(bool $useInternal = false) { + if ($this->is_public && !$useInternal) { return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true"; } else { return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->uuid}:27017/?directConnection=true"; diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index 669b43f58..3a0432180 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -62,9 +62,9 @@ class StandalonePostgresql extends BaseModel { return 'standalone-postgresql'; } - public function getDbUrl(): string + public function getDbUrl(bool $useInternal = false): string { - if ($this->is_public) { + if ($this->is_public && !$useInternal) { return "postgres://{$this->postgres_user}:{$this->postgres_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->postgres_db}"; } else { return "postgres://{$this->postgres_user}:{$this->postgres_password}@{$this->uuid}:5432/{$this->postgres_db}"; diff --git a/config/sentry.php b/config/sentry.php index a7d0a2a84..b8cd87fa3 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -3,11 +3,11 @@ return [ // @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/ - 'dsn' => 'https://72f02655749d5d687297b6b9f078b8b9@o1082494.ingest.sentry.io/4505347448045568', + 'dsn' => 'https://c35fe90ee56e18b220bb55e8217d4839@o1082494.ingest.sentry.io/4505347448045568', // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.98', + 'release' => '4.0.0-beta.99', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 36134c947..63857a361 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@