From 498d9b9b2c57b1cbb3404c4f14512658d52bb6ae Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 7 Sep 2026 22:31:17 +0200 Subject: [PATCH] fix(sentinel): mount dev proxy volume for local traffic logs Use the Coolify data volume path in local env so Sentinel can read access.log instead of the production proxy path. Cover the directory and TRAFFIC_ACCESS_LOG_PATH in tests. --- app/Actions/Server/StartSentinel.php | 12 ++++++++++-- .../TrafficAnalytics/StartSentinelTrafficTest.php | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Actions/Server/StartSentinel.php b/app/Actions/Server/StartSentinel.php index f7c73523b3..edcd4a1edd 100644 --- a/app/Actions/Server/StartSentinel.php +++ b/app/Actions/Server/StartSentinel.php @@ -10,13 +10,20 @@ class StartSentinel { use AsAction; + public static function trafficLogDirectory(Server $server): string + { + return isDev() + ? '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/proxy' + : rtrim($server->proxyPath(), '/'); + } + public static function sentinelTrafficEnvironment(Server $server): array { if (! $server->isTrafficAnalyticsEnabled()) { return []; } - $logPath = rtrim($server->proxyPath(), '/').'/access.log'; + $logPath = self::trafficLogDirectory($server).'/access.log'; $settings = $server->settings; $env = [ 'TRAFFIC_ENABLED' => 'true', @@ -76,8 +83,9 @@ class StartSentinel } $dockerEnvironments = implode(' ', array_map(fn ($key, $value) => '-e '.escapeshellarg("$key=$value"), array_keys($environments), $environments)); $dockerLabels = implode(' ', array_map(fn ($key, $value) => "$key=$value", array_keys($labels), $labels)); + $trafficLogDirectory = self::trafficLogDirectory($server); $trafficMount = $server->isTrafficAnalyticsEnabled() - ? '-v '.escapeshellarg($server->proxyPath().':'.$server->proxyPath().':ro').' ' + ? '-v '.escapeshellarg("{$trafficLogDirectory}:{$trafficLogDirectory}:ro").' ' : ''; $dockerCommand = "docker run -d $dockerEnvironments --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v $mountDir:/app/db {$trafficMount}--pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-start-period 120s --health-interval 10s --health-retries 3 --add-host=host.docker.internal:host-gateway --label $dockerLabels $image"; diff --git a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php index 4e06079a6c..b8856f4c67 100644 --- a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php +++ b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php @@ -40,6 +40,18 @@ it('produces traffic + geoip env when enabled', function () { expect($env)->toHaveKey('TRAFFIC_ACCESS_LOG_PATH'); }); +it('uses the dev proxy volume for traffic logs locally', function () { + config()->set('app.env', 'local'); + $server = Server::factory()->create(['team_id' => $this->team->id]); + $server->settings->is_traffic_analytics_enabled = true; + $server->settings->save(); + + expect(StartSentinel::trafficLogDirectory($server->fresh())) + ->toBe('/var/lib/docker/volumes/coolify_dev_coolify_data/_data/proxy'); + expect(StartSentinel::sentinelTrafficEnvironment($server->fresh())['TRAFFIC_ACCESS_LOG_PATH']) + ->toBe('/var/lib/docker/volumes/coolify_dev_coolify_data/_data/proxy/access.log'); +}); + it('passes custom traffic settings as sentinel env', function () { $server = Server::factory()->create(['team_id' => $this->team->id]); $server->settings->is_traffic_analytics_enabled = true;