deerflow-code/nginx-1.28-deployment/build-image.sh
2026-09-07 18:24:55 +08:00

36 lines
983 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
IMAGE="${NGINX_IMAGE:-nginx-oneclick:1.28}"
NGINX_VERSION="${NGINX_VERSION:-1.28}"
ARCHIVE="${NGINX_IMAGE_ARCHIVE:-${SCRIPT_DIR}/nginx-oneclick-1.28.tar.gz}"
command -v docker >/dev/null 2>&1 || {
echo "错误:未找到 Docker,请先安装 Docker。" >&2
exit 1
}
echo "[1/2] 构建镜像 ${IMAGE}(基础镜像 nginx:${NGINX_VERSION})"
docker build \
--pull \
--build-arg "NGINX_VERSION=${NGINX_VERSION}" \
--tag "${IMAGE}" \
"${SCRIPT_DIR}"
echo "[2/2] 导出镜像 ${ARCHIVE}"
mkdir -p "$(dirname -- "${ARCHIVE}")"
tmp_archive="${ARCHIVE}.tmp"
trap 'rm -f -- "${tmp_archive}"' EXIT
docker save "${IMAGE}" | gzip -c >"${tmp_archive}"
mv -f -- "${tmp_archive}" "${ARCHIVE}"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${ARCHIVE}" >"${ARCHIVE}.sha256"
fi
echo
echo "构建完成:"
echo " 镜像:${IMAGE}"
echo " 文件:${ARCHIVE}"