test: harden clickhouse deployment guardrails

This commit is contained in:
WuYongJie 2026-09-07 11:28:22 +08:00
parent 50683ca44c
commit 1d70e7bfd7
6 changed files with 88 additions and 0 deletions

View File

@ -65,6 +65,15 @@ services:
- caiwu_clickhouse_logs:/var/log/clickhouse-server
mem_limit: 4g
cpus: "2.00"
ulimits:
nofile:
soft: 262144
hard: 262144
logging:
driver: json-file
options:
max-size: "20m"
max-file: "5"
healthcheck:
test:
- "CMD-SHELL"

View File

@ -114,6 +114,25 @@ fi
docker compose -f compose.jiangling.yml up -d --remove-orphans
clickhouse_healthy=0
clickhouse_attempt=1
while [ "$clickhouse_attempt" -le 24 ]; do
if [ "$(docker inspect caiwu_clickhouse --format '{{.State.Health.Status}}' 2>/dev/null || true)" = "healthy" ]; then
clickhouse_healthy=1
break
fi
sleep 5
clickhouse_attempt=$((clickhouse_attempt + 1))
done
if [ "$clickhouse_healthy" -ne 1 ]; then
docker compose -f compose.jiangling.yml logs --tail 120 clickhouse >&2 || true
restore_previous_image
echo "ClickHouse did not become healthy; previous application image was restored when available" >&2
exit 1
fi
healthy=0
attempt=1
while [ "$attempt" -le 30 ]; do

View File

@ -118,6 +118,25 @@ fi
docker compose -f compose.jiangling.yml up -d --remove-orphans
clickhouse_healthy=0
clickhouse_attempt=1
while [ "$clickhouse_attempt" -le 24 ]; do
if [ "$(docker inspect caiwu_clickhouse --format '{{.State.Health.Status}}' 2>/dev/null || true)" = "healthy" ]; then
clickhouse_healthy=1
break
fi
sleep 5
clickhouse_attempt=$((clickhouse_attempt + 1))
done
if [ "$clickhouse_healthy" -ne 1 ]; then
docker compose -f compose.jiangling.yml logs --tail 120 clickhouse >&2 || true
restore_previous_image
echo "ClickHouse did not become healthy; previous application image was restored when available" >&2
exit 1
fi
healthy=0
attempt=1
while [ "$attempt" -le 30 ]; do

View File

@ -90,6 +90,10 @@ services:
- jiangling_clickhouse:/var/lib/clickhouse
networks:
- jiangling_net
ulimits:
nofile:
soft: 262144
hard: 262144
healthcheck:
test: ["CMD-SHELL", "clickhouse-client --user \"$$CLICKHOUSE_USER\" --password \"$$CLICKHOUSE_PASSWORD\" --query 'SELECT 1' >/dev/null"]
interval: 10s

View File

@ -51,4 +51,28 @@ class BusinessMirrorScheduleTest extends TestCase
$this->assertStringNotContainsString("['stat_date', 'push_fee', 'item_id']", $contents);
$this->assertStringContainsString("['stat_date', 'push_fee']", $contents);
}
public function test_clickhouse_is_internal_resource_bounded_and_uses_private_runtime_credentials(): void
{
$root = dirname(__DIR__, 3);
$compose = file_get_contents($root . '/compose.jiangling.yml');
$start = strpos($compose, " clickhouse:\n");
$end = strpos($compose, " app:\n", $start);
$service = substr($compose, $start, $end - $start);
$this->assertStringContainsString('clickhouse/clickhouse-server:26.8.2.7-alpine', $service);
$this->assertStringContainsString('mem_limit: 4g', $service);
$this->assertStringContainsString('cpus: "2.00"', $service);
$this->assertStringContainsString('max-size: "20m"', $service);
$this->assertStringNotContainsString('ports:', $service);
$this->assertStringContainsString('./runtime/clickhouse.env', $compose);
foreach (['activate-release.sh', 'activate-incremental-release.sh'] as $script) {
$contents = file_get_contents($root . '/deploy/' . $script);
$this->assertStringContainsString('openssl rand -hex 24', $contents, $script);
$this->assertStringContainsString('chmod 600 "$clickhouse_env"', $contents, $script);
$this->assertStringContainsString('docker inspect caiwu_clickhouse', $contents, $script);
$this->assertStringContainsString('ClickHouse did not become healthy', $contents, $script);
}
}
}

View File

@ -69,4 +69,17 @@ class BusinessDataPlacementTest extends TestCase
$this->assertSame('mariadb', $policy['target_store']);
$this->assertSame('always', $policy['sync']);
}
public function test_every_fixed_upstream_dataset_has_exactly_one_storage_policy(): void
{
$upstream = require base_path('config/upstream_mirrors.php');
$businessData = require base_path('config/business_data.php');
$this->assertCount(51, $upstream['datasets']);
$upstreamKeys = array_keys($upstream['datasets']);
$policyKeys = array_keys($businessData['datasets']);
sort($upstreamKeys);
sort($policyKeys);
$this->assertSame($upstreamKeys, $policyKeys);
}
}