sentinel updates

This commit is contained in:
Andras Bacsai
2024-10-15 13:39:19 +02:00
parent 81db57002b
commit d446cd4f31
19 changed files with 293 additions and 145 deletions

View File

@@ -17,39 +17,46 @@ class StartSentinel
}
$metrics_history = $server->settings->sentinel_metrics_history_days;
$refresh_rate = $server->settings->sentinel_metrics_refresh_rate_seconds;
$push_interval = $server->settings->sentinel_push_interval_seconds;
$token = $server->settings->sentinel_token;
$endpoint = InstanceSettings::get()->fqdn;
if (isDev()) {
$mount_dir = '/data/coolify/sentinel';
$image = "ghcr.io/coollabsio/sentinel:$version";
if ($server->isLocalhost()) {
$endpoint = 'http://host.docker.internal:8000';
} else {
if (! $endpoint) {
throw new \Exception('You should set FQDN in Instance Settings.');
}
}
if (! $endpoint) {
throw new \Exception('You should set FQDN in Instance Settings.');
}
// Ensure the endpoint is using HTTPS
$endpoint = str($endpoint)->replace('http://', 'https://')->value();
$environments = [
'TOKEN' => $token,
'ENDPOINT' => $endpoint,
'COLLECTOR_ENABLED' => 'true',
'PUSH_ENDPOINT' => $endpoint,
'PUSH_INTERVAL_SECONDS' => $push_interval,
'COLLECTOR_ENABLED' => $server->isMetricsEnabled() ? 'true' : 'false',
'COLLECTOR_REFRESH_RATE_SECONDS' => $refresh_rate,
'COLLECTOR_RETENTION_PERIOD_DAYS' => $metrics_history,
];
if (isDev()) {
data_set($environments, 'GIN_MODE', 'debug');
}
$mount_dir = '/data/coolify/sentinel';
if (isDev()) {
data_set($environments, 'DEBUG', 'true');
$mount_dir = '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/sentinel';
$image = 'sentinel';
}
$docker_environments = '-e "'.implode('" -e "', array_map(fn ($key, $value) => "$key=$value", array_keys($environments), $environments)).'"';
$docker_command = "docker run --pull always --rm -d $docker_environments --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v $mount_dir:/app/db --pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-interval 10s --health-retries 3 --add-host=host.docker.internal:host-gateway ghcr.io/coollabsio/sentinel:$version";
$docker_environments = '-e "' . implode('" -e "', array_map(fn($key, $value) => "$key=$value", array_keys($environments), $environments)) . '"';
return instant_remote_process([
$docker_command = "docker run -d $docker_environments --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v $mount_dir:/app/db --pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-interval 10s --health-retries 3 --add-host=host.docker.internal:host-gateway $image";
instant_remote_process([
'docker rm -f coolify-sentinel || true',
"mkdir -p $mount_dir",
$docker_command,
"chown -R 9999:root $mount_dir",
"chmod -R 700 $mount_dir",
], $server, true);
], $server);
$server->settings->is_sentinel_enabled = true;
$server->settings->save();
$server->sentinelUpdateAt();
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Actions\Server;
use App\Models\Server;
use Carbon\Carbon;
use Lorisleiva\Actions\Concerns\AsAction;
class StopSentinel
@@ -12,5 +13,6 @@ class StopSentinel
public function handle(Server $server)
{
instant_remote_process(['docker rm -f coolify-sentinel'], $server, false);
$server->sentinelUpdateAt(isReset: true);
}
}