refactor
This commit is contained in:
@@ -13,4 +13,6 @@ APP_DEBUG=true
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
APP_PORT=8000
|
APP_PORT=8000
|
||||||
|
|
||||||
|
DEV_CONFIG_PATH=/home/andrasbacsai/devel/coolify/_data/coolify
|
||||||
|
|
||||||
DUSK_DRIVER_URL=http://selenium:4444
|
DUSK_DRIVER_URL=http://selenium:4444
|
||||||
|
28
app/Actions/Proxy/CheckConfigurationSync.php
Normal file
28
app/Actions/Proxy/CheckConfigurationSync.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Proxy;
|
||||||
|
|
||||||
|
use App\Actions\Proxy\SaveConfigurationSync;
|
||||||
|
use App\Enums\ProxyTypes;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CheckConfigurationSync
|
||||||
|
{
|
||||||
|
public function __invoke(Server $server, bool $reset = false)
|
||||||
|
{
|
||||||
|
$proxy_path = get_proxy_path();
|
||||||
|
$proxy_configuration = instant_remote_process([
|
||||||
|
"cat $proxy_path/docker-compose.yml",
|
||||||
|
], $server, false);
|
||||||
|
|
||||||
|
if ($reset || is_null($proxy_configuration)) {
|
||||||
|
$proxy_configuration = Str::of(generate_default_proxy_configuration($server))->trim()->value;
|
||||||
|
resolve(SaveConfigurationSync::class)($server, $proxy_configuration);
|
||||||
|
return $proxy_configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $proxy_configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Proxy;
|
|
||||||
|
|
||||||
use App\Enums\ProxyTypes;
|
|
||||||
use App\Models\Server;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class CheckProxySettingsInSync
|
|
||||||
{
|
|
||||||
public function __invoke(Server $server, bool $reset = false)
|
|
||||||
{
|
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
|
||||||
$output = instant_remote_process([
|
|
||||||
"cat $proxy_path/docker-compose.yml",
|
|
||||||
], $server, false);
|
|
||||||
if (is_null($output) || $reset) {
|
|
||||||
$final_output = Str::of(getProxyConfiguration($server))->trim()->value;
|
|
||||||
} else {
|
|
||||||
$final_output = Str::of($output)->trim()->value;
|
|
||||||
}
|
|
||||||
$docker_compose_yml_base64 = base64_encode($final_output);
|
|
||||||
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
|
||||||
$server->save();
|
|
||||||
if (is_null($output) || $reset) {
|
|
||||||
instant_remote_process([
|
|
||||||
"mkdir -p $proxy_path",
|
|
||||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
|
||||||
], $server);
|
|
||||||
}
|
|
||||||
return $final_output;
|
|
||||||
}
|
|
||||||
}
|
|
23
app/Actions/Proxy/SaveConfigurationSync.php
Normal file
23
app/Actions/Proxy/SaveConfigurationSync.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Proxy;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class SaveConfigurationSync
|
||||||
|
{
|
||||||
|
public function __invoke(Server $server, string $configuration)
|
||||||
|
{
|
||||||
|
$proxy_path = get_proxy_path();
|
||||||
|
$docker_compose_yml_base64 = base64_encode($configuration);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Proxy;
|
namespace App\Actions\Proxy;
|
||||||
|
|
||||||
|
use App\Actions\Proxy\CheckConfigurationSync;
|
||||||
use App\Enums\ProxyStatus;
|
use App\Enums\ProxyStatus;
|
||||||
use App\Enums\ProxyTypes;
|
use App\Enums\ProxyTypes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
@@ -18,8 +19,7 @@ class StartProxy
|
|||||||
$server->proxy->status = ProxyStatus::EXITED->value;
|
$server->proxy->status = ProxyStatus::EXITED->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
}
|
}
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = get_proxy_path();
|
||||||
|
|
||||||
$networks = collect($server->standaloneDockers)->map(function ($docker) {
|
$networks = collect($server->standaloneDockers)->map(function ($docker) {
|
||||||
return $docker['network'];
|
return $docker['network'];
|
||||||
})->unique();
|
})->unique();
|
||||||
@@ -30,23 +30,16 @@ 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 = instant_remote_process([
|
$configuration = resolve(CheckConfigurationSync::class)($server);
|
||||||
"cat $proxy_path/docker-compose.yml",
|
|
||||||
], $server, false);
|
|
||||||
if (is_null($configuration)) {
|
|
||||||
$configuration = Str::of(getProxyConfiguration($server))->trim()->value;
|
|
||||||
} else {
|
|
||||||
$configuration = Str::of($configuration)->trim()->value;
|
|
||||||
}
|
|
||||||
$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();
|
||||||
|
|
||||||
$activity = remote_process([
|
$activity = remote_process([
|
||||||
"echo 'Creating required Docker networks...'",
|
"echo 'Creating required Docker networks...'",
|
||||||
...$create_networks_command,
|
...$create_networks_command,
|
||||||
"mkdir -p $proxy_path",
|
|
||||||
"cd $proxy_path",
|
"cd $proxy_path",
|
||||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
|
||||||
"echo 'Creating Docker Compose file...'",
|
"echo 'Creating Docker Compose file...'",
|
||||||
"echo 'Pulling docker image...'",
|
"echo 'Pulling docker image...'",
|
||||||
'docker compose pull -q',
|
'docker compose pull -q',
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Server;
|
namespace App\Http\Livewire\Server;
|
||||||
|
|
||||||
use App\Actions\Proxy\CheckProxySettingsInSync;
|
use App\Actions\Proxy\CheckConfigurationSync;
|
||||||
|
use App\Actions\Proxy\SaveConfigurationSync;
|
||||||
use App\Enums\ProxyTypes;
|
use App\Enums\ProxyTypes;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
@@ -16,7 +17,7 @@ class Proxy extends Component
|
|||||||
public $proxy_settings = null;
|
public $proxy_settings = null;
|
||||||
public string|null $redirect_url = null;
|
public string|null $redirect_url = null;
|
||||||
|
|
||||||
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration'];
|
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration'=>'submit'];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->redirect_url = $this->server->proxy->redirect_url;
|
$this->redirect_url = $this->server->proxy->redirect_url;
|
||||||
@@ -41,17 +42,11 @@ class Proxy extends Component
|
|||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
resolve(SaveConfigurationSync::class)($this->server, $this->proxy_settings);
|
||||||
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
|
||||||
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
|
||||||
$this->server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
|
||||||
$this->server->proxy->redirect_url = $this->redirect_url;
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
|
|
||||||
instant_remote_process([
|
|
||||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
|
||||||
], $this->server);
|
|
||||||
$this->server->refresh();
|
|
||||||
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
|
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
|
||||||
$this->emit('success', 'Proxy configuration saved.');
|
$this->emit('success', 'Proxy configuration saved.');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -61,7 +56,7 @@ class Proxy extends Component
|
|||||||
public function reset_proxy_configuration()
|
public function reset_proxy_configuration()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->proxy_settings = resolve(CheckProxySettingsInSync::class)($this->server, true);
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return general_error_handler(err: $e);
|
return general_error_handler(err: $e);
|
||||||
}
|
}
|
||||||
@@ -69,7 +64,7 @@ class Proxy extends Component
|
|||||||
public function load_proxy_configuration()
|
public function load_proxy_configuration()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->proxy_settings = resolve(CheckProxySettingsInSync::class)($this->server);
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return general_error_handler(err: $e);
|
return general_error_handler(err: $e);
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Spatie\Url\Url;
|
use Spatie\Url\Url;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
function getProxyConfiguration(Server $server)
|
function get_proxy_path() {
|
||||||
|
$base_path = config('coolify.base_config_path');
|
||||||
|
$proxy_path = "$base_path/proxy";
|
||||||
|
return $proxy_path;
|
||||||
|
}
|
||||||
|
function generate_default_proxy_configuration(Server $server)
|
||||||
{
|
{
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = get_proxy_path();
|
||||||
if (isDev()) {
|
if (isDev()) {
|
||||||
$proxy_path = $proxy_path . '/testing-host-1/';
|
$proxy_path = config('coolify.dev_config_path') . '/' . $server->name . '/proxy';
|
||||||
}
|
}
|
||||||
$networks = collect($server->standaloneDockers)->map(function ($docker) {
|
$networks = collect($server->standaloneDockers)->map(function ($docker) {
|
||||||
return $docker['network'];
|
return $docker['network'];
|
||||||
@@ -53,7 +59,7 @@ function getProxyConfiguration(Server $server)
|
|||||||
"--ping=true",
|
"--ping=true",
|
||||||
"--ping.entrypoint=http",
|
"--ping.entrypoint=http",
|
||||||
"--api.dashboard=true",
|
"--api.dashboard=true",
|
||||||
"--api.insecure=true",
|
"--api.insecure=false",
|
||||||
"--entrypoints.http.address=:80",
|
"--entrypoints.http.address=:80",
|
||||||
"--entrypoints.https.address=:443",
|
"--entrypoints.https.address=:443",
|
||||||
"--entrypoints.http.http.encodequerysemicolons=true",
|
"--entrypoints.http.http.encodequerysemicolons=true",
|
||||||
@@ -86,8 +92,10 @@ function getProxyConfiguration(Server $server)
|
|||||||
}
|
}
|
||||||
function setup_default_redirect_404(string|null $redirect_url, Server $server)
|
function setup_default_redirect_404(string|null $redirect_url, Server $server)
|
||||||
{
|
{
|
||||||
$traefik_dynamic_conf_path = '/data/coolify/proxy/dynamic';
|
ray('called');
|
||||||
|
$traefik_dynamic_conf_path = get_proxy_path() . "/dynamic";
|
||||||
$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);
|
||||||
if (empty($redirect_url)) {
|
if (empty($redirect_url)) {
|
||||||
remote_process([
|
remote_process([
|
||||||
"rm -f $traefik_default_redirect_file",
|
"rm -f $traefik_default_redirect_file",
|
||||||
|
@@ -10,5 +10,5 @@ return [
|
|||||||
'mux_enabled' => env('MUX_ENABLED', true),
|
'mux_enabled' => env('MUX_ENABLED', true),
|
||||||
'dev_webhook' => env('SERVEO_URL'),
|
'dev_webhook' => env('SERVEO_URL'),
|
||||||
'base_config_path' => env('BASE_CONFIG_PATH', '/data/coolify'),
|
'base_config_path' => env('BASE_CONFIG_PATH', '/data/coolify'),
|
||||||
'proxy_config_path' => env('BASE_CONFIG_PATH', '/data/coolify') . "/proxy",
|
'dev_config_path' => env('DEV_CONFIG_PATH', './_data/coolify'),
|
||||||
];
|
];
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'project_path_on_host' => env('PROJECT_PATH_ON_HOST', '/var/www/html')
|
|
||||||
];
|
|
@@ -1,7 +1,6 @@
|
|||||||
version: '3.8'
|
version: "3.8"
|
||||||
|
|
||||||
x-testing-host:
|
x-testing-host: &testing-host-base
|
||||||
&testing-host-base
|
|
||||||
build:
|
build:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
context: ./docker/testing-host
|
context: ./docker/testing-host
|
||||||
@@ -55,19 +54,19 @@ services:
|
|||||||
container_name: coolify-testing-host
|
container_name: coolify-testing-host
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- "./_data/coolify/proxy/testing-host-1:/data/coolify/proxy"
|
- "./_data/coolify/testing-local-docker-container/proxy:/data/coolify/proxy"
|
||||||
testing-host-2:
|
testing-host-2:
|
||||||
<<: *testing-host-base
|
<<: *testing-host-base
|
||||||
container_name: coolify-testing-host-2
|
container_name: coolify-testing-host-2
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- "./_data/coolify/proxy/testing-host-2:/data/coolify/proxy"
|
- "./_data/coolify/testing-local-docker-container-2/proxy:/data/coolify/proxy"
|
||||||
mailpit:
|
mailpit:
|
||||||
image: 'axllent/mailpit:latest'
|
image: "axllent/mailpit:latest"
|
||||||
container_name: coolify-mail
|
container_name: coolify-mail
|
||||||
ports:
|
ports:
|
||||||
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
|
- "${FORWARD_MAILPIT_PORT:-1025}:1025"
|
||||||
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
|
- "${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025"
|
||||||
networks:
|
networks:
|
||||||
- coolify
|
- coolify
|
||||||
|
|
||||||
|
@@ -12,13 +12,12 @@
|
|||||||
@endif
|
@endif
|
||||||
<livewire:server.proxy.status :server="$server" />
|
<livewire:server.proxy.status :server="$server" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pt-3 pb-4 ">Traefik v2</div>
|
<div class="pt-3 pb-4 ">Traefik v2</div>
|
||||||
@if (
|
@if (
|
||||||
$server->proxy->last_applied_settings &&
|
$server->proxy->last_applied_settings &&
|
||||||
$server->proxy->last_saved_settings !== $server->proxy->last_applied_settings)
|
$server->proxy->last_saved_settings !== $server->proxy->last_applied_settings)
|
||||||
<div class="text-red-500 ">Configuration out of sync. Restart to get the new
|
<div class="text-red-500 ">Configuration out of sync. Restart the proxy to apply the new
|
||||||
configs.
|
configurations.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<div class="container w-full pb-4 mx-auto">
|
<div class="container w-full pb-4 mx-auto">
|
||||||
|
Reference in New Issue
Block a user