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
fix: proxy configuration saving
Andras Bacsai61f58fa30f1b
diff --git a/app/Actions/Proxy/CheckConfigurationSync.php b/app/Actions/Proxy/CheckConfiguration.phpsimilarity index 76%rename from app/Actions/Proxy/CheckConfigurationSync.phprename to app/Actions/Proxy/CheckConfiguration.phpindex c1a261796b..1526c9728f 100644--- a/app/Actions/Proxy/CheckConfigurationSync.php+++ b/app/Actions/Proxy/CheckConfiguration.php@@ -2,12 +2,14 @@namespace App\Actions\Proxy;+use Lorisleiva\Actions\Concerns\AsAction;use App\Models\Server;use Illuminate\Support\Str;-class CheckConfigurationSync+class CheckConfiguration{- public function __invoke(Server $server, bool $reset = false)+ use AsAction;+ public function handle(Server $server, bool $reset = false){$proxy_path = get_proxy_path();$proxy_configuration = instant_remote_process([diff --git a/app/Actions/Proxy/SaveConfiguration.php b/app/Actions/Proxy/SaveConfiguration.phpnew file mode 100644index 0000000000..85aebf6197--- /dev/null+++ b/app/Actions/Proxy/SaveConfiguration.php@@ -0,0 +1,27 @@+<?php++namespace App\Actions\Proxy;++use App\Models\Server;+use Illuminate\Support\Str;+use Lorisleiva\Actions\Concerns\AsAction;++class SaveConfiguration+{+ use AsAction;++ public function handle(Server $server)+ {+ $proxy_settings = CheckConfiguration::run($server, true);+ $proxy_path = get_proxy_path();+ $docker_compose_yml_base64 = base64_encode($proxy_settings);++ $server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;+ $server->save();++ return instant_remote_process([+ "mkdir -p $proxy_path",+ "echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",+ ], $server);+ }+}diff --git a/app/Actions/Proxy/SaveConfigurationSync.php b/app/Actions/Proxy/SaveConfigurationSync.phpdeleted file mode 100644index d58dad0c79..0000000000--- a/app/Actions/Proxy/SaveConfigurationSync.php+++ /dev/null@@ -1,29 +0,0 @@-<?php--namespace App\Actions\Proxy;--use App\Models\Server;-use Illuminate\Support\Str;--class SaveConfigurationSync-{- public function __invoke(Server $server)- {- try {- $proxy_settings = resolve(CheckConfigurationSync::class)($server, true);- $proxy_path = get_proxy_path();- $docker_compose_yml_base64 = base64_encode($proxy_settings);-- $server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;- $server->save();-- instant_remote_process([- "mkdir -p $proxy_path",- "echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",- ], $server);- } catch (\Throwable $e) {- ray($e);- }-- }-}diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.phpindex 37c9c492e2..fd14f49d5c 100644--- a/app/Actions/Proxy/StartProxy.php+++ b/app/Actions/Proxy/StartProxy.php@@ -32,8 +32,10 @@ class StartProxyreturn "docker network ls --format '{{.Name}}' | grep '^$network$' >/dev/null 2>&1 || docker network create --attachable $network > /dev/null 2>&1";});- $configuration = resolve(CheckConfigurationSync::class)($server);-+ $configuration = CheckConfiguration::run($server);+ if (!$configuration) {+ throw new \Exception("Configuration is not synced");+ }$docker_compose_yml_base64 = base64_encode($configuration);$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;$server->save();diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.phpindex d655189751..560bdd784c 100644--- a/app/Http/Livewire/Server/Proxy.php+++ b/app/Http/Livewire/Server/Proxy.php@@ -2,9 +2,8 @@namespace App\Http\Livewire\Server;-use App\Actions\Proxy\CheckConfigurationSync;-use App\Actions\Proxy\SaveConfigurationSync;-use App\Enums\ProxyTypes;+use App\Actions\Proxy\CheckConfiguration;+use App\Actions\Proxy\SaveConfiguration;use App\Models\Server;use Livewire\Component;@@ -48,8 +47,7 @@ class Proxy extends Componentpublic function submit(){try {- resolve(SaveConfigurationSync::class)($this->server);-+ SaveConfiguration::run($this->server);$this->server->proxy->redirect_url = $this->redirect_url;$this->server->save();@@ -63,7 +61,7 @@ class Proxy extends Componentpublic function reset_proxy_configuration(){try {- $this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true);+ $this->proxy_settings = CheckConfiguration::run($this->server, true);} catch (\Throwable $e) {return handleError($e);}@@ -72,8 +70,7 @@ class Proxy extends Componentpublic function loadProxyConfiguration(){try {- ray('loadProxyConfiguration');- $this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server);+ $this->proxy_settings = CheckConfiguration::run($this->server);} catch (\Throwable $e) {return handleError($e);}diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.phpindex df369c49a4..ad60ca53aa 100644--- a/app/Http/Livewire/Server/Proxy/Deploy.php+++ b/app/Http/Livewire/Server/Proxy/Deploy.php@@ -2,7 +2,7 @@namespace App\Http\Livewire\Server\Proxy;-use App\Actions\Proxy\SaveConfigurationSync;+use App\Actions\Proxy\SaveConfiguration;use App\Actions\Proxy\StartProxy;use App\Models\Server;use Livewire\Component;@@ -13,20 +13,25 @@ class Deploy extends Componentpublic $proxy_settings = null;protected $listeners = ['proxyStatusUpdated'];- public function proxyStatusUpdated() {+ public function proxyStatusUpdated()+ {$this->server->refresh();}public function startProxy(){- if (- $this->server->proxy->last_applied_settings &&- $this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings- ) {- resolve(SaveConfigurationSync::class)($this->server);- }+ try {+ if (+ $this->server->proxy->last_applied_settings &&+ $this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings+ ) {+ SaveConfiguration::run($this->server);+ }- $activity = resolve(StartProxy::class)($this->server);- $this->emit('newMonitorActivity', $activity->id);+ $activity = resolve(StartProxy::class)($this->server);+ $this->emit('newMonitorActivity', $activity->id);+ } catch (\Throwable $e) {+ return handleError($e);+ }}public function stop()diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.phpindex c78a560c77..e3db2be36f 100644--- a/bootstrap/helpers/proxy.php+++ b/bootstrap/helpers/proxy.php@@ -96,7 +96,7 @@ function setup_default_redirect_404(string|null $redirect_url, Server $server)$traefik_default_redirect_file = "$traefik_dynamic_conf_path/default_redirect_404.yaml";ray($redirect_url);if (empty($redirect_url)) {- remote_process([+ instant_remote_process(["rm -f $traefik_default_redirect_file",], $server);} else {@@ -157,7 +157,7 @@ function setup_default_redirect_404(string|null $redirect_url, Server $server)$base64 = base64_encode($yaml);ray("mkdir -p $traefik_dynamic_conf_path");- remote_process([+ instant_remote_process(["mkdir -p $traefik_dynamic_conf_path","echo '$base64' | base64 -d > $traefik_default_redirect_file",], $server);diff --git a/composer.json b/composer.jsonindex 79f3793dd5..217560b572 100644--- a/composer.json+++ b/composer.json@@ -22,6 +22,7 @@"lcobucci/jwt": "^5.0.0","league/flysystem-aws-s3-v3": "^3.0","livewire/livewire": "^v2.12.3",+ "lorisleiva/laravel-actions": "^2.7","masmerise/livewire-toaster": "^1.2","nubs/random-name-generator": "^2.2","phpseclib/phpseclib": "~3.0",diff --git a/composer.lock b/composer.lockindex 63d0c626d9..551d78229f 100644--- a/composer.lock+++ b/composer.lock@@ -4,7 +4,7 @@"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies","This file is @generated automatically"],- "content-hash": "cf138424c896f30b035bc8cdff63e8d1",+ "content-hash": "de2c45be3f03d43430549d963778dc4a","packages": [{"name": "aws/aws-crt-php",@@ -3059,6 +3059,153 @@],"time": "2023-08-11T04:02:34+00:00"},+ {+ "name": "lorisleiva/laravel-actions",+ "version": "v2.7.1",+ "source": {+ "type": "git",+ "url": "https://github.com/lorisleiva/laravel-actions.git",+ "reference": "5250614fd6b77e8e2780be0206174e069e94661d"+ },+ "dist": {+ "type": "zip",+ "url": "https://api.github.com/repos/lorisleiva/laravel-actions/zipball/5250614fd6b77e8e2780be0206174e069e94661d",+ "reference": "5250614fd6b77e8e2780be0206174e069e94661d",+ "shasum": ""+ },+ "require": {+ "illuminate/contracts": "9.0 - 9.34 || ^9.36 || ^10.0",+ "lorisleiva/lody": "^0.4",+ "php": "^8.0"+ },+ "require-dev": {+ "orchestra/testbench": "^8.5",+ "pestphp/pest": "^1.23",+ "phpunit/phpunit": "^9.6"+ },+ "type": "library",+ "extra": {+ "laravel": {+ "providers": [+ "Lorisleiva\\Actions\\ActionServiceProvider"+ ],+ "aliases": {+ "Action": "Lorisleiva\\Actions\\Facades\\Actions"+ }+ }+ },+ "autoload": {+ "psr-4": {+ "Lorisleiva\\Actions\\": "src"+ }+ },+ "notification-url": "https://packagist.org/downloads/",+ "license": [+ "MIT"+ ],+ "authors": [+ {+ "name": "Loris Leiva",+ "email": "[email protected]",+ "homepage": "https://lorisleiva.com",+ "role": "Developer"+ }+ ],+ "description": "Laravel components that take care of one specific task",+ "homepage": "https://github.com/lorisleiva/laravel-actions",+ "keywords": [+ "action",+ "command",+ "component",+ "controller",+ "job",+ "laravel",+ "object"+ ],+ "support": {+ "issues": "https://github.com/lorisleiva/laravel-actions/issues",+ "source": "https://github.com/lorisleiva/laravel-actions/tree/v2.7.1"+ },+ "funding": [+ {+ "url": "https://github.com/sponsors/lorisleiva",+ "type": "github"+ }+ ],+ "time": "2023-08-24T10:20:57+00:00"+ },+ {+ "name": "lorisleiva/lody",+ "version": "v0.4.0",+ "source": {+ "type": "git",+ "url": "https://github.com/lorisleiva/lody.git",+ "reference": "1a43e8e423f3b2b64119542bc44a2071208fae16"+ },+ "dist": {+ "type": "zip",+ "url": "https://api.github.com/repos/lorisleiva/lody/zipball/1a43e8e423f3b2b64119542bc44a2071208fae16",+ "reference": "1a43e8e423f3b2b64119542bc44a2071208fae16",+ "shasum": ""+ },+ "require": {+ "illuminate/contracts": "^8.0|^9.0|^10.0",+ "php": "^8.0"+ },+ "require-dev": {+ "orchestra/testbench": "^8.0",+ "pestphp/pest": "^1.20.0",+ "phpunit/phpunit": "^9.5.10"+ },+ "type": "library",+ "extra": {+ "laravel": {+ "providers": [+ "Lorisleiva\\Lody\\LodyServiceProvider"+ ],+ "aliases": {+ "Lody": "Lorisleiva\\Lody\\Lody"+ }+ }+ },+ "autoload": {+ "psr-4": {+ "Lorisleiva\\Lody\\": "src"+ }+ },+ "notification-url": "https://packagist.org/downloads/",+ "license": [+ "MIT"+ ],+ "authors": [+ {+ "name": "Loris Leiva",+ "email": "[email protected]",+ "homepage": "https://lorisleiva.com",+ "role": "Developer"+ }+ ],+ "description": "Load files and classes as lazy collections in Laravel.",+ "homepage": "https://github.com/lorisleiva/lody",+ "keywords": [+ "classes",+ "collection",+ "files",+ "laravel",+ "load"+ ],+ "support": {+ "issues": "https://github.com/lorisleiva/lody/issues",+ "source": "https://github.com/lorisleiva/lody/tree/v0.4.0"+ },+ "funding": [+ {+ "url": "https://github.com/sponsors/lorisleiva",+ "type": "github"+ }+ ],+ "time": "2023-02-05T15:03:45+00:00"+ },{"name": "masmerise/livewire-toaster","version": "1.3.0",@@ -13089,5 +13236,5 @@"php": "^8.2"},"platform-dev": [],- "plugin-api-version": "2.3.0"+ "plugin-api-version": "2.6.0"}