Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: backups should be done with internal db url fix: create default database on mongodb start with a collection

Andras Bacsai91acd4cb6ab6
diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php
index fbdf0bba4f..645ed6ee95 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 9104434ea1..84aad1b6c5 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 56c644481a..6d9158a64d 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 669b43f58b..3a0432180a 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 a7d0a2a840..b8cd87fa3d 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://[email protected]/4505347448045568',
+ 'dsn' => 'https://[email protected]/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 36134c9475..63857a361e 100644
--- a/config/version.php
+++ b/config/version.php
@@ -1,3 +1,3 @@
<?php
-return '4.0.0-beta.98';
+return '4.0.0-beta.99';
diff --git a/versions.json b/versions.json
index e204d7ef15..fe4b26a879 100644
--- a/versions.json
+++ b/versions.json
@@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
- "version": "4.0.0-beta.98"
+ "version": "4.0.0-beta.99"
}
}
}