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.

init: redis

Andras Bacsaibeae0b545fbd
diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php
new file mode 100644
index 0000000000..5752408694
--- /dev/null
+++ b/app/Actions/Database/StartRedis.php
@@ -0,0 +1,144 @@
+<?php
+
+namespace App\Actions\Database;
+
+use App\Models\Server;
+use App\Models\StandaloneRedis;
+use Illuminate\Support\Str;
+use Symfony\Component\Yaml\Yaml;
+use Lorisleiva\Actions\Concerns\AsAction;
+
+class StartRedis
+{
+ use AsAction;
+
+ public StandaloneRedis $database;
+ public array $commands = [];
+ public string $configuration_dir;
+
+
+ public function handle(Server $server, StandaloneRedis $database)
+ {
+ $this->database = $database;
+ $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();
+ $docker_compose = [
+ 'version' => '3.8',
+ 'services' => [
+ $container_name => [
+ 'image' => $this->database->image,
+ 'command' => "redis-server --requirepass {$this->database->redis_password} --appendonly yes",
+ 'container_name' => $container_name,
+ 'environment' => $environment_variables,
+ 'restart' => RESTART_MODE,
+ 'networks' => [
+ $this->database->destination->network,
+ ],
+ 'healthcheck' => [
+ 'test' => [
+ 'CMD-SHELL',
+ 'redis-cli',
+ 'ping'
+ ],
+ '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 (count($this->init_scripts) > 0) {
+ // foreach ($this->init_scripts as $init_script) {
+ // $docker_compose['services'][$container_name]['volumes'][] = [
+ // 'type' => 'bind',
+ // 'source' => $init_script,
+ // 'target' => '/docker-entrypoint-initdb.d/' . basename($init_script),
+ // '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";
+ $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();
+ ray('Generate Environment Variables')->green();
+ ray($this->database->runtime_environment_variables)->green();
+ 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('REDIS_PASSWORD'))->isEmpty()) {
+ $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}");
+ }
+
+ return $environment_variables->all();
+ }
+}
diff --git a/app/Http/Controllers/DatabaseController.php b/app/Http/Controllers/DatabaseController.php
index 958d6d5abe..e8f85110b0 100644
--- a/app/Http/Controllers/DatabaseController.php
+++ b/app/Http/Controllers/DatabaseController.php
@@ -19,7 +19,7 @@ class DatabaseController extends Controller
if (!$environment) {
return redirect()->route('dashboard');
}
- $database = $environment->databases->where('uuid', request()->route('database_uuid'))->first();
+ $database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
return redirect()->route('dashboard');
}
@@ -37,7 +37,7 @@ class DatabaseController extends Controller
if (!$environment) {
return redirect()->route('dashboard');
}
- $database = $environment->databases->where('uuid', request()->route('database_uuid'))->first();
+ $database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
return redirect()->route('dashboard');
}
@@ -64,7 +64,7 @@ class DatabaseController extends Controller
if (!$environment) {
return redirect()->route('dashboard');
}
- $database = $environment->databases->where('uuid', request()->route('database_uuid'))->first();
+ $database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
return redirect()->route('dashboard');
}
diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php
index 7b8cfbfd1c..a4db0b1f85 100644
--- a/app/Http/Controllers/ProjectController.php
+++ b/app/Http/Controllers/ProjectController.php
@@ -59,11 +59,16 @@ class ProjectController extends Controller
return redirect()->route('dashboard');
}
if (in_array($type, DATABASE_TYPES)) {
- $standalone_postgresql = create_standalone_postgresql($environment->id, $destination_uuid);
+ if ($type->value() === "postgresql") {
+ $database = create_standalone_postgresql($environment->id, $destination_uuid);
+ } else if ($type->value() === 'redis') {
+ $database = create_standalone_redis($environment->id, $destination_uuid);
+ }
+ ray($database);
return redirect()->route('project.database.configuration', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
- 'database_uuid' => $standalone_postgresql->uuid,
+ 'database_uuid' => $database->uuid,
]);
}
if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) {
diff --git a/app/Http/Livewire/Project/Database/Heading.php b/app/Http/Livewire/Project/Database/Heading.php
index 3389ac80a8..2c739f0878 100644
--- a/app/Http/Livewire/Project/Database/Heading.php
+++ b/app/Http/Livewire/Project/Database/Heading.php
@@ -3,6 +3,7 @@
namespace App\Http\Livewire\Project\Database;
use App\Actions\Database\StartPostgresql;
+use App\Actions\Database\StartRedis;
use App\Jobs\ContainerStatusJob;
use Livewire\Component;
@@ -26,6 +27,7 @@ class Heading extends Component
{
dispatch_sync(new ContainerStatusJob($this->database->destination->server));
$this->database->refresh();
+ $this->emit('refresh');
}
public function mount()
@@ -40,7 +42,7 @@ class Heading extends Component
$this->database->destination->server
);
if ($this->database->is_public) {
- stopPostgresProxy($this->database);
+ stopDatabaseProxy($this->database);
$this->database->is_public = false;
}
$this->database->status = 'exited';
@@ -55,5 +57,9 @@ class Heading extends Component
$activity = resolve(StartPostgresql::class)($this->database->destination->server, $this->database);
$this->emit('newMonitorActivity', $activity->id);
}
+ if ($this->database->type() === 'standalone-redis') {
+ $activity = StartRedis::run($this->database->destination->server, $this->database);
+ $this->emit('newMonitorActivity', $activity->id);
+ }
}
}
diff --git a/app/Http/Livewire/Project/Database/Postgresql/General.php b/app/Http/Livewire/Project/Database/Postgresql/General.php
index 5a03908e1c..bbd1de0ff1 100644
--- a/app/Http/Livewire/Project/Database/Postgresql/General.php
+++ b/app/Http/Livewire/Project/Database/Postgresql/General.php
@@ -67,10 +67,10 @@ class General extends Component
}
if ($this->database->is_public) {
$this->emit('success', 'Starting TCP proxy...');
- startPostgresProxy($this->database);
+ startDatabaseProxy($this->database);
$this->emit('success', 'Database is now publicly accessible.');
} else {
- stopPostgresProxy($this->database);
+ stopDatabaseProxy($this->database);
$this->emit('success', 'Database is no longer publicly accessible.');
}
$this->getDbUrl();
diff --git a/app/Http/Livewire/Project/Database/Redis/General.php b/app/Http/Livewire/Project/Database/Redis/General.php
new file mode 100644
index 0000000000..446d720c06
--- /dev/null
+++ b/app/Http/Livewire/Project/Database/Redis/General.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace App\Http\Livewire\Project\Database\Redis;
+
+use App\Models\StandaloneRedis;
+use Exception;
+use Livewire\Component;
+
+class General extends Component
+{
+ protected $listeners = ['refresh'];
+
+ public StandaloneRedis $database;
+ public string $db_url;
+
+ protected $rules = [
+ 'database.name' => 'required',
+ 'database.description' => 'nullable',
+ 'database.redis_password' => '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.redis_password' => 'Postgres User',
+ 'database.image' => 'Image',
+ 'database.ports_mappings' => 'Port Mapping',
+ 'database.is_public' => 'Is Public',
+ 'database.public_port' => 'Public Port',
+ ];
+ public function submit() {
+ try {
+ $this->validate();
+ $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($this->database);
+ $this->emit('success', 'Database is now publicly accessible.');
+ } else {
+ stopDatabaseProxy($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 = "redis://{$this->database->redis_password}@{$this->database->destination->server->getIp}:{$this->database->public_port}/0";
+ } else {
+ $this->db_url = "redis://{$this->database->redis_password}@{$this->database->uuid}:5432/0";
+ }
+ }
+ public function render()
+ {
+ return view('livewire.project.database.redis.general');
+ }
+}
diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php
index a95c949772..ce7c5ae40c 100644
--- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php
+++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php
@@ -75,6 +75,9 @@ class All extends Component
case 'standalone-postgresql':
$environment->standalone_postgresql_id = $this->resource->id;
break;
+ case 'standalone-redis':
+ $environment->standalone_redis_id = $this->resource->id;
+ break;
case 'service':
$environment->service_id = $this->resource->id;
break;
diff --git a/app/Http/Livewire/Project/Shared/Logs.php b/app/Http/Livewire/Project/Shared/Logs.php
index 69848a7c57..15a4e510c7 100644
--- a/app/Http/Livewire/Project/Shared/Logs.php
+++ b/app/Http/Livewire/Project/Shared/Logs.php
@@ -6,12 +6,13 @@ use App\Models\Application;
use App\Models\Server;
use App\Models\Service;
use App\Models\StandalonePostgresql;
+use App\Models\StandaloneRedis;
use Livewire\Component;
class Logs extends Component
{
public ?string $type = null;
- public Application|StandalonePostgresql|Service $resource;
+ public Application|StandalonePostgresql|Service|StandaloneRedis $resource;
public Server $server;
public ?string $container = null;
public $parameters;
@@ -33,7 +34,14 @@ class Logs extends Component
}
} else if (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
- $this->resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->firstOrFail();
+ $resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first();
+ if (is_null($resource)) {
+ $resource = StandaloneRedis::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;
$this->container = $this->resource->uuid;
diff --git a/app/Models/Environment.php b/app/Models/Environment.php
index 624787ba6b..f66bf48f28 100644
--- a/app/Models/Environment.php
+++ b/app/Models/Environment.php
@@ -14,7 +14,7 @@ class Environment extends Model
public function can_delete_environment()
{
- return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0 && $this->services()->count() == 0;
+ return $this->applications()->count() == 0 && $this->redis()->count() == 0 && $this->postgresqls()->count() == 0 && $this->services()->count() == 0;
}
public function applications()
@@ -26,10 +26,16 @@ class Environment extends Model
{
return $this->hasMany(StandalonePostgresql::class);
}
+ public function redis()
+ {
+ return $this->hasMany(StandaloneRedis::class);
+ }
public function databases()
{
- return $this->postgresqls();
+ $postgresqls = $this->postgresqls;
+ $redis = $this->redis;
+ return $postgresqls->concat($redis);
}
public function project()
diff --git a/app/Models/Project.php b/app/Models/Project.php
index 13f86bf661..f8f9622b81 100644
--- a/app/Models/Project.php
+++ b/app/Models/Project.php
@@ -52,4 +52,8 @@ class Project extends BaseModel
{
return $this->hasManyThrough(StandalonePostgresql::class, Environment::class);
}
+ public function redis()
+ {
+ return $this->hasManyThrough(StandaloneRedis::class, Environment::class);
+ }
}
diff --git a/app/Models/Server.php b/app/Models/Server.php
index 313040afa7..8b1ebc9760 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -123,7 +123,9 @@ class Server extends BaseModel
{
return $this->destinations()->map(function ($standaloneDocker) {
$postgresqls = $standaloneDocker->postgresqls;
- return $postgresqls?->concat([]) ?? collect([]);
+ $redis = $standaloneDocker->redis;
+ return $postgresqls->merge($redis);
+ // return $postgresqls?->concat([]) ?? collect([]);
})->flatten();
}
public function applications()
diff --git a/app/Models/StandaloneDocker.php b/app/Models/StandaloneDocker.php
index 16d85d956f..a594b854a9 100644
--- a/app/Models/StandaloneDocker.php
+++ b/app/Models/StandaloneDocker.php
@@ -15,6 +15,10 @@ class StandaloneDocker extends BaseModel
{
return $this->morphMany(StandalonePostgresql::class, 'destination');
}
+ public function redis()
+ {
+ return $this->morphMany(StandaloneRedis::class, 'destination');
+ }
public function server()
{
diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php
new file mode 100644
index 0000000000..f48dc7bb60
--- /dev/null
+++ b/app/Models/StandaloneRedis.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Casts\Attribute;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\HasMany;
+
+class StandaloneRedis extends BaseModel
+{
+ use HasFactory;
+ protected $guarded = [];
+
+ protected static function booted()
+ {
+ static::created(function ($database) {
+ LocalPersistentVolume::create([
+ 'name' => 'redis-data-' . $database->uuid,
+ 'mount_path' => '/data',
+ 'host_path' => null,
+ 'resource_id' => $database->id,
+ 'resource_type' => $database->getMorphClass(),
+ 'is_readonly' => true
+ ]);
+ });
+ static::deleting(function ($database) {
+ // Stop Container
+ instant_remote_process(
+ ["docker rm -f {$database->uuid}"],
+ $database->destination->server,
+ false
+ );
+ // Stop TCP Proxy
+ if ($database->is_public) {
+ instant_remote_process(["docker rm -f {$database->uuid}-proxy"], $database->destination->server, false);
+ }
+ $database->scheduledBackups()->delete();
+ $database->persistentStorages()->delete();
+ $database->environment_variables()->delete();
+ // Remove Volume
+ instant_remote_process(['docker volume rm postgres-data-' . $database->uuid], $database->destination->server, false);
+ });
+ }
+
+ public function portsMappings(): Attribute
+ {
+ return Attribute::make(
+ set: fn ($value) => $value === "" ? null : $value,
+ );
+ }
+
+ // Normal Deployments
+
+ public function portsMappingsArray(): Attribute
+ {
+ return Attribute::make(
+ get: fn () => is_null($this->ports_mappings)
+ ? []
+ : explode(',', $this->ports_mappings),
+
+ );
+ }
+
+ public function type(): string
+ {
+ return 'standalone-redis';
+ }
+
+ 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/bootstrap/helpers/constants.php b/bootstrap/helpers/constants.php
index c6fbc3c4d5..f915ea0412 100644
--- a/bootstrap/helpers/constants.php
+++ b/bootstrap/helpers/constants.php
@@ -1,6 +1,6 @@
<?php
-const DATABASE_TYPES = ['postgresql'];
+const DATABASE_TYPES = ['postgresql','redis'];
const VALID_CRON_STRINGS = [
'every_minute' => '* * * * *',
'hourly' => '0 * * * *',
diff --git a/bootstrap/helpers/databases.php b/bootstrap/helpers/databases.php
index 3b8e893c74..3c4f0dfd94 100644
--- a/bootstrap/helpers/databases.php
+++ b/bootstrap/helpers/databases.php
@@ -3,6 +3,7 @@
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\StandalonePostgresql;
+use App\Models\StandaloneRedis;
use Visus\Cuid2\Cuid2;
function generate_database_name(string $type): string
@@ -27,6 +28,21 @@ function create_standalone_postgresql($environment_id, $destination_uuid): Stand
]);
}
+function create_standalone_redis($environment_id, $destination_uuid): StandaloneRedis
+{
+ $destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
+ if (!$destination) {
+ throw new Exception('Destination not found');
+ }
+ return StandaloneRedis::create([
+ 'name' => generate_database_name('redis'),
+ 'redis_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 $filename
diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php
index abada1bda5..81cb92c496 100644
--- a/bootstrap/helpers/proxy.php
+++ b/bootstrap/helpers/proxy.php
@@ -3,6 +3,7 @@
use App\Actions\Proxy\SaveConfiguration;
use App\Models\Server;
use App\Models\StandalonePostgresql;
+use App\Models\StandaloneRedis;
use Symfony\Component\Yaml\Yaml;
function get_proxy_path()
@@ -187,8 +188,14 @@ function setup_default_redirect_404(string|null $redirect_url, Server $server)
}
}
-function startPostgresProxy(StandalonePostgresql $database)
+function startDatabaseProxy(StandalonePostgresql|StandaloneRedis $database)
{
+ $internalPort = null;
+ if ($database->getMorphClass()=== 'App\Models\StandaloneRedis') {
+ $internalPort = 6379;
+ } else if ($database->getMorphClass()=== 'App\Models\StandalonePostgresql') {
+ $internalPort = 5432;
+ }
$containerName = "{$database->uuid}-proxy";
$configuration_dir = database_proxy_dir($database->uuid);
$nginxconf = <<<EOF
@@ -203,7 +210,7 @@ events {
stream {
server {
listen $database->public_port;
- proxy_pass $database->uuid:5432;
+ proxy_pass $database->uuid:$internalPort;
}
}
EOF;
@@ -260,7 +267,7 @@ EOF;
"docker compose --project-directory {$configuration_dir} up --build -d >/dev/null",
], $database->destination->server);
}
-function stopPostgresProxy(StandalonePostgresql $database)
+function stopDatabaseProxy(StandalonePostgresql|StandaloneRedis $database)
{
instant_remote_process(["docker rm -f {$database->uuid}-proxy"], $database->destination->server);
}
diff --git a/database/migrations/2023_10_12_132430_create_standalone_redis_table.php b/database/migrations/2023_10_12_132430_create_standalone_redis_table.php
new file mode 100644
index 0000000000..e6c94dbb69
--- /dev/null
+++ b/database/migrations/2023_10_12_132430_create_standalone_redis_table.php
@@ -0,0 +1,54 @@
+<?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_redis', function (Blueprint $table) {
+ $table->id();
+ $table->string('uuid')->unique();
+ $table->string('name');
+ $table->string('description')->nullable();
+
+ $table->text('redis_password');
+ $table->longText('redis_conf')->nullable();
+
+ $table->string('status')->default('exited');
+
+ $table->string('image')->default('redis:7.2');
+
+ $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_redis');
+ }
+};
diff --git a/database/migrations/2023_10_12_132431_add_standalone_redis_to_environment_variables_table.php b/database/migrations/2023_10_12_132431_add_standalone_redis_to_environment_variables_table.php
new file mode 100644
index 0000000000..2fdacc9e5f
--- /dev/null
+++ b/database/migrations/2023_10_12_132431_add_standalone_redis_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_redis_id')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('environment_variables', function (Blueprint $table) {
+ $table->dropColumn('standalone_redis_id');
+ });
+ }
+};
diff --git a/database/seeders/StandaloneRedisSeeder.php b/database/seeders/StandaloneRedisSeeder.php
new file mode 100644
index 0000000000..cbe10bb003
--- /dev/null
+++ b/database/seeders/StandaloneRedisSeeder.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\StandaloneDocker;
+use App\Models\StandalonePostgresql;
+use App\Models\StandaloneRedis;
+use Illuminate\Database\Seeder;
+
+class StandaloneRedisSeeder extends Seeder
+{
+ public function run(): void
+ {
+ StandaloneRedis::create([
+ 'name' => 'Local PostgreSQL',
+ 'description' => 'Local PostgreSQL for testing',
+ 'redis_password' => 'redis',
+ 'environment_id' => 1,
+ 'destination_id' => 0,
+ 'destination_type' => StandaloneDocker::class,
+ ]);
+ }
+}
diff --git a/resources/views/livewire/project/database/redis/general.blade.php b/resources/views/livewire/project/database/redis/general.blade.php
new file mode 100644
index 0000000000..952e48bef9
--- /dev/null
+++ b/resources/views/livewire/project/database/redis/general.blade.php
@@ -0,0 +1,27 @@
+<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/_/postgres'>https://hub.docker.com/_/postgres</a>" />
+ </div>
+ <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="Redis URL" readonly wire:model="db_url" />
+ </div>
+ </form>
+</div>
diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.php
index 2aa62e83e2..5edd410b5c 100644
--- a/resources/views/livewire/project/new/select.blade.php
+++ b/resources/views/livewire/project/new/select.blade.php
@@ -94,6 +94,16 @@
</div>
</div>
</div>
+ <div class="box group" wire:click="setType('redis')">
+ <div class="flex flex-col mx-6">
+ <div class="font-bold text-white group-hover:text-white">
+ New Redis
+ </div>
+ <div class="text-xs group-hover:text-white">
+ The open source, in-memory data store for cache, streaming engine, and message broker.
+ </div>
+ </div>
+ </div>
{{-- <div class="box group" wire:click="setType('existing-postgresql')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
diff --git a/resources/views/livewire/project/service/storage.blade.php b/resources/views/livewire/project/service/storage.blade.php
index 97a089cf8a..0888c1c8eb 100644
--- a/resources/views/livewire/project/service/storage.blade.php
+++ b/resources/views/livewire/project/service/storage.blade.php
@@ -1,7 +1,8 @@
<div>
@if (
$resource->getMorphClass() == 'App\Models\Application' ||
- $resource->getMorphClass() == 'App\Models\StandalonePostgresql')
+ $resource->getMorphClass() == 'App\Models\StandalonePostgresql' ||
+ $resource->getMorphClass() == 'App\Models\StandaloneRedis')
<div class="flex items-center gap-2">
<h2>Storages</h2>
<x-helper
diff --git a/resources/views/project/database/configuration.blade.php b/resources/views/project/database/configuration.blade.php
index 78daa3b0c6..bed2f96efb 100644
--- a/resources/views/project/database/configuration.blade.php
+++ b/resources/views/project/database/configuration.blade.php
@@ -13,25 +13,23 @@
</x-modal>
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }" class="flex h-full pt-6">
<div class="flex flex-col gap-4 min-w-fit">
- <a :class="activeTab === 'general' && 'text-white'"
- @click.prevent="activeTab = 'general'; window.location.hash = 'general'" href="#">General</a>
+ <a :class="activeTab === 'general' && 'text-white'" @click.prevent="activeTab = 'general';
+ window.location.hash = 'general'" href="#">General</a>
<a :class="activeTab === 'environment-variables' && 'text-white'"
@click.prevent="activeTab = 'environment-variables'; window.location.hash = 'environment-variables'"
href="#">Environment
Variables</a>
- <a :class="activeTab === 'server' && 'text-white'"
- @click.prevent="activeTab = 'server'; window.location.hash = 'server'"
- href="#">Server
+ <a :class="activeTab === 'server' && 'text-white'" @click.prevent="activeTab = 'server';
+ window.location.hash = 'server'" href="#">Server
</a>
- <a :class="activeTab === 'storages' && 'text-white'"
- @click.prevent="activeTab = 'storages'; window.location.hash = 'storages'" href="#">Storages
+ <a :class="activeTab === 'storages' && 'text-white'" @click.prevent="activeTab = 'storages';
+ window.location.hash = 'storages'" href="#">Storages
</a>
- <a :class="activeTab === 'resource-limits' && 'text-white'"
- @click.prevent="activeTab = 'resource-limits'; window.location.hash = 'resource-limits'"
- href="#">Resource Limits
+ <a :class="activeTab === 'resource-limits' && 'text-white'" @click.prevent="activeTab = 'resource-limits';
+ window.location.hash = 'resource-limits'" href="#">Resource Limits
</a>
- <a :class="activeTab === 'danger' && 'text-white'"
- @click.prevent="activeTab = 'danger'; window.location.hash = 'danger'" href="#">Danger Zone
+ <a :class="activeTab === 'danger' && 'text-white'" @click.prevent="activeTab = 'danger';
+ window.location.hash = 'danger'" href="#">Danger Zone
</a>
</div>
<div class="w-full pl-8">
@@ -39,6 +37,9 @@
@if ($database->type() === 'standalone-postgresql')
<livewire:project.database.postgresql.general :database="$database" />
@endif
+ @if ($database->type() === 'standalone-redis')
+ <livewire:project.database.redis.general :database="$database" />
+ @endif
</div>
<div x-cloak x-show="activeTab === 'environment-variables'">
<livewire:project.shared.environment-variable.all :resource="$database" />
diff --git a/resources/views/project/resources.blade.php b/resources/views/project/resources.blade.php
index ac728fc0d4..b842f82ee2 100644
--- a/resources/views/project/resources.blade.php
+++ b/resources/views/project/resources.blade.php
@@ -46,7 +46,7 @@
</div>
</a>
@endforeach
- @foreach ($environment->databases->sortBy('name') as $databases)
+ @foreach ($environment->databases()->sortBy('name') as $databases)
<a class="box group"
href="{{ route('project.database.configuration', [$project->uuid, $environment->name, $databases->uuid]) }}">
<div class="flex flex-col mx-6">