bd18acd040
Deploy / Staging E2E Tests (push) Has been skipped
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
Deploy / Deploy Staging (push) Failing after 135h54m40s
CI/CD Pipeline / Frontend Lint (push) Failing after 135h54m55s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 135h54m55s
71 lines
2.6 KiB
Bash
Executable File
71 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
VERSION="${1:-${RELEASE_VERSION:-}}"
|
|
if [ -z "$VERSION" ]; then
|
|
echo "Usage: $0 <version>"
|
|
echo "Example: $0 v0.1.5"
|
|
exit 1
|
|
fi
|
|
|
|
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
|
|
OUTPUT_DIR="${OUTPUT_DIR:-$ROOT_DIR/dist/release-images}"
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
API_IMAGE="xiaoxia-saas-api:$VERSION"
|
|
WORKER_IMAGE="xiaoxia-saas-worker:$VERSION"
|
|
API_LATEST="xiaoxia-saas-api:dev"
|
|
WORKER_LATEST="xiaoxia-saas-worker:dev"
|
|
TAR_PATH="$OUTPUT_DIR/xiaoxia-runtime-images-$VERSION.tar"
|
|
|
|
cd "$ROOT_DIR"
|
|
|
|
if docker ps --format '{{.Names}}' | grep -Eq '^(xiaoxia-(api|web|worker|postgres|redis)-production|gitea)$'; then
|
|
if [ "${ALLOW_SHARED_PRODUCTION_BUILD_HOST:-false}" != "true" ]; then
|
|
echo "Refusing to build runtime images on a host that is running production services."
|
|
echo "Use a dedicated build host/CI runner, or set ALLOW_SHARED_PRODUCTION_BUILD_HOST=true only for an explicitly approved emergency."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# ---- BuildKit 缓存优化 ----
|
|
CACHE_REGISTRY="${CACHE_REGISTRY:-git.xiaoxiajianji.com/xiaoxia/xiaoxia-saas}"
|
|
CACHE_TAG="${CACHE_TAG:-release}"
|
|
USE_CACHE=0
|
|
|
|
# 检查 buildx 和 Gitea Registry 认证是否可用
|
|
if docker buildx version >/dev/null 2>&1; then
|
|
# 尝试登录缓存 Registry(有 token 才启用缓存)
|
|
if [ -n "${REGISTRY_TOKEN:-}" ]; then
|
|
printf '%s' "${REGISTRY_TOKEN}" | docker login git.xiaoxiajianji.com -u xiaoxia --password-stdin 2>/dev/null && USE_CACHE=1
|
|
fi
|
|
# 确保使用 docker driver(共享 daemon 凭证)
|
|
docker buildx use default 2>/dev/null || true
|
|
fi
|
|
|
|
if [ "$USE_CACHE" -eq 1 ]; then
|
|
echo "Using buildx with distributed cache (${CACHE_REGISTRY})"
|
|
docker buildx build \
|
|
--cache-from "type=registry,ref=${CACHE_REGISTRY}/api-cache:${CACHE_TAG},ignore-error=true" \
|
|
--cache-to "type=registry,ref=${CACHE_REGISTRY}/api-cache:${CACHE_TAG},mode=max" \
|
|
-f infra/docker/api.Dockerfile \
|
|
-t "$API_IMAGE" -t "$API_LATEST" \
|
|
--load \
|
|
.
|
|
docker buildx build \
|
|
--cache-from "type=registry,ref=${CACHE_REGISTRY}/worker-cache:${CACHE_TAG},ignore-error=true" \
|
|
--cache-to "type=registry,ref=${CACHE_REGISTRY}/worker-cache:${CACHE_TAG},mode=max" \
|
|
-f infra/docker/worker.Dockerfile \
|
|
-t "$WORKER_IMAGE" -t "$WORKER_LATEST" \
|
|
--load \
|
|
.
|
|
else
|
|
echo "Buildx cache not available, using plain docker build"
|
|
docker build --pull=false -f infra/docker/api.Dockerfile -t "$API_IMAGE" -t "$API_LATEST" .
|
|
docker build --pull=false -f infra/docker/worker.Dockerfile -t "$WORKER_IMAGE" -t "$WORKER_LATEST" .
|
|
fi
|
|
|
|
docker save "$API_IMAGE" "$API_LATEST" "$WORKER_IMAGE" "$WORKER_LATEST" -o "$TAR_PATH"
|
|
|
|
printf '%s\n' "$TAR_PATH"
|