lasthourcloud/app/Actions/Proxy/CheckProxySettingsInSync.php

34 lines
1.0 KiB
PHP
Raw Normal View History

2023-05-12 19:42:39 +01:00
<?php
namespace App\Actions\Proxy;
use App\Enums\ProxyTypes;
use App\Models\Server;
2023-05-15 13:45:37 +02:00
use Illuminate\Support\Str;
2023-05-12 19:42:39 +01:00
class CheckProxySettingsInSync
{
public function __invoke(Server $server)
{
2023-05-15 13:45:37 +02:00
$proxy_path = config('coolify.proxy_config_path');
2023-05-12 19:51:07 +01:00
$output = instantRemoteProcess([
2023-05-15 13:45:37 +02:00
"cat $proxy_path/docker-compose.yml",
], $server, false);
if (is_null($output)) {
$final_output = Str::of(getProxyConfiguration($server))->trim();
} else {
$final_output = Str::of($output)->trim();
}
$docker_compose_yml_base64 = base64_encode($final_output);
$server->extra_attributes->last_saved_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$server->save();
if (is_null($output)) {
instantRemoteProcess([
"mkdir -p $proxy_path",
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
], $server);
}
return $final_output;
2023-05-12 19:42:39 +01:00
}
}