diff --git a/app/Actions/Proxy/CheckConfigurationSync.php b/app/Actions/Proxy/CheckConfiguration.php similarity index 76% rename from app/Actions/Proxy/CheckConfigurationSync.php rename to app/Actions/Proxy/CheckConfiguration.php index c1a261796..1526c9728 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.php new file mode 100644 index 000000000..85aebf619 --- /dev/null +++ b/app/Actions/Proxy/SaveConfiguration.php @@ -0,0 +1,27 @@ +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.php deleted file mode 100644 index d58dad0c7..000000000 --- a/app/Actions/Proxy/SaveConfigurationSync.php +++ /dev/null @@ -1,29 +0,0 @@ -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.php index 37c9c492e..fd14f49d5 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -32,8 +32,10 @@ class StartProxy return "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.php index d65518975..560bdd784 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 Component public 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 Component public 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 Component public 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.php index df369c49a..ad60ca53a 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 Component public $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.php index c78a560c7..e3db2be36 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.json index 79f3793dd..217560b57 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.lock index 63d0c626d..551d78229 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": "loris.leiva@gmail.com", + "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": "loris.leiva@gmail.com", + "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" }