From 035ab44078d710605d29632122936ecbbb0e45b0 Mon Sep 17 00:00:00 2001 From: yuyr Date: Sun, 28 Sep 2025 07:51:03 +0000 Subject: [PATCH] =?UTF-8?q?[#7]=20bind=E7=AB=AF=E5=88=B0=E7=AB=AF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BD=BF=E7=94=A8=E6=8C=87=E5=AE=9A=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ src/bind/tests/docker-compose.yml | 6 +++--- src/bind/tests/scripts/00_e2e_test.sh | 5 ++++- src/bind/tests/scripts/01_start_container.sh | 5 ++++- src/bind/tests/scripts/02_dig_test.sh | 7 +++++-- src/bind/tests/scripts/03.5_dns_sync_test.sh | 9 ++++++--- src/bind/tests/scripts/03_reload_test.sh | 7 +++++-- src/bind/tests/scripts/04_persistence_test.sh | 7 +++++-- src/bind/tests/scripts/05_cleanup.sh | 3 +++ 9 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 253aded..b4796ee 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,10 @@ 项目文档:【腾讯文档】GPU集群运维系统 https://docs.qq.com/doc/DQUxDdmhIZ1dpeERk +## 构建账号配置 + +镜像构建和运行账号的 UID/GID 可通过 `configs/build_user.conf` 配置,详细说明见 `doc/build-user-config.md`。 + +## 本地端口占用提示 + +如需运行 BIND 模块端到端测试且宿主机 53 端口已占用,可通过环境变量 `HOST_DNS_PORT`(默认 1053)指定对外映射端口,例如 `HOST_DNS_PORT=12053 ./scripts/00_e2e_test.sh`。 diff --git a/src/bind/tests/docker-compose.yml b/src/bind/tests/docker-compose.yml index e2d4fc9..b01d33d 100644 --- a/src/bind/tests/docker-compose.yml +++ b/src/bind/tests/docker-compose.yml @@ -3,8 +3,8 @@ services: image: argus-bind9:latest container_name: argus-bind9-test ports: - - "53:53/tcp" - - "53:53/udp" + - "${HOST_DNS_PORT:-1053}:53/tcp" + - "${HOST_DNS_PORT:-1053}:53/udp" volumes: - ./private:/private restart: unless-stopped @@ -13,4 +13,4 @@ services: networks: bind-test-network: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/src/bind/tests/scripts/00_e2e_test.sh b/src/bind/tests/scripts/00_e2e_test.sh index 3a8a78a..6aa92b1 100755 --- a/src/bind/tests/scripts/00_e2e_test.sh +++ b/src/bind/tests/scripts/00_e2e_test.sh @@ -7,6 +7,9 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + +export HOST_DNS_PORT echo "==========================================" echo "BIND9 DNS Server End-to-End Test Suite" @@ -112,4 +115,4 @@ else echo " - Review BIND9 configuration files" echo " - Check system resources and port availability" exit 1 -fi \ No newline at end of file +fi diff --git a/src/bind/tests/scripts/01_start_container.sh b/src/bind/tests/scripts/01_start_container.sh index 210be89..407a88c 100755 --- a/src/bind/tests/scripts/01_start_container.sh +++ b/src/bind/tests/scripts/01_start_container.sh @@ -7,6 +7,9 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_DIR="$(dirname "$SCRIPT_DIR")" +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + +export HOST_DNS_PORT cd "$TEST_DIR" @@ -36,4 +39,4 @@ fi echo "" echo "BIND9 test environment is ready!" -echo "DNS server listening on localhost:53" +echo "DNS server listening on localhost:${HOST_DNS_PORT}" diff --git a/src/bind/tests/scripts/02_dig_test.sh b/src/bind/tests/scripts/02_dig_test.sh index 5ea31ad..65c91df 100755 --- a/src/bind/tests/scripts/02_dig_test.sh +++ b/src/bind/tests/scripts/02_dig_test.sh @@ -5,7 +5,10 @@ set -e +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + echo "Testing DNS resolution with dig..." +echo "Using DNS server localhost:${HOST_DNS_PORT}" # Function to test DNS query test_dns_query() { @@ -19,7 +22,7 @@ test_dns_query() { echo "Expected IP: $expected_ip" # Perform dig query - result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED") + result=$(dig @localhost -p "$HOST_DNS_PORT" "$hostname".argus.com A +short 2>/dev/null || echo "QUERY_FAILED") if [ "$result" = "QUERY_FAILED" ]; then echo "✗ DNS query failed" @@ -69,4 +72,4 @@ if [ $failed_tests -eq 0 ]; then else echo "✗ $failed_tests test(s) failed" exit 1 -fi \ No newline at end of file +fi diff --git a/src/bind/tests/scripts/03.5_dns_sync_test.sh b/src/bind/tests/scripts/03.5_dns_sync_test.sh index 6e872bc..9a164c9 100755 --- a/src/bind/tests/scripts/03.5_dns_sync_test.sh +++ b/src/bind/tests/scripts/03.5_dns_sync_test.sh @@ -6,10 +6,13 @@ set -e +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_DIR="$(dirname "$SCRIPT_DIR")" echo "=== DNS Auto-Sync Functionality Test ===" +echo "Using DNS server localhost:${HOST_DNS_PORT}" # Check if container is running if ! docker compose ps | grep -q "Up"; then @@ -36,7 +39,7 @@ test_dns_query() { # Wait a moment for DNS cache sleep 2 - result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED") + result=$(dig @localhost -p "$HOST_DNS_PORT" "$hostname".argus.com A +short 2>/dev/null || echo "QUERY_FAILED") if [ "$result" = "$expected_ip" ]; then echo "✓ $result" @@ -90,7 +93,7 @@ echo "" echo "Step 2: Testing initial DNS configuration..." # Get current IP for web.argus.com (may have been changed by previous tests) -current_web_ip=$(dig @localhost web.argus.com A +short 2>/dev/null || echo "UNKNOWN") +current_web_ip=$(dig @localhost -p "$HOST_DNS_PORT" web.argus.com A +short 2>/dev/null || echo "UNKNOWN") echo "Current web.argus.com IP: $current_web_ip" # Test that DNS is working (regardless of specific IP) @@ -185,7 +188,7 @@ docker compose exec bind9 bash -c 'echo "this is not an IP address" > /private/a wait_for_sync # Verify invalid record was not added (should fail to resolve) -result=$(dig @localhost invalid.argus.com A +short 2>/dev/null || echo "NO_RESULT") +result=$(dig @localhost -p "$HOST_DNS_PORT" invalid.argus.com A +short 2>/dev/null || echo "NO_RESULT") if [ "$result" = "NO_RESULT" ] || [ -z "$result" ]; then echo "✓ Invalid IP correctly ignored" else diff --git a/src/bind/tests/scripts/03_reload_test.sh b/src/bind/tests/scripts/03_reload_test.sh index 3dac886..e023a4b 100755 --- a/src/bind/tests/scripts/03_reload_test.sh +++ b/src/bind/tests/scripts/03_reload_test.sh @@ -5,10 +5,13 @@ set -e +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_DIR="$(dirname "$SCRIPT_DIR")" echo "=== DNS Configuration Reload Test ===" +echo "Using DNS server localhost:${HOST_DNS_PORT}" # Check if container is running if ! docker compose ps | grep -q "Up"; then @@ -32,7 +35,7 @@ test_dns_query() { echo "Testing: $description" echo "Query: $hostname.argus.com -> Expected: $expected_ip" - result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED") + result=$(dig @localhost -p "$HOST_DNS_PORT" "$hostname".argus.com A +short 2>/dev/null || echo "QUERY_FAILED") if [ "$result" = "$expected_ip" ]; then echo "✓ $result" @@ -109,4 +112,4 @@ fi echo "" echo "✓ DNS configuration reload test completed successfully!" echo "✓ IP address changed from 12.4.5.6 to 192.168.1.100" -echo "✓ Configuration persisted and reloaded correctly" \ No newline at end of file +echo "✓ Configuration persisted and reloaded correctly" diff --git a/src/bind/tests/scripts/04_persistence_test.sh b/src/bind/tests/scripts/04_persistence_test.sh index 46db1eb..e3ccb21 100755 --- a/src/bind/tests/scripts/04_persistence_test.sh +++ b/src/bind/tests/scripts/04_persistence_test.sh @@ -5,10 +5,13 @@ set -e +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_DIR="$(dirname "$SCRIPT_DIR")" echo "=== Configuration Persistence Test ===" +echo "Using DNS server localhost:${HOST_DNS_PORT}" # Check if dig is available if ! command -v dig &> /dev/null; then @@ -25,7 +28,7 @@ test_dns_query() { echo "Testing: $description" echo "Query: $hostname.argus.com -> Expected: $expected_ip" - result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED") + result=$(dig @localhost -p "$HOST_DNS_PORT" "$hostname".argus.com A +short 2>/dev/null || echo "QUERY_FAILED") if [ "$result" = "$expected_ip" ]; then echo "✓ $result" @@ -112,4 +115,4 @@ echo "" echo "✓ Configuration persistence test completed successfully!" echo "✓ Modified IP (192.168.1.100) persisted after container restart" echo "✓ Configuration files properly linked to persistent storage" -echo "✓ DNS resolution working correctly with persisted configuration" \ No newline at end of file +echo "✓ DNS resolution working correctly with persisted configuration" diff --git a/src/bind/tests/scripts/05_cleanup.sh b/src/bind/tests/scripts/05_cleanup.sh index 2ee0884..45e8cdb 100755 --- a/src/bind/tests/scripts/05_cleanup.sh +++ b/src/bind/tests/scripts/05_cleanup.sh @@ -7,6 +7,9 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_DIR="$(dirname "$SCRIPT_DIR")" +HOST_DNS_PORT="${HOST_DNS_PORT:-1053}" + +export HOST_DNS_PORT # Parse command line arguments FULL_CLEANUP=true