dev_1.0.0_yuyr_2:重新提交 PR,增加 master/agent 以及系统集成测试 (#17)
Reviewed-on: #17 Reviewed-by: sundapeng <sundp@mail.zgclab.edu.cn> Reviewed-by: xuxt <xuxt@zgclab.edu.cn>
This commit was merged in pull request #17.
This commit is contained in:
@@ -6,6 +6,11 @@ ENV TZ=Asia/Shanghai
|
||||
|
||||
# 设置构建参数
|
||||
ARG USE_INTRANET=false
|
||||
ARG ARGUS_BUILD_UID=2133
|
||||
ARG ARGUS_BUILD_GID=2015
|
||||
|
||||
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \
|
||||
ARGUS_BUILD_GID=${ARGUS_BUILD_GID}
|
||||
|
||||
# 配置内网 apt 源 (如果指定了内网选项)
|
||||
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||
@@ -29,6 +34,24 @@ RUN apt-get update && \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 调整 bind 用户与用户组 ID 以匹配宿主机配置
|
||||
RUN set -eux; \
|
||||
current_gid="$(getent group bind | awk -F: '{print $3}')"; \
|
||||
if [ -z "$current_gid" ]; then \
|
||||
groupadd -g "${ARGUS_BUILD_GID}" bind; \
|
||||
elif [ "$current_gid" != "${ARGUS_BUILD_GID}" ]; then \
|
||||
groupmod -g "${ARGUS_BUILD_GID}" bind; \
|
||||
fi; \
|
||||
if id bind >/dev/null 2>&1; then \
|
||||
current_uid="$(id -u bind)"; \
|
||||
if [ "$current_uid" != "${ARGUS_BUILD_UID}" ]; then \
|
||||
usermod -u "${ARGUS_BUILD_UID}" bind; \
|
||||
fi; \
|
||||
else \
|
||||
useradd -m -u "${ARGUS_BUILD_UID}" -g "${ARGUS_BUILD_GID}" bind; \
|
||||
fi; \
|
||||
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" /var/cache/bind /var/lib/bind
|
||||
|
||||
# 配置部署时使用的apt源
|
||||
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||
echo "deb [trusted=yes] https://10.92.132.52/mirrors/ubuntu2204/ jammy main" > /etc/apt/sources.list; \
|
||||
|
||||
@@ -9,6 +9,9 @@ SLEEP_SECONDS=10
|
||||
RELOAD_SCRIPT="/usr/local/bin/reload-bind9.sh" # 这里放你已有脚本的路径
|
||||
|
||||
mkdir -p "$(dirname "$LOCKFILE")" "$BACKUP_DIR"
|
||||
BACKUP_UID="${ARGUS_BUILD_UID:-2133}"
|
||||
BACKUP_GID="${ARGUS_BUILD_GID:-2015}"
|
||||
chown -R "$BACKUP_UID:$BACKUP_GID" "$BACKUP_DIR" 2>/dev/null || true
|
||||
|
||||
is_ipv4() {
|
||||
local ip="$1"
|
||||
@@ -33,6 +36,7 @@ upsert_record() {
|
||||
local changed=0
|
||||
|
||||
cp -a "$ZONE_DB" "$BACKUP_DIR/db.argus.com.$ts.bak"
|
||||
chown "$BACKUP_UID:$BACKUP_GID" "$BACKUP_DIR/db.argus.com.$ts.bak" 2>/dev/null || true
|
||||
|
||||
local cur_ip
|
||||
cur_ip="$(get_current_ip "$name" || true)"
|
||||
@@ -61,7 +65,10 @@ upsert_record() {
|
||||
echo "[SKIP] ${name} unchanged (${new_ip})"
|
||||
fi
|
||||
|
||||
return $changed
|
||||
if [[ $changed -eq 1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
while true; do
|
||||
@@ -70,7 +77,7 @@ while true; do
|
||||
shopt -s nullglob
|
||||
NEED_RELOAD=0
|
||||
|
||||
for f in "$WATCH_DIR"/*.argus.com; do
|
||||
for f in "$WATCH_DIR"/*.argus.com; do
|
||||
base="$(basename "$f")"
|
||||
name="${base%.argus.com}"
|
||||
ip="$(grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' "$f" | tail -n1 || true)"
|
||||
@@ -97,4 +104,3 @@ while true; do
|
||||
|
||||
sleep "$SLEEP_SECONDS"
|
||||
done
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ chmod 777 /private 2>/dev/null || true
|
||||
# Create persistent directories for BIND9 configs and DNS sync
|
||||
mkdir -p /private/argus/bind
|
||||
mkdir -p /private/argus/etc
|
||||
chown bind:bind /private/argus 2>/dev/null || true
|
||||
chown -R bind:bind /private/argus/bind /private/argus/etc
|
||||
|
||||
# Copy configuration files to persistent storage if they don't exist
|
||||
if [ ! -f /private/argus/bind/named.conf.local ]; then
|
||||
|
||||
@@ -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
|
||||
driver: bridge
|
||||
|
||||
@@ -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
|
||||
fi
|
||||
|
||||
@@ -7,13 +7,17 @@ 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"
|
||||
|
||||
echo "Starting BIND9 test container..."
|
||||
|
||||
# Ensure private directory exists with proper permissions
|
||||
mkdir -p private
|
||||
mkdir -p private/argus/bind
|
||||
mkdir -p private/argus/etc
|
||||
chmod 777 private
|
||||
|
||||
# Start the container
|
||||
@@ -35,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}"
|
||||
|
||||
@@ -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
|
||||
fi
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
echo "✓ Configuration persisted and reloaded correctly"
|
||||
|
||||
@@ -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"
|
||||
echo "✓ DNS resolution working correctly with persisted configuration"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user