Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(sentinel): mount dev proxy volume for local traffic logs

Andras Bacsai498d9b9b2c57
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;