coolify/app/Actions/Proxy/CheckProxySettingsInSync.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2023-05-12 20:42:39 +02:00
<?php
namespace App\Actions\Proxy;
use App\Enums\ActivityTypes;
use App\Enums\ProxyTypes;
use App\Models\Server;
use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml;
class CheckProxySettingsInSync
{
public function __invoke(Server $server)
{
// @TODO What is the mechanism to make sure setting in sync?
$folder_name = match ($server->extra_attributes->proxy) {
ProxyTypes::TRAEFIK_V2->value => 'proxy',
};
2023-05-12 20:51:07 +02:00
$container_name = 'coolify-proxy';
$output = instantRemoteProcess([
2023-05-12 21:06:13 +02:00
// Folder exists, in ~/projects/<folder-name>
2023-05-15 08:53:56 +02:00
'if [ -d "projects/' . $folder_name . '" ]; then echo "true"; else echo "false"; fi',
2023-05-12 21:06:13 +02:00
// Container of name <container-name> is running
2023-05-12 20:51:07 +02:00
<<<EOT
[[ "$(docker inspect -f '{{.State.Running}}' $container_name 2>/dev/null)" == "true" ]] && echo "true" || echo "false"
EOT,
2023-05-12 20:42:39 +02:00
], $server);
2023-05-12 20:51:07 +02:00
return collect(
explode(PHP_EOL, $output)
2023-05-15 08:53:56 +02:00
)->every(fn ($output) => $output === 'true');
2023-05-12 20:42:39 +02:00
}
}