diff --git a/compose.jiangling.yml b/compose.jiangling.yml index 5d104c8b..f3d9f8ac 100644 --- a/compose.jiangling.yml +++ b/compose.jiangling.yml @@ -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" diff --git a/deploy/activate-incremental-release.sh b/deploy/activate-incremental-release.sh index adbbfdeb..1554d1fd 100644 --- a/deploy/activate-incremental-release.sh +++ b/deploy/activate-incremental-release.sh @@ -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 diff --git a/deploy/activate-release.sh b/deploy/activate-release.sh index f5ce22c7..73e690b2 100644 --- a/deploy/activate-release.sh +++ b/deploy/activate-release.sh @@ -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 diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 986b31e5..45276cf0 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -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 diff --git a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php index c67ab0ef..45b8378f 100644 --- a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php +++ b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php @@ -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); + } + } } diff --git a/tests/Unit/EcommerceFinance/BusinessDataPlacementTest.php b/tests/Unit/EcommerceFinance/BusinessDataPlacementTest.php index 8a7529dd..1caf66d1 100644 --- a/tests/Unit/EcommerceFinance/BusinessDataPlacementTest.php +++ b/tests/Unit/EcommerceFinance/BusinessDataPlacementTest.php @@ -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); + } }