[#15] 增加镜像构建 --no-cache选项

This commit is contained in:
yuyr 2025-10-13 15:17:33 +08:00
parent ee13c8d094
commit 0e96c5bcb0
2 changed files with 21 additions and 1 deletions

View File

@ -10,6 +10,7 @@ Usage: $0 [OPTIONS]
Options: Options:
--intranet Use intranet mirror for log/bind builds --intranet Use intranet mirror for log/bind builds
--master-offline Build master offline image (requires src/master/offline_wheels.tar.gz) --master-offline Build master offline image (requires src/master/offline_wheels.tar.gz)
--no-cache Build all images without using Docker layer cache
-h, --help Show this help message -h, --help Show this help message
Examples: Examples:
@ -23,6 +24,7 @@ EOF
use_intranet=false use_intranet=false
build_master=true build_master=true
build_master_offline=false build_master_offline=false
no_cache=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
@ -39,6 +41,10 @@ while [[ $# -gt 0 ]]; do
build_master_offline=true build_master_offline=true
shift shift
;; ;;
--no-cache)
no_cache=true
shift
;;
-h|--help) -h|--help)
show_help show_help
exit 0 exit 0
@ -65,6 +71,10 @@ cd "$root"
load_build_user load_build_user
build_args+=("--build-arg" "ARGUS_BUILD_UID=${ARGUS_BUILD_UID}" "--build-arg" "ARGUS_BUILD_GID=${ARGUS_BUILD_GID}") build_args+=("--build-arg" "ARGUS_BUILD_UID=${ARGUS_BUILD_UID}" "--build-arg" "ARGUS_BUILD_GID=${ARGUS_BUILD_GID}")
if [[ "$no_cache" == true ]]; then
build_args+=("--no-cache")
fi
master_root="$root/src/master" master_root="$root/src/master"
master_offline_tar="$master_root/offline_wheels.tar.gz" master_offline_tar="$master_root/offline_wheels.tar.gz"
master_offline_dir="$master_root/offline_wheels" master_offline_dir="$master_root/offline_wheels"
@ -159,6 +169,9 @@ if [[ "$build_master" == true ]]; then
if [[ "$build_master_offline" == true ]]; then if [[ "$build_master_offline" == true ]]; then
master_args+=("--offline") master_args+=("--offline")
fi fi
if [[ "$no_cache" == true ]]; then
master_args+=("--no-cache")
fi
if ./scripts/build_images.sh "${master_args[@]}"; then if ./scripts/build_images.sh "${master_args[@]}"; then
if [[ "$build_master_offline" == true ]]; then if [[ "$build_master_offline" == true ]]; then
images_built+=("argus-master:offline") images_built+=("argus-master:offline")

View File

@ -3,12 +3,13 @@ set -euo pipefail
usage() { usage() {
cat >&2 <<'USAGE' cat >&2 <<'USAGE'
Usage: $0 [--intranet] [--offline] [--tag <image_tag>] Usage: $0 [--intranet] [--offline] [--tag <image_tag>] [--no-cache]
Options: Options:
--intranet 使用指定的 PyPI 镜像源(默认清华镜像)。 --intranet 使用指定的 PyPI 镜像源(默认清华镜像)。
--offline 完全离线构建,依赖 offline_wheels/ 目录中的离线依赖包。 --offline 完全离线构建,依赖 offline_wheels/ 目录中的离线依赖包。
--tag <image_tag> 自定义镜像标签,默认 argus-master:latest。 --tag <image_tag> 自定义镜像标签,默认 argus-master:latest。
--no-cache 不使用 Docker 构建缓存。
USAGE USAGE
} }
@ -19,6 +20,7 @@ IMAGE_TAG="${IMAGE_TAG:-argus-master:latest}"
DOCKERFILE="src/master/Dockerfile" DOCKERFILE="src/master/Dockerfile"
BUILD_ARGS=() BUILD_ARGS=()
OFFLINE_MODE=0 OFFLINE_MODE=0
NO_CACHE=0
source "$PROJECT_ROOT/scripts/common/build_user.sh" source "$PROJECT_ROOT/scripts/common/build_user.sh"
load_build_user load_build_user
@ -45,6 +47,11 @@ while [[ "$#" -gt 0 ]]; do
IMAGE_TAG="$2" IMAGE_TAG="$2"
shift 2 shift 2
;; ;;
--no-cache)
NO_CACHE=1
BUILD_ARGS+=("--no-cache")
shift
;;
-h|--help) -h|--help)
usage usage
exit 0 exit 0