[#7] 根目录统一构建镜像入口脚本
This commit is contained in:
@@ -38,19 +38,20 @@ RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
|
||||
# Copy supervisor configuration
|
||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY src/bind/build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Copy BIND9 configuration files
|
||||
COPY named.conf.local /etc/bind/named.conf.local
|
||||
COPY db.argus.com /etc/bind/db.argus.com
|
||||
COPY src/bind/build/named.conf.local /etc/bind/named.conf.local
|
||||
COPY src/bind/build/db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
# Copy startup and reload scripts
|
||||
COPY startup.sh /usr/local/bin/startup.sh
|
||||
COPY reload-bind9.sh /usr/local/bin/reload-bind9.sh
|
||||
COPY argus_dns_sync.sh /usr/local/bin/argus_dns_sync.sh
|
||||
COPY src/bind/build/startup.sh /usr/local/bin/startup.sh
|
||||
COPY src/bind/build/reload-bind9.sh /usr/local/bin/reload-bind9.sh
|
||||
COPY src/bind/build/argus_dns_sync.sh /usr/local/bin/argus_dns_sync.sh
|
||||
COPY src/bind/build/update-dns.sh /usr/local/bin/update-dns.sh
|
||||
|
||||
# Make scripts executable
|
||||
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/reload-bind9.sh /usr/local/bin/argus_dns_sync.sh
|
||||
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/reload-bind9.sh /usr/local/bin/argus_dns_sync.sh /usr/local/bin/update-dns.sh
|
||||
|
||||
# Set proper ownership for BIND9 files
|
||||
RUN chown bind:bind /etc/bind/named.conf.local /etc/bind/db.argus.com
|
||||
|
||||
68
src/bind/build/dns-monitor.sh
Normal file
68
src/bind/build/dns-monitor.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# DNS监控脚本 - 每10秒检查dns.conf是否有变化
|
||||
# 如果有变化则执行update-dns.sh脚本
|
||||
|
||||
DNS_CONF="/private/argus/etc/dns.conf"
|
||||
DNS_BACKUP="/tmp/dns.conf.backup"
|
||||
UPDATE_SCRIPT="/private/argus/etc/update-dns.sh"
|
||||
LOG_FILE="/var/log/supervisor/dns-monitor.log"
|
||||
|
||||
# 确保日志文件存在
|
||||
touch "$LOG_FILE"
|
||||
|
||||
log_message() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') [DNS-Monitor] $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
log_message "DNS监控脚本启动"
|
||||
|
||||
while true; do
|
||||
if [ -f "$DNS_CONF" ]; then
|
||||
if [ -f "$DNS_BACKUP" ]; then
|
||||
# 比较文件内容
|
||||
if ! cmp -s "$DNS_CONF" "$DNS_BACKUP"; then
|
||||
log_message "检测到DNS配置变化"
|
||||
|
||||
# 更新备份文件
|
||||
cp "$DNS_CONF" "$DNS_BACKUP"
|
||||
|
||||
# 执行更新脚本
|
||||
if [ -x "$UPDATE_SCRIPT" ]; then
|
||||
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
|
||||
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "DNS更新脚本执行成功"
|
||||
else
|
||||
log_message "DNS更新脚本执行失败"
|
||||
fi
|
||||
else
|
||||
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
||||
# 第一次检测到配置文件,执行更新脚本
|
||||
if [ -x "$UPDATE_SCRIPT" ]; then
|
||||
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
|
||||
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "DNS更新脚本执行成功"
|
||||
|
||||
# 第一次运行,创建备份并执行更新
|
||||
cp "$DNS_CONF" "$DNS_BACKUP"
|
||||
log_message "创建DNS配置备份文件"
|
||||
|
||||
else
|
||||
log_message "DNS更新脚本执行失败"
|
||||
fi
|
||||
else
|
||||
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_message "警告: DNS配置文件不存在: $DNS_CONF"
|
||||
fi
|
||||
|
||||
sleep 10
|
||||
done
|
||||
@@ -16,6 +16,11 @@ if [ ! -f /private/argus/bind/db.argus.com ]; then
|
||||
cp /etc/bind/db.argus.com /private/argus/bind/db.argus.com
|
||||
fi
|
||||
|
||||
# Copy update-dns.sh to /private/argus/etc/
|
||||
cp /usr/local/bin/update-dns.sh /private/argus/etc/update-dns.sh
|
||||
chown bind:bind /private/argus/etc/update-dns.sh
|
||||
chmod a+x /private/argus/etc/update-dns.sh
|
||||
|
||||
# Create symlinks to use persistent configs
|
||||
ln -sf /private/argus/bind/named.conf.local /etc/bind/named.conf.local
|
||||
ln -sf /private/argus/bind/db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# 帮助信息
|
||||
show_help() {
|
||||
cat << EOF
|
||||
ARGUS BIND9 DNS System - Image Build Tool
|
||||
|
||||
Usage: $0 [OPTIONS]
|
||||
|
||||
Options:
|
||||
--intranet Use intranet mirror for Ubuntu 22.04 packages
|
||||
-h, --help Show this help message
|
||||
|
||||
Examples:
|
||||
$0 # Build with default sources
|
||||
$0 --intranet # Build with intranet mirror
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# 解析命令行参数
|
||||
use_intranet=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--intranet)
|
||||
use_intranet=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$root"
|
||||
|
||||
echo "======================================="
|
||||
echo "ARGUS BIND9 DNS System - Image Build Tool"
|
||||
echo "======================================="
|
||||
|
||||
if [[ "$use_intranet" == true ]]; then
|
||||
echo "🌐 Mode: Intranet (Using internal mirror: 10.68.64.1)"
|
||||
build_args="--build-arg USE_INTRANET=true"
|
||||
else
|
||||
echo "🌐 Mode: Public (Using default package sources)"
|
||||
build_args=""
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# 构建 BIND9 镜像
|
||||
echo "🔄 Building BIND9 DNS container image..."
|
||||
echo "Image: argus-bind9:latest"
|
||||
echo "Build directory: $root/build"
|
||||
|
||||
if [[ "$use_intranet" == true ]]; then
|
||||
echo "Building with intranet mirror sources..."
|
||||
else
|
||||
echo "Building with default public apt sources..."
|
||||
fi
|
||||
|
||||
if docker build $build_args -t argus-bind9:latest ./build; then
|
||||
echo "✅ Build completed successfully!"
|
||||
else
|
||||
echo "❌ Failed to build BIND9 image"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "======================================="
|
||||
echo "📦 Build Summary"
|
||||
echo "======================================="
|
||||
echo "✅ Successfully built image:"
|
||||
echo " • argus-bind9:latest"
|
||||
|
||||
if [[ "$use_intranet" == true ]]; then
|
||||
echo ""
|
||||
echo "🌐 Built with intranet mirror configuration"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Image details:"
|
||||
docker images argus-bind9:latest
|
||||
|
||||
echo ""
|
||||
echo "🚀 Next steps:"
|
||||
echo " ./scripts/save_images.sh # Export images"
|
||||
echo " cd tests && ./scripts/00_e2e_test.sh # Run tests"
|
||||
echo ""
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Save BIND DNS container images to tar files
|
||||
# Usage: ./save_images.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
IMAGES_DIR="$PROJECT_ROOT/images"
|
||||
|
||||
IMAGE_NAME="argus-bind9"
|
||||
TAG="latest"
|
||||
|
||||
echo "Saving BIND9 DNS container images..."
|
||||
|
||||
# Create images directory if it doesn't exist
|
||||
mkdir -p "$IMAGES_DIR"
|
||||
|
||||
# Check if image exists
|
||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^$IMAGE_NAME:$TAG$"; then
|
||||
echo "Error: Image $IMAGE_NAME:$TAG not found"
|
||||
echo "Please build the image first using: ./build_images.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Save the image
|
||||
echo "Saving $IMAGE_NAME:$TAG to $IMAGES_DIR/argus-bind9.tar..."
|
||||
docker save "$IMAGE_NAME:$TAG" -o "$IMAGES_DIR/argus-bind9.tar"
|
||||
|
||||
# Compress the tar file to save space
|
||||
echo "Compressing image archive..."
|
||||
gzip -f "$IMAGES_DIR/argus-bind9.tar"
|
||||
|
||||
echo "Image saved successfully!"
|
||||
echo "Location: $IMAGES_DIR/argus-bind9.tar.gz"
|
||||
|
||||
# Show file size
|
||||
if [ -f "$IMAGES_DIR/argus-bind9.tar.gz" ]; then
|
||||
echo "File size: $(du -h "$IMAGES_DIR/argus-bind9.tar.gz" | cut -f1)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To load the image later, use:"
|
||||
echo " gunzip $IMAGES_DIR/argus-bind9.tar.gz"
|
||||
echo " docker load -i $IMAGES_DIR/argus-bind9.tar"
|
||||
Reference in New Issue
Block a user