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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: standalone mongodb
Andras Bacsaic53d88902c00
diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.phpindex eccdf1a6a7..15009019da 100644--- a/app/Actions/Database/StartDatabaseProxy.php+++ b/app/Actions/Database/StartDatabaseProxy.php@@ -2,6 +2,7 @@namespace App\Actions\Database;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;use Lorisleiva\Actions\Concerns\AsAction;@@ -11,13 +12,15 @@ class StartDatabaseProxy{use AsAction;- public function handle(StandaloneRedis|StandalonePostgresql $database)+ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb $database){$internalPort = null;- if ($database->getMorphClass()=== 'App\Models\StandaloneRedis') {+ if ($database->getMorphClass() === 'App\Models\StandaloneRedis') {$internalPort = 6379;- } else if ($database->getMorphClass()=== 'App\Models\StandalonePostgresql') {+ } else if ($database->getMorphClass() === 'App\Models\StandalonePostgresql') {$internalPort = 5432;+ } else if ($database->getMorphClass() === 'App\Models\StandaloneMongodb') {+ $internalPort = 27017;}$containerName = "{$database->uuid}-proxy";$configuration_dir = database_proxy_dir($database->uuid);diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.phpnew file mode 100644index 0000000000..39d1b99b3c--- /dev/null+++ b/app/Actions/Database/StartMongodb.php@@ -0,0 +1,165 @@+<?php++namespace App\Actions\Database;++use App\Models\Server;+use App\Models\StandaloneMongodb;+use Illuminate\Support\Str;+use Symfony\Component\Yaml\Yaml;+use Lorisleiva\Actions\Concerns\AsAction;++class StartMongodb+{+ use AsAction;++ public StandaloneMongodb $database;+ public array $commands = [];+ public string $configuration_dir;++ public function handle(Server $server, StandaloneMongodb $database)+ {+ $this->database = $database;++ $startCommand = "mongod";++ $container_name = $this->database->uuid;+ $this->configuration_dir = database_configuration_dir() . '/' . $container_name;++ $this->commands = [+ "echo '####### Starting {$database->name}.'",+ "mkdir -p $this->configuration_dir",+ ];++ $persistent_storages = $this->generate_local_persistent_volumes();+ $volume_names = $this->generate_local_persistent_volumes_only_volume_names();+ $environment_variables = $this->generate_environment_variables();+ $this->add_custom_mongo_conf();++ $docker_compose = [+ 'version' => '3.8',+ 'services' => [+ $container_name => [+ 'image' => $this->database->image,+ 'command' => $startCommand,+ 'container_name' => $container_name,+ 'environment' => $environment_variables,+ 'restart' => RESTART_MODE,+ 'networks' => [+ $this->database->destination->network,+ ],+ 'labels' => [+ 'coolify.managed' => 'true',+ ],+ 'healthcheck' => [+ 'test' => [+ 'CMD-SHELL',+ 'mongo --eval "printjson(db.serverStatus())" | grep uptime | grep -v grep'+ ],+ 'interval' => '5s',+ 'timeout' => '5s',+ 'retries' => 10,+ 'start_period' => '5s'+ ],+ 'mem_limit' => $this->database->limits_memory,+ 'memswap_limit' => $this->database->limits_memory_swap,+ 'mem_swappiness' => $this->database->limits_memory_swappiness,+ 'mem_reservation' => $this->database->limits_memory_reservation,+ 'cpus' => $this->database->limits_cpus,+ 'cpuset' => $this->database->limits_cpuset,+ 'cpu_shares' => $this->database->limits_cpu_shares,+ ]+ ],+ 'networks' => [+ $this->database->destination->network => [+ 'external' => true,+ 'name' => $this->database->destination->network,+ 'attachable' => true,+ ]+ ]+ ];+ if (count($this->database->ports_mappings_array) > 0) {+ $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array;+ }+ if (count($persistent_storages) > 0) {+ $docker_compose['services'][$container_name]['volumes'] = $persistent_storages;+ }+ if (count($volume_names) > 0) {+ $docker_compose['volumes'] = $volume_names;+ }+ if (!is_null($this->database->mongo_conf)) {+ $docker_compose['services'][$container_name]['volumes'][] = [+ 'type' => 'bind',+ '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 = 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";+ $readme = generate_readme_file($this->database->name, now());+ $this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md";+ $this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";+ $this->commands[] = "echo '####### {$database->name} started.'";+ return remote_process($this->commands, $server);+ }++ private function generate_local_persistent_volumes()+ {+ $local_persistent_volumes = [];+ foreach ($this->database->persistentStorages as $persistentStorage) {+ $volume_name = $persistentStorage->host_path ?? $persistentStorage->name;+ $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path;+ }+ return $local_persistent_volumes;+ }++ private function generate_local_persistent_volumes_only_volume_names()+ {+ $local_persistent_volumes_names = [];+ foreach ($this->database->persistentStorages as $persistentStorage) {+ if ($persistentStorage->host_path) {+ continue;+ }+ $name = $persistentStorage->name;+ $local_persistent_volumes_names[$name] = [+ 'name' => $name,+ 'external' => false,+ ];+ }+ return $local_persistent_volumes_names;+ }++ private function generate_environment_variables()+ {+ $environment_variables = collect();+ foreach ($this->database->runtime_environment_variables as $env) {+ $environment_variables->push("$env->key=$env->value");+ }++ if ($environment_variables->filter(fn ($env) => Str::of($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::of($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::of($env)->contains('MONGO_INITDB_DATABASE'))->isEmpty()) {+ $environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}");+ }+ return $environment_variables->all();+ }+ private function add_custom_mongo_conf()+ {+ if (is_null($this->database->mongo_conf)) {+ return;+ }+ $filename = 'mongod.conf';+ $content = $this->database->mongo_conf;+ $content_base64 = base64_encode($content);+ $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/{$filename}";++ }+}diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.phpindex ee1913f066..7e3f5f4c2f 100644--- a/app/Actions/Database/StopDatabase.php+++ b/app/Actions/Database/StopDatabase.php@@ -2,16 +2,16 @@namespace App\Actions\Database;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;-use App\Notifications\Application\StatusChanged;use Lorisleiva\Actions\Concerns\AsAction;class StopDatabase{use AsAction;- public function handle(StandaloneRedis|StandalonePostgresql $database)+ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb $database){$server = $database->destination->server;instant_remote_process(diff --git a/app/Actions/Database/StopDatabaseProxy.php b/app/Actions/Database/StopDatabaseProxy.phpindex ba836ec3a0..840e8ed561 100644--- a/app/Actions/Database/StopDatabaseProxy.php+++ b/app/Actions/Database/StopDatabaseProxy.php@@ -2,6 +2,7 @@namespace App\Actions\Database;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;use Lorisleiva\Actions\Concerns\AsAction;@@ -10,7 +11,7 @@ class StopDatabaseProxy{use AsAction;- public function handle(StandaloneRedis|StandalonePostgresql $database)+ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb $database){instant_remote_process(["docker rm -f {$database->uuid}-proxy"], $database->destination->server);$database->is_public = false;diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.phpindex 7e67a588c7..1d1a5b14ed 100644--- a/app/Http/Controllers/ProjectController.php+++ b/app/Http/Controllers/ProjectController.php@@ -63,6 +63,8 @@ class ProjectController extends Controller$database = create_standalone_postgresql($environment->id, $destination_uuid);} else if ($type->value() === 'redis') {$database = create_standalone_redis($environment->id, $destination_uuid);+ } else if ($type->value() === 'mongodb') {+ $database = create_standalone_mongodb($environment->id, $destination_uuid);}return redirect()->route('project.database.configuration', ['project_uuid' => $project->uuid,diff --git a/app/Http/Livewire/Project/Database/Heading.php b/app/Http/Livewire/Project/Database/Heading.phpindex fc867ce79e..1a199ecb73 100644--- a/app/Http/Livewire/Project/Database/Heading.php+++ b/app/Http/Livewire/Project/Database/Heading.php@@ -2,6 +2,7 @@namespace App\Http\Livewire\Project\Database;+use App\Actions\Database\StartMongodb;use App\Actions\Database\StartPostgresql;use App\Actions\Database\StartRedis;use App\Actions\Database\StopDatabase;@@ -53,5 +54,9 @@ class Heading extends Component$activity = StartRedis::run($this->database->destination->server, $this->database);$this->emit('newMonitorActivity', $activity->id);}+ if ($this->database->type() === 'standalone-mongodb') {+ $activity = StartMongodb::run($this->database->destination->server, $this->database);+ $this->emit('newMonitorActivity', $activity->id);+ }}}diff --git a/app/Http/Livewire/Project/Database/Mongodb/General.php b/app/Http/Livewire/Project/Database/Mongodb/General.phpnew file mode 100644index 0000000000..c6665f94db--- /dev/null+++ b/app/Http/Livewire/Project/Database/Mongodb/General.php@@ -0,0 +1,98 @@+<?php++namespace App\Http\Livewire\Project\Database\Mongodb;++use App\Actions\Database\StartDatabaseProxy;+use App\Actions\Database\StopDatabaseProxy;+use App\Models\StandaloneMongodb;+use Exception;+use Livewire\Component;++class General extends Component+{+ protected $listeners = ['refresh'];++ public StandaloneMongodb $database;+ public string $db_url;++ protected $rules = [+ 'database.name' => 'required',+ 'database.description' => 'nullable',+ 'database.mongo_conf' => 'nullable',+ 'database.mongo_initdb_root_username' => 'required',+ 'database.mongo_initdb_root_password' => 'required',+ 'database.mongo_initdb_database' => 'required',+ 'database.image' => 'required',+ 'database.ports_mappings' => 'nullable',+ 'database.is_public' => 'nullable|boolean',+ 'database.public_port' => 'nullable|integer',+ ];+ protected $validationAttributes = [+ 'database.name' => 'Name',+ 'database.description' => 'Description',+ 'database.mongo_conf' => 'Mongo Configuration',+ 'database.mongo_initdb_root_username' => 'Root Username',+ 'database.mongo_initdb_root_password' => 'Root Password',+ 'database.mongo_initdb_database' => 'Database',+ 'database.image' => 'Image',+ 'database.ports_mappings' => 'Port Mapping',+ 'database.is_public' => 'Is Public',+ 'database.public_port' => 'Public Port',+ ];+ public function submit() {+ try {+ $this->validate();+ if ($this->database->mongo_conf === "") {+ $this->database->mongo_conf = null;+ }+ $this->database->save();+ $this->emit('success', 'Database updated successfully.');+ } catch (Exception $e) {+ return handleError($e, $this);+ }+ }+ public function instantSave()+ {+ try {+ if ($this->database->is_public && !$this->database->public_port) {+ $this->emit('error', 'Public port is required.');+ $this->database->is_public = false;+ return;+ }+ if ($this->database->is_public) {+ $this->emit('success', 'Starting TCP proxy...');+ StartDatabaseProxy::run($this->database);+ $this->emit('success', 'Database is now publicly accessible.');+ } else {+ StopDatabaseProxy::run($this->database);+ $this->emit('success', 'Database is no longer publicly accessible.');+ }+ $this->getDbUrl();+ $this->database->save();+ } catch(\Throwable $e) {+ $this->database->is_public = !$this->database->is_public;+ return handleError($e, $this);+ }+ }+ public function refresh(): void+ {+ $this->database->refresh();+ }++ public function mount()+ {+ $this->getDbUrl();+ }+ public function getDbUrl() {++ if ($this->database->is_public) {+ $this->db_url = "mongodb://{$this->database->mongo_initdb_root_username}:{$this->database->mongo_initdb_root_password}@{$this->database->destination->server->getIp}:{$this->database->public_port}/?directConnection=true";+ } else {+ $this->db_url = "mongodb://{$this->database->mongo_initdb_root_username}:{$this->database->mongo_initdb_root_password}@{$this->database->uuid}:27017/?directConnection=true";+ }+ }+ public function render()+ {+ return view('livewire.project.database.mongodb.general');+ }+}diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.phpindex ce7c5ae40c..f453b4bf3c 100644--- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php+++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php@@ -78,6 +78,9 @@ class All extends Componentcase 'standalone-redis':$environment->standalone_redis_id = $this->resource->id;break;+ case 'standalone-mongodb':+ $environment->standalone_mongodb_id = $this->resource->id;+ break;case 'service':$environment->service_id = $this->resource->id;break;diff --git a/app/Http/Livewire/Project/Shared/GetLogs.php b/app/Http/Livewire/Project/Shared/GetLogs.phpindex cd0ee98fd1..90983785d7 100644--- a/app/Http/Livewire/Project/Shared/GetLogs.php+++ b/app/Http/Livewire/Project/Shared/GetLogs.php@@ -13,6 +13,7 @@ class GetLogs extends Componentpublic Server $server;public ?string $container = null;public ?bool $streamLogs = false;+ public ?bool $showTimeStamps = true;public int $numberOfLines = 100;public function doSomethingWithThisChunkOfOutput($output){@@ -24,7 +25,11 @@ class GetLogs extends Componentpublic function getLogs($refresh = false){if ($this->container) {- $sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} -t {$this->container}");+ if ($this->showTimeStamps) {+ $sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} -t {$this->container}");+ } else {+ $sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} {$this->container}");+ }if ($refresh) {$this->outputs = '';}diff --git a/app/Http/Livewire/Project/Shared/Logs.php b/app/Http/Livewire/Project/Shared/Logs.phpindex 15a4e510c7..80cdf82c4b 100644--- a/app/Http/Livewire/Project/Shared/Logs.php+++ b/app/Http/Livewire/Project/Shared/Logs.php@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Project\Shared;use App\Models\Application;use App\Models\Server;use App\Models\Service;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;use Livewire\Component;@@ -12,7 +13,7 @@ use Livewire\Component;class Logs extends Component{public ?string $type = null;- public Application|StandalonePostgresql|Service|StandaloneRedis $resource;+ public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb $resource;public Server $server;public ?string $container = null;public $parameters;@@ -38,9 +39,13 @@ class Logs extends Componentif (is_null($resource)) {$resource = StandaloneRedis::where('uuid', $this->parameters['database_uuid'])->first();if (is_null($resource)) {- abort(404);+ $resource = StandaloneMongodb::where('uuid', $this->parameters['database_uuid'])->first();+ if (is_null($resource)) {+ abort(404);+ }}}+$this->resource = $resource;$this->status = $this->resource->status;$this->server = $this->resource->destination->server;diff --git a/app/Jobs/StopResourceJob.php b/app/Jobs/StopResourceJob.phpindex 0bfc1f2faf..721f7f6989 100644--- a/app/Jobs/StopResourceJob.php+++ b/app/Jobs/StopResourceJob.php@@ -7,6 +7,7 @@ use App\Actions\Database\StopDatabase;use App\Actions\Service\StopService;use App\Models\Application;use App\Models\Service;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;use Illuminate\Bus\Queueable;@@ -20,7 +21,7 @@ class StopResourceJob implements ShouldQueue, ShouldBeEncrypted{use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;- public function __construct(public Application|Service|StandalonePostgresql|StandaloneRedis $resource)+ public function __construct(public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb $resource){}@@ -41,6 +42,9 @@ class StopResourceJob implements ShouldQueue, ShouldBeEncryptedcase 'standalone-redis':StopDatabase::run($this->resource);break;+ case 'standalone-mongodb':+ StopDatabase::run($this->resource);+ break;case 'service':StopService::run($this->resource);break;diff --git a/app/Models/Environment.php b/app/Models/Environment.phpindex f66bf48f28..8f67ed004a 100644--- a/app/Models/Environment.php+++ b/app/Models/Environment.php@@ -14,7 +14,11 @@ class Environment extends Modelpublic function can_delete_environment(){- return $this->applications()->count() == 0 && $this->redis()->count() == 0 && $this->postgresqls()->count() == 0 && $this->services()->count() == 0;+ return $this->applications()->count() == 0 &&+ $this->redis()->count() == 0 &&+ $this->postgresqls()->count() == 0 &&+ $this->mongodbs()->count() == 0 &&+ $this->services()->count() == 0;}public function applications()@@ -30,12 +34,17 @@ class Environment extends Model{return $this->hasMany(StandaloneRedis::class);}+ public function mongodbs()+ {+ return $this->hasMany(StandaloneMongodb::class);+ }public function databases(){$postgresqls = $this->postgresqls;$redis = $this->redis;- return $postgresqls->concat($redis);+ $mongodbs = $this->mongodbs;+ return $postgresqls->concat($redis)->concat($mongodbs);}public function project()diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 07f975c48c..d5d9709a0e 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -124,7 +124,8 @@ class Server extends BaseModelreturn $this->destinations()->map(function ($standaloneDocker) {$postgresqls = $standaloneDocker->postgresqls;$redis = $standaloneDocker->redis;- return $postgresqls->concat($redis);+ $mongodbs = $standaloneDocker->mongodbs;+ return $postgresqls->concat($redis)->concat($mongodbs);})->flatten();}public function applications()diff --git a/app/Models/StandaloneDocker.php b/app/Models/StandaloneDocker.phpindex a594b854a9..9e70b7514f 100644--- a/app/Models/StandaloneDocker.php+++ b/app/Models/StandaloneDocker.php@@ -15,10 +15,15 @@ class StandaloneDocker extends BaseModel{return $this->morphMany(StandalonePostgresql::class, 'destination');}+public function redis(){return $this->morphMany(StandaloneRedis::class, 'destination');}+ public function mongodbs()+ {+ return $this->morphMany(StandaloneMongodb::class, 'destination');+ }public function server(){diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.phpnew file mode 100644index 0000000000..f8697e2ed4--- /dev/null+++ b/app/Models/StandaloneMongodb.php@@ -0,0 +1,93 @@+<?php++namespace App\Models;++use Illuminate\Database\Eloquent\Casts\Attribute;+use Illuminate\Database\Eloquent\Factories\HasFactory;+use Illuminate\Database\Eloquent\Relations\HasMany;++class StandaloneMongodb extends BaseModel+{+ use HasFactory;+ protected $guarded = [];++ protected static function booted()+ {+ static::created(function ($database) {+ LocalPersistentVolume::create([+ 'name' => 'mongodb-data-' . $database->uuid,+ 'mount_path' => '/data',+ 'host_path' => null,+ 'resource_id' => $database->id,+ 'resource_type' => $database->getMorphClass(),+ 'is_readonly' => true+ ]);+ });+ static::deleting(function ($database) {+ $database->scheduledBackups()->delete();+ $storages = $database->persistentStorages()->get();+ foreach ($storages as $storage) {+ instant_remote_process(["docker volume rm -f $storage->name"], $database->destination->server, false);+ }+ $database->persistentStorages()->delete();+ $database->environment_variables()->delete();+ });+ }++ public function portsMappings(): Attribute+ {+ return Attribute::make(+ set: fn ($value) => $value === "" ? null : $value,+ );+ }++ public function portsMappingsArray(): Attribute+ {+ return Attribute::make(+ get: fn () => is_null($this->ports_mappings)+ ? []+ : explode(',', $this->ports_mappings),++ );+ }++ public function type(): string+ {+ return 'standalone-mongodb';+ }++ public function environment()+ {+ return $this->belongsTo(Environment::class);+ }++ public function fileStorages()+ {+ return $this->morphMany(LocalFileVolume::class, 'resource');+ }++ public function destination()+ {+ return $this->morphTo();+ }++ public function environment_variables(): HasMany+ {+ return $this->hasMany(EnvironmentVariable::class);+ }++ public function runtime_environment_variables(): HasMany+ {+ return $this->hasMany(EnvironmentVariable::class);+ }++ public function persistentStorages()+ {+ return $this->morphMany(LocalPersistentVolume::class, 'resource');+ }++ public function scheduledBackups()+ {+ return $this->morphMany(ScheduledDatabaseBackup::class, 'database');+ }+}diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.phpindex 6517c2ef7c..6cd3f00642 100644--- a/app/Models/StandaloneRedis.php+++ b/app/Models/StandaloneRedis.php@@ -41,8 +41,6 @@ class StandaloneRedis extends BaseModel);}- // Normal Deployments-public function portsMappingsArray(): Attribute{return Attribute::make(diff --git a/bootstrap/helpers/constants.php b/bootstrap/helpers/constants.phpindex f915ea0412..586ba531d5 100644--- a/bootstrap/helpers/constants.php+++ b/bootstrap/helpers/constants.php@@ -1,6 +1,6 @@<?php-const DATABASE_TYPES = ['postgresql','redis'];+const DATABASE_TYPES = ['postgresql','redis', 'mongodb'];const VALID_CRON_STRINGS = ['every_minute' => '* * * * *','hourly' => '0 * * * *',diff --git a/bootstrap/helpers/databases.php b/bootstrap/helpers/databases.phpindex 3c4f0dfd94..0c5c8898ea 100644--- a/bootstrap/helpers/databases.php+++ b/bootstrap/helpers/databases.php@@ -2,6 +2,7 @@use App\Models\Server;use App\Models\StandaloneDocker;+use App\Models\StandaloneMongodb;use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;use Visus\Cuid2\Cuid2;@@ -43,6 +44,21 @@ function create_standalone_redis($environment_id, $destination_uuid): Standalone]);}+function create_standalone_mongodb($environment_id, $destination_uuid): StandaloneMongodb+{+ $destination = StandaloneDocker::where('uuid', $destination_uuid)->first();+ if (!$destination) {+ throw new Exception('Destination not found');+ }+ return StandaloneMongodb::create([+ 'name' => generate_database_name('mongodb'),+ 'mongo_initdb_root_password' => \Illuminate\Support\Str::password(symbols: false),+ 'environment_id' => $environment_id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ]);+}+/*** Delete file locally on the filesystem.* @param string $filenamediff --git a/database/factories/StandaloneMongoDBFactory.php b/database/factories/StandaloneMongoDBFactory.phpnew file mode 100644index 0000000000..8ec395e49a--- /dev/null+++ b/database/factories/StandaloneMongoDBFactory.php@@ -0,0 +1,23 @@+<?php++namespace Database\Factories;++use Illuminate\Database\Eloquent\Factories\Factory;++/**+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\StandaloneMongodb>+ */+class StandaloneMongodbFactory extends Factory+{+ /**+ * Define the model's default state.+ *+ * @return array<string, mixed>+ */+ public function definition(): array+ {+ return [+ //+ ];+ }+}diff --git a/database/migrations/2023_10_19_101331_create_standalone_mongodbs_table.php b/database/migrations/2023_10_19_101331_create_standalone_mongodbs_table.phpnew file mode 100644index 0000000000..30f5c24af1--- /dev/null+++ b/database/migrations/2023_10_19_101331_create_standalone_mongodbs_table.php@@ -0,0 +1,56 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::create('standalone_mongodbs', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('name');+ $table->string('description')->nullable();++ $table->text('mongo_conf')->nullable();+ $table->text('mongo_initdb_root_username')->default('root');+ $table->text('mongo_initdb_root_password');+ $table->text('mongo_initdb_database')->default('default');++ $table->string('status')->default('exited');++ $table->string('image')->default('mongo:7');++ $table->boolean('is_public')->default(false);+ $table->integer('public_port')->nullable();+ $table->text('ports_mappings')->nullable();++ $table->string('limits_memory')->default("0");+ $table->string('limits_memory_swap')->default("0");+ $table->integer('limits_memory_swappiness')->default(60);+ $table->string('limits_memory_reservation')->default("0");++ $table->string('limits_cpus')->default("0");+ $table->string('limits_cpuset')->nullable()->default("0");+ $table->integer('limits_cpu_shares')->default(1024);++ $table->timestamp('started_at')->nullable();+ $table->morphs('destination');+ $table->foreignId('environment_id')->nullable();+ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('standalone_mongodbs');+ }+};diff --git a/database/migrations/2023_10_19_101332_add_standalone_mongodb_to_environment_variables_table.php b/database/migrations/2023_10_19_101332_add_standalone_mongodb_to_environment_variables_table.phpnew file mode 100644index 0000000000..b67c226371--- /dev/null+++ b/database/migrations/2023_10_19_101332_add_standalone_mongodb_to_environment_variables_table.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('environment_variables', function (Blueprint $table) {+ $table->foreignId('standalone_mongodb_id')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('environment_variables', function (Blueprint $table) {+ $table->dropColumn('standalone_mongodb_id');+ });+ }+};diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex 0bf3e8828a..9b7af1c025 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -34,7 +34,7 @@ services:POSTGRES_DB: "${DB_DATABASE:-coolify}"POSTGRES_HOST_AUTH_METHOD: "trust"volumes:- - ./_data/coolify/_volumes/database/:/var/lib/postgresql/data+ - /data/coolify/_volumes/database/:/var/lib/postgresql/data# - coolify-pg-data-dev:/var/lib/postgresql/dataredis:ports:@@ -42,7 +42,7 @@ services:env_file:- .envvolumes:- - ./_data/coolify/_volumes/redis/:/data+ - /data/coolify/_volumes/redis/:/data# - coolify-redis-data-dev:/datavite:image: node:19@@ -58,7 +58,7 @@ services:volumes:- /:/host- /var/run/docker.sock:/var/run/docker.sock- - ./_data/coolify/:/data/coolify+ - /data/coolify/:/data/coolify# - coolify-data-dev:/data/coolifymailpit:image: "axllent/mailpit:latest"@@ -79,7 +79,7 @@ services:MINIO_ACCESS_KEY: "${MINIO_ACCESS_KEY:-minioadmin}"MINIO_SECRET_KEY: "${MINIO_SECRET_KEY:-minioadmin}"volumes:- - ./_data/coolify/_volumes/minio/:/data+ - /data/coolify/_volumes/minio/:/data# - coolify-minio-data-dev:/datanetworks:- coolifydiff --git a/resources/views/livewire/project/database/mongodb/general.blade.php b/resources/views/livewire/project/database/mongodb/general.blade.phpnew file mode 100644index 0000000000..51cb31d23b--- /dev/null+++ b/resources/views/livewire/project/database/mongodb/general.blade.php@@ -0,0 +1,52 @@+<div>+ <form wire:submit.prevent="submit" class="flex flex-col gap-2">+ <div class="flex items-center gap-2">+ <h2>General</h2>+ <x-forms.button type="submit">+ Save+ </x-forms.button>+ </div>+ <div class="flex gap-2">+ <x-forms.input label="Name" id="database.name" />+ <x-forms.input label="Description" id="database.description" />+ <x-forms.input label="Image" id="database.image" required+ helper="For all available images, check here:<br><br><a target='_blank' href='https://hub.docker.com/_/mongo'>https://hub.docker.com/_/mongo</a>" />+ </div>+ @if ($database->started_at)+ <div class="flex gap-2">+ <x-forms.input label="Initial Username" id="database.mongo_initdb_root_username"+ placeholder="If empty: postgres" readonly helper="You can only change this in the database." />+ <x-forms.input label="Initial Password" id="database.mongo_initdb_root_password" type="password" required+ readonly helper="You can only change this in the database." />+ <x-forms.input label="Initial Database" id="database.mongo_initdb_database"+ placeholder="If empty, it will be the same as Username." readonly+ helper="You can only change this in the database." />+ </div>+ @else+ <div class="pt-8 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.+ </div>+ <div class="flex gap-2 pb-8">+ <x-forms.input required label="Username" id="database.mongo_initdb_root_username"+ placeholder="If empty: postgres" />+ <x-forms.input label="Password" id="database.mongo_initdb_root_password" type="password" required />+ <x-forms.input required label="Database" id="database.mongo_initdb_database"+ placeholder="If empty, it will be the same as Username." />+ </div>+ @endif+ <div class="flex flex-col gap-2">+ <h3 class="py-2">Network</h3>+ <div class="flex items-end gap-2">+ <x-forms.input placeholder="3000:5432" id="database.ports_mappings" label="Ports Mappings"+ helper="A comma separated list of ports you would like to map to the host system.<br><span class='inline-block font-bold text-warning'>Example</span>3000:5432,3002:5433" />+ <x-forms.input placeholder="5432" disabled="{{ $database->is_public }}" id="database.public_port"+ label="Public Port" />+ <x-forms.checkbox instantSave id="database.is_public" label="Accessible over the internet" />+ </div>+ <x-forms.input label="Mongo URL"+ helper="If you change the user/password/port, this could be different. This is with the default values."+ type="password" readonly wire:model="db_url" />+ </div>+ <x-forms.textarea label="Custom MongoDB Configuration" rows="10" id="database.mongo_conf" />+ </form>+</div>diff --git a/resources/views/livewire/project/database/postgresql/general.blade.php b/resources/views/livewire/project/database/postgresql/general.blade.phpindex 61a95f9f80..dfe64b993e 100644--- a/resources/views/livewire/project/database/postgresql/general.blade.php+++ b/resources/views/livewire/project/database/postgresql/general.blade.php@@ -62,7 +62,7 @@label="Public Port" /><x-forms.checkbox instantSave id="database.is_public" label="Accessible over the internet" /></div>- <x-forms.input label="Postgres URL" type="password" readonly wire:model="db_url" />+ <x-forms.input label="Postgres URL" helper="If you change the user/password/port, this could be different. This is with the default values." type="password" readonly wire:model="db_url" /></div></form><div class="pb-16">diff --git a/resources/views/livewire/project/database/redis/general.blade.php b/resources/views/livewire/project/database/redis/general.blade.phpindex 17f440fbb2..1789d0c15e 100644--- a/resources/views/livewire/project/database/redis/general.blade.php+++ b/resources/views/livewire/project/database/redis/general.blade.php@@ -21,7 +21,7 @@label="Public Port" /><x-forms.checkbox instantSave id="database.is_public" label="Accessible over the internet" /></div>- <x-forms.input label="Redis URL" type="password" readonly wire:model="db_url" />+ <x-forms.input label="Redis URL" helper="If you change the user/password/port, this could be different. This is with the default values." type="password" readonly wire:model="db_url" /></div><x-forms.textarea helper="<a target='_blank' class='text-white underline' href='https://raw.githubusercontent.com/redis/redis/7.2/redis.conf'>Redis Default Configuration</a>" label="Custom Redis Configuration" rows="10" id="database.redis_conf" /></form>diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.phpindex 8d6636fb10..9659ff995b 100644--- a/resources/views/livewire/project/new/select.blade.php+++ b/resources/views/livewire/project/new/select.blade.php@@ -103,6 +103,15 @@The open source, in-memory data store for cache, streaming engine, and message broker.</div></div>+ </div> <div class="box group" wire:click="setType('mongodb')">+ <div class="flex flex-col mx-6">+ <div class="font-bold text-white group-hover:text-white">+ New MongoDB+ </div>+ <div class="text-xs group-hover:text-white">+ MongoDB is a source-available cross-platform document-oriented database program.+ </div>+ </div></div>{{-- <div class="box group" wire:click="setType('existing-postgresql')"><div class="flex flex-col mx-6">diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.phpindex 31f6e6bc36..eed8f143b2 100644--- a/resources/views/livewire/project/shared/get-logs.blade.php+++ b/resources/views/livewire/project/shared/get-logs.blade.php@@ -5,13 +5,15 @@<span wire:poll.2000ms='getLogs(true)' class="loading loading-xs text-warning loading-spinner"></span>@endif</div>+ <div class="flex gap-2">+ <x-forms.checkbox instantSave label="Stream Logs" id="streamLogs"></x-forms.checkbox>+ <x-forms.checkbox instantSave label="Include Timestamps" id="showTimeStamps"></x-forms.checkbox>+ </div><form wire:submit.prevent='getLogs(true)' class="flex items-end gap-2"><x-forms.input label="Only Show Number of Lines" placeholder="1000" required id="numberOfLines"></x-forms.input><x-forms.button type="submit">Refresh</x-forms.button></form>- <div class="w-32">- <x-forms.checkbox instantSave label="Stream Logs" id="streamLogs"></x-forms.checkbox>- </div>+<div class="container w-full pt-4 mx-auto"><divclass="scrollbar flex flex-col-reverse w-full overflow-y-auto border border-solid rounded border-coolgray-300 max-h-[32rem] p-4 pt-6 text-xs text-white">diff --git a/resources/views/project/database/configuration.blade.php b/resources/views/project/database/configuration.blade.phpindex bed2f96efb..8fbfa8f0ca 100644--- a/resources/views/project/database/configuration.blade.php+++ b/resources/views/project/database/configuration.blade.php@@ -40,6 +40,9 @@@if ($database->type() === 'standalone-redis')<livewire:project.database.redis.general :database="$database" />@endif+ @if ($database->type() === 'standalone-mongodb')+ <livewire:project.database.mongodb.general :database="$database" />+ @endif</div><div x-cloak x-show="activeTab === 'environment-variables'"><livewire:project.shared.environment-variable.all :resource="$database" />