Files
2026-05-18 00:50:46 +08:00

72 lines
2.2 KiB
Python

"""
构建并上传全部 forge 编译环境镜像
默认按依赖顺序构建 ubuntu 和 bun
1. 先构建并上传 docker.pchuan.top/forge/ubuntu:latest
2. 再构建并上传 docker.pchuan.top/forge/bun:latest
3. bun 默认依赖刚上传的 ubuntu 镜像
- --no-push 只构建不上传
- --force-build 使用 docker build --no-cache
- --platform linux/amd64 指定构建平台
"""
import argparse
import subprocess
import sys
from pathlib import Path
# 基础配置
ROOT = Path(__file__).resolve().parents[1]
BUILD_SCRIPT = ROOT / "scripts" / "build.py"
TARGETS = ["ubuntu", "bun"]
parser = argparse.ArgumentParser(description="构建并上传全部 forge 编译环境镜像")
parser.add_argument("--registry", default="docker.pchuan.top", help="镜像仓库地址")
parser.add_argument("--namespace", default="forge", help="镜像命名空间")
parser.add_argument("--tag", default="latest", help="镜像 tag")
parser.add_argument("--no-push", action="store_true", help="只构建不上传")
parser.add_argument("--force-build", action="store_true", help="强制无缓存构建")
parser.add_argument("--platform", default="", help="目标平台,例如 linux/amd64")
parser.add_argument("--bun-registry", default="", help="覆盖 bun 的 npm registry")
args = parser.parse_args()
ubuntu_image = f"{args.registry.rstrip('/')}/{args.namespace.strip('/')}/ubuntu:{args.tag}"
for target in TARGETS:
command = [
sys.executable,
str(BUILD_SCRIPT),
target,
"--registry",
args.registry,
"--namespace",
args.namespace,
"--tag",
args.tag,
]
if args.no_push:
command += ["--no-push"]
if args.force_build:
command += ["--force-build"]
if args.platform:
command += ["--platform", args.platform]
# bun 必须显式依赖本次构建的 ubuntu 镜像地址
if target == "bun":
command += ["--base-image", ubuntu_image]
if args.bun_registry:
command += ["--bun-registry", args.bun_registry]
print(f"[RUN] Build target {target}")
print("[INFO] " + " ".join(command))
subprocess.run(command, cwd=ROOT, check=True)
print(f"[PASS] Build target {target}")
print("[PASS] build all completed")