完成a6000测试系统构建、部署、测试整合 #35
@ -122,14 +122,22 @@ build_image() {
|
|||||||
local image_name=$1
|
local image_name=$1
|
||||||
local dockerfile_path=$2
|
local dockerfile_path=$2
|
||||||
local tag=$3
|
local tag=$3
|
||||||
|
local context="."
|
||||||
shift 3
|
shift 3
|
||||||
|
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
context=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
local extra_args=("$@")
|
local extra_args=("$@")
|
||||||
|
|
||||||
echo "🔄 Building $image_name image..."
|
echo "🔄 Building $image_name image..."
|
||||||
echo " Dockerfile: $dockerfile_path"
|
echo " Dockerfile: $dockerfile_path"
|
||||||
echo " Tag: $tag"
|
echo " Tag: $tag"
|
||||||
|
echo " Context: $context"
|
||||||
|
|
||||||
if docker build "${build_args[@]}" "${extra_args[@]}" -f "$dockerfile_path" -t "$tag" .; then
|
if docker build "${build_args[@]}" "${extra_args[@]}" -f "$dockerfile_path" -t "$tag" "$context"; then
|
||||||
echo "✅ $image_name image built successfully"
|
echo "✅ $image_name image built successfully"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -138,6 +146,28 @@ build_image() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pull_base_image() {
|
||||||
|
local image_ref=$1
|
||||||
|
local attempts=${2:-3}
|
||||||
|
local delay=${3:-5}
|
||||||
|
|
||||||
|
for ((i=1; i<=attempts; i++)); do
|
||||||
|
echo " Pulling base image ($i/$attempts): $image_ref"
|
||||||
|
if docker pull "$image_ref" >/dev/null; then
|
||||||
|
echo " Base image ready: $image_ref"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo " Pull failed: $image_ref"
|
||||||
|
if (( i < attempts )); then
|
||||||
|
echo " Retrying in ${delay}s..."
|
||||||
|
sleep "$delay"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "❌ Unable to pull base image after ${attempts} attempts: $image_ref"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
images_built=()
|
images_built=()
|
||||||
build_failed=false
|
build_failed=false
|
||||||
|
|
||||||
@ -194,28 +224,34 @@ fi
|
|||||||
if [[ "$build_metric" == true ]]; then
|
if [[ "$build_metric" == true ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Building Metric module images..."
|
echo "Building Metric module images..."
|
||||||
metric_root="$root/src/metric"
|
|
||||||
pushd "$metric_root/tests" >/dev/null
|
|
||||||
|
|
||||||
# 检查docker-compose.yml是否存在
|
metric_base_images=(
|
||||||
if [[ ! -f "docker-compose.yml" ]]; then
|
"ubuntu:22.04"
|
||||||
echo "docker-compose.yml not found in $metric_root/tests" >&2
|
"ubuntu/prometheus:3-24.04_stable"
|
||||||
build_failed=true
|
"grafana/grafana:11.1.0"
|
||||||
else
|
)
|
||||||
# 构建metric镜像
|
|
||||||
if docker compose build --no-cache; then
|
for base_image in "${metric_base_images[@]}"; do
|
||||||
images_built+=("argus-metric-ftp:latest")
|
if ! pull_base_image "$base_image"; then
|
||||||
images_built+=("argus-metric-prometheus:latest")
|
|
||||||
images_built+=("argus-metric-grafana:latest")
|
|
||||||
images_built+=("argus-metric-test-node:latest")
|
|
||||||
images_built+=("argus-metric-test-gpu-node:latest")
|
|
||||||
else
|
|
||||||
echo "Failed to build metric module images"
|
|
||||||
build_failed=true
|
build_failed=true
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
|
|
||||||
popd >/dev/null
|
metric_builds=(
|
||||||
|
"Metric FTP|src/metric/ftp/build/Dockerfile|argus-metric-ftp:latest|src/metric/ftp/build"
|
||||||
|
"Metric Prometheus|src/metric/prometheus/build/Dockerfile|argus-metric-prometheus:latest|src/metric/prometheus/build"
|
||||||
|
"Metric Grafana|src/metric/grafana/build/Dockerfile|argus-metric-grafana:latest|src/metric/grafana/build"
|
||||||
|
)
|
||||||
|
|
||||||
|
for build_spec in "${metric_builds[@]}"; do
|
||||||
|
IFS='|' read -r image_label dockerfile_path image_tag build_context <<< "$build_spec"
|
||||||
|
if build_image "$image_label" "$dockerfile_path" "$image_tag" "$build_context"; then
|
||||||
|
images_built+=("$image_tag")
|
||||||
|
else
|
||||||
|
build_failed=true
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "======================================="
|
echo "======================================="
|
||||||
|
|||||||
@ -71,8 +71,6 @@ declare -A images=(
|
|||||||
["argus-metric-ftp:latest"]="argus-metric-ftp-latest.tar"
|
["argus-metric-ftp:latest"]="argus-metric-ftp-latest.tar"
|
||||||
["argus-metric-prometheus:latest"]="argus-metric-prometheus-latest.tar"
|
["argus-metric-prometheus:latest"]="argus-metric-prometheus-latest.tar"
|
||||||
["argus-metric-grafana:latest"]="argus-metric-grafana-latest.tar"
|
["argus-metric-grafana:latest"]="argus-metric-grafana-latest.tar"
|
||||||
["argus-metric-test-node:latest"]="argus-metric-test-node-latest.tar"
|
|
||||||
["argus-metric-test-gpu-node:latest"]="argus-metric-test-gpu-node-latest.tar"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 函数:检查镜像是否存在
|
# 函数:检查镜像是否存在
|
||||||
|
|||||||
@ -2,6 +2,18 @@ FROM grafana/grafana:11.1.0
|
|||||||
|
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
|
# 构建参数:是否使用内网镜像
|
||||||
|
ARG USE_INTRANET=false
|
||||||
|
|
||||||
|
# 根据是否为内网构建切换 apk 源
|
||||||
|
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||||
|
echo "Configuring intranet apk repositories..." && \
|
||||||
|
sed -i 's#https\?://[^/]\+#http://10.68.64.1#g' /etc/apk/repositories; \
|
||||||
|
else \
|
||||||
|
echo "Configuring public apk repositories..." && \
|
||||||
|
sed -i 's#https\?://[^/]\+#https://mirrors.aliyun.com#g' /etc/apk/repositories; \
|
||||||
|
fi
|
||||||
|
|
||||||
# 安装必要的工具
|
# 安装必要的工具
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
supervisor \
|
supervisor \
|
||||||
@ -10,6 +22,11 @@ RUN apk add --no-cache \
|
|||||||
vim \
|
vim \
|
||||||
bash
|
bash
|
||||||
|
|
||||||
|
# 部署镜像时恢复到部署侧使用的内网镜像源
|
||||||
|
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||||
|
sed -i 's#https\?://[^/]\+#https://10.92.132.52/mirrors#g' /etc/apk/repositories; \
|
||||||
|
fi
|
||||||
|
|
||||||
# supervisor 日志目录
|
# supervisor 日志目录
|
||||||
RUN mkdir -p /var/log/supervisor
|
RUN mkdir -p /var/log/supervisor
|
||||||
|
|
||||||
|
|||||||
@ -61,10 +61,25 @@ RUN mkdir -p ${PROMETHEUS_BASE_PATH}/rules \
|
|||||||
&& ln -s ${PROMETHEUS_BASE_PATH} /prometheus
|
&& ln -s ${PROMETHEUS_BASE_PATH} /prometheus
|
||||||
|
|
||||||
# 修改 Prometheus 用户 UID/GID 并授权
|
# 修改 Prometheus 用户 UID/GID 并授权
|
||||||
RUN usermod -u ${ARGUS_BUILD_UID} nobody && \
|
RUN set -eux; \
|
||||||
groupmod -g ${ARGUS_BUILD_GID} nogroup && \
|
existing_user=""; \
|
||||||
chown -h nobody:nogroup /prometheus && \
|
if getent passwd "${ARGUS_BUILD_UID}" >/dev/null 2>&1; then \
|
||||||
chown -R nobody:nogroup ${PROMETHEUS_BASE_PATH} && \
|
existing_user="$(getent passwd "${ARGUS_BUILD_UID}" | cut -d: -f1)"; \
|
||||||
|
fi; \
|
||||||
|
if [ -n "$existing_user" ] && [ "$existing_user" != "nobody" ]; then \
|
||||||
|
userdel -r "$existing_user" || true; \
|
||||||
|
fi; \
|
||||||
|
existing_group=""; \
|
||||||
|
if getent group "${ARGUS_BUILD_GID}" >/dev/null 2>&1; then \
|
||||||
|
existing_group="$(getent group "${ARGUS_BUILD_GID}" | cut -d: -f1)"; \
|
||||||
|
fi; \
|
||||||
|
if [ -n "$existing_group" ] && [ "$existing_group" != "nogroup" ]; then \
|
||||||
|
groupdel "$existing_group" || true; \
|
||||||
|
fi; \
|
||||||
|
usermod -u ${ARGUS_BUILD_UID} nobody; \
|
||||||
|
groupmod -g ${ARGUS_BUILD_GID} nogroup; \
|
||||||
|
chown -h nobody:nogroup /prometheus; \
|
||||||
|
chown -R nobody:nogroup ${PROMETHEUS_BASE_PATH}; \
|
||||||
chown -R nobody:nogroup /etc/prometheus
|
chown -R nobody:nogroup /etc/prometheus
|
||||||
|
|
||||||
# supervisor 配置
|
# supervisor 配置
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user