fix: proxy configuration saving
This commit is contained in:
parent
026f3fd72d
commit
61f58fa30f
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Actions\Proxy;
|
namespace App\Actions\Proxy;
|
||||||
|
|
||||||
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Str;
|
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_path = get_proxy_path();
|
||||||
$proxy_configuration = instant_remote_process([
|
$proxy_configuration = instant_remote_process([
|
27
app/Actions/Proxy/SaveConfiguration.php
Normal file
27
app/Actions/Proxy/SaveConfiguration.php
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -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";
|
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);
|
$docker_compose_yml_base64 = base64_encode($configuration);
|
||||||
$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Server;
|
namespace App\Http\Livewire\Server;
|
||||||
|
|
||||||
use App\Actions\Proxy\CheckConfigurationSync;
|
use App\Actions\Proxy\CheckConfiguration;
|
||||||
use App\Actions\Proxy\SaveConfigurationSync;
|
use App\Actions\Proxy\SaveConfiguration;
|
||||||
use App\Enums\ProxyTypes;
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
@ -48,8 +47,7 @@ class Proxy extends Component
|
|||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
resolve(SaveConfigurationSync::class)($this->server);
|
SaveConfiguration::run($this->server);
|
||||||
|
|
||||||
$this->server->proxy->redirect_url = $this->redirect_url;
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ class Proxy extends Component
|
|||||||
public function reset_proxy_configuration()
|
public function reset_proxy_configuration()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true);
|
$this->proxy_settings = CheckConfiguration::run($this->server, true);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
}
|
}
|
||||||
@ -72,8 +70,7 @@ class Proxy extends Component
|
|||||||
public function loadProxyConfiguration()
|
public function loadProxyConfiguration()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ray('loadProxyConfiguration');
|
$this->proxy_settings = CheckConfiguration::run($this->server);
|
||||||
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server);
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Server\Proxy;
|
namespace App\Http\Livewire\Server\Proxy;
|
||||||
|
|
||||||
use App\Actions\Proxy\SaveConfigurationSync;
|
use App\Actions\Proxy\SaveConfiguration;
|
||||||
use App\Actions\Proxy\StartProxy;
|
use App\Actions\Proxy\StartProxy;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
@ -13,20 +13,25 @@ class Deploy extends Component
|
|||||||
public $proxy_settings = null;
|
public $proxy_settings = null;
|
||||||
protected $listeners = ['proxyStatusUpdated'];
|
protected $listeners = ['proxyStatusUpdated'];
|
||||||
|
|
||||||
public function proxyStatusUpdated() {
|
public function proxyStatusUpdated()
|
||||||
|
{
|
||||||
$this->server->refresh();
|
$this->server->refresh();
|
||||||
}
|
}
|
||||||
public function startProxy()
|
public function startProxy()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
if (
|
if (
|
||||||
$this->server->proxy->last_applied_settings &&
|
$this->server->proxy->last_applied_settings &&
|
||||||
$this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings
|
$this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings
|
||||||
) {
|
) {
|
||||||
resolve(SaveConfigurationSync::class)($this->server);
|
SaveConfiguration::run($this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity = resolve(StartProxy::class)($this->server);
|
$activity = resolve(StartProxy::class)($this->server);
|
||||||
$this->emit('newMonitorActivity', $activity->id);
|
$this->emit('newMonitorActivity', $activity->id);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return handleError($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop()
|
public function stop()
|
||||||
|
@ -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";
|
$traefik_default_redirect_file = "$traefik_dynamic_conf_path/default_redirect_404.yaml";
|
||||||
ray($redirect_url);
|
ray($redirect_url);
|
||||||
if (empty($redirect_url)) {
|
if (empty($redirect_url)) {
|
||||||
remote_process([
|
instant_remote_process([
|
||||||
"rm -f $traefik_default_redirect_file",
|
"rm -f $traefik_default_redirect_file",
|
||||||
], $server);
|
], $server);
|
||||||
} else {
|
} else {
|
||||||
@ -157,7 +157,7 @@ function setup_default_redirect_404(string|null $redirect_url, Server $server)
|
|||||||
|
|
||||||
$base64 = base64_encode($yaml);
|
$base64 = base64_encode($yaml);
|
||||||
ray("mkdir -p $traefik_dynamic_conf_path");
|
ray("mkdir -p $traefik_dynamic_conf_path");
|
||||||
remote_process([
|
instant_remote_process([
|
||||||
"mkdir -p $traefik_dynamic_conf_path",
|
"mkdir -p $traefik_dynamic_conf_path",
|
||||||
"echo '$base64' | base64 -d > $traefik_default_redirect_file",
|
"echo '$base64' | base64 -d > $traefik_default_redirect_file",
|
||||||
], $server);
|
], $server);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
"lcobucci/jwt": "^5.0.0",
|
"lcobucci/jwt": "^5.0.0",
|
||||||
"league/flysystem-aws-s3-v3": "^3.0",
|
"league/flysystem-aws-s3-v3": "^3.0",
|
||||||
"livewire/livewire": "^v2.12.3",
|
"livewire/livewire": "^v2.12.3",
|
||||||
|
"lorisleiva/laravel-actions": "^2.7",
|
||||||
"masmerise/livewire-toaster": "^1.2",
|
"masmerise/livewire-toaster": "^1.2",
|
||||||
"nubs/random-name-generator": "^2.2",
|
"nubs/random-name-generator": "^2.2",
|
||||||
"phpseclib/phpseclib": "~3.0",
|
"phpseclib/phpseclib": "~3.0",
|
||||||
|
151
composer.lock
generated
151
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "cf138424c896f30b035bc8cdff63e8d1",
|
"content-hash": "de2c45be3f03d43430549d963778dc4a",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aws/aws-crt-php",
|
"name": "aws/aws-crt-php",
|
||||||
@ -3059,6 +3059,153 @@
|
|||||||
],
|
],
|
||||||
"time": "2023-08-11T04:02:34+00:00"
|
"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",
|
"name": "masmerise/livewire-toaster",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
@ -13089,5 +13236,5 @@
|
|||||||
"php": "^8.2"
|
"php": "^8.2"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.6.0"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user