diff --git a/src/bind/build/Dockerfile b/src/bind/build/Dockerfile index 412a44f..916eef2 100644 --- a/src/bind/build/Dockerfile +++ b/src/bind/build/Dockerfile @@ -4,6 +4,18 @@ FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive ENV TZ=Asia/Shanghai +# 设置构建参数 +ARG USE_INTRANET=false + +# 配置内网 apt 源 (如果指定了内网选项) +RUN if [ "$USE_INTRANET" = "true" ]; then \ + echo "Configuring intranet apt sources..." && \ + cp /etc/apt/sources.list /etc/apt/sources.list.bak && \ + echo "deb [trusted=yes] http://10.68.64.1/ubuntu2204/ jammy main" > /etc/apt/sources.list && \ + echo 'Acquire::https::Verify-Peer "false";' > /etc/apt/apt.conf.d/99disable-ssl-check && \ + echo 'Acquire::https::Verify-Host "false";' >> /etc/apt/apt.conf.d/99disable-ssl-check; \ + fi + # Update package list and install required packages RUN apt-get update && \ apt-get install -y \ @@ -11,9 +23,17 @@ RUN apt-get update && \ bind9utils \ bind9-doc \ supervisor \ + net-tools \ + inetutils-ping \ + vim \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +# 配置部署时使用的apt源 +RUN if [ "$USE_INTRANET" = "true" ]; then \ + echo "deb [trusted=yes] https://10.92.132.52/mirrors/ubuntu2204/ jammy main" > /etc/apt/sources.list; \ + fi + # Create supervisor configuration directory RUN mkdir -p /etc/supervisor/conf.d diff --git a/src/bind/scripts/build_images.sh b/src/bind/scripts/build_images.sh index 97a3690..6796656 100755 --- a/src/bind/scripts/build_images.sh +++ b/src/bind/scripts/build_images.sh @@ -1,74 +1,98 @@ -#!/bin/bash +#!/usr/bin/env bash +set -euo pipefail -# Build BIND DNS container image -# Usage: ./build_images.sh [--intranet] +# 帮助信息 +show_help() { + cat << EOF +ARGUS BIND9 DNS System - Image Build Tool -set -e +Usage: $0 [OPTIONS] -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" -BUILD_DIR="$PROJECT_ROOT/build" +Options: + --intranet Use intranet mirror for Ubuntu 22.04 packages + -h, --help Show this help message -IMAGE_NAME="argus-bind9" -TAG="latest" +Examples: + $0 # Build with default sources + $0 --intranet # Build with intranet mirror + +EOF +} + +# 解析命令行参数 +use_intranet=false -# Parse command line arguments -USE_INTRANET=false while [[ $# -gt 0 ]]; do case $1 in --intranet) - USE_INTRANET=true + use_intranet=true shift ;; + -h|--help) + show_help + exit 0 + ;; *) echo "Unknown option: $1" - echo "Usage: $0 [--intranet]" + show_help exit 1 ;; esac done -echo "Building BIND9 DNS container image..." -echo "Image: $IMAGE_NAME:$TAG" -echo "Build directory: $BUILD_DIR" +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$root" -# Check if build directory exists -if [ ! -d "$BUILD_DIR" ]; then - echo "Error: Build directory not found: $BUILD_DIR" - exit 1 +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 -# Check if Dockerfile exists -if [ ! -f "$BUILD_DIR/Dockerfile" ]; then - echo "Error: Dockerfile not found: $BUILD_DIR/Dockerfile" - exit 1 -fi +echo "" -cd "$BUILD_DIR" +# 构建 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 apt source (10.68.64.1)..." - - # Create temporary Dockerfile with intranet apt source - cp Dockerfile Dockerfile.tmp - - # Insert intranet apt configuration after the FROM line - sed -i '/^FROM ubuntu:22.04/a\\n# Configure intranet apt source\nRUN echo "deb [trusted=yes] http://10.68.64.1/ubuntu2204/ jammy main" > /etc/apt/sources.list && \\\n mkdir -p /etc/apt/apt.conf.d && \\\n echo "Acquire::https::Verify-Peer \"false\";" > /etc/apt/apt.conf.d/99-disable-ssl-verify && \\\n echo "Acquire::https::Verify-Host \"false\";" >> /etc/apt/apt.conf.d/99-disable-ssl-verify' Dockerfile.tmp - - # Build with modified Dockerfile - docker build -f Dockerfile.tmp -t "$IMAGE_NAME:$TAG" . - - # Clean up temporary file - rm -f Dockerfile.tmp +if [[ "$use_intranet" == true ]]; then + echo "Building with intranet mirror sources..." else echo "Building with default public apt sources..." - docker build -t "$IMAGE_NAME:$TAG" . fi -echo "Build completed successfully!" -echo "Image: $IMAGE_NAME:$TAG" +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 -# Show image info echo "" echo "Image details:" -docker images "$IMAGE_NAME:$TAG" \ No newline at end of file +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 "" \ No newline at end of file