mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-25 17:01:49 -04:00
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.
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user