fix: build local images through the context-aware Docker CLI

This commit is contained in:
2026-11-01 19:13:41 +08:00
parent 11efdaa331
commit c4fb5a6f4e

View File

@@ -45,13 +45,27 @@ def compose(*args, **kwargs):
ORBIT_LOCAL_USER=f'{os.getuid()}:{os.getgid()}')
# 本地环境使用 Docker 自带构建器,不占用用户选中的跨平台构建器。
docker_context = subprocess.check_output(['docker', 'context', 'show'], text=True).strip()
env.update(BUILDX_BUILDER=docker_context, COMPOSE_BAKE='false')
env.update(DOCKER_CONTEXT=docker_context, BUILDX_BUILDER=docker_context, COMPOSE_BAKE='false')
command = ['docker', '--context', docker_context, 'compose', '--project-name', 'orbit-test',
'--env-file', str(ENV_FILE), '-f', str(ROOT / 'deploy/docker-compose.yml'),
'-f', str(ROOT / 'deploy/local/compose.yml'), *args]
return subprocess.run(command, cwd=ROOT, env=env, check=True, **kwargs)
def build_image(values):
# Compose's embedded buildx can lose the selected context for a context-backed
# builder. Invoke the Docker CLI explicitly; do not change the user's builder.
docker_context = subprocess.check_output(['docker', 'context', 'show'], text=True).strip()
command = ['docker', '--context', docker_context, 'buildx', 'build',
'--builder', docker_context, '--load', '--tag', values['ORBIT_IMAGE']]
for source, target in [('ORBIT_BUILD_VERSION', 'VERSION'),
('ORBIT_BUILD_REVISION', 'REVISION'),
('ORBIT_BUILD_TIME', 'BUILD_TIME')]:
command.extend(['--build-arg', target + '=' + values[source]])
command.append('.')
subprocess.run(command, cwd=ROOT, check=True)
def wait_ready():
for _ in range(60):
try:
@@ -100,7 +114,7 @@ def setup():
values['ORBIT_BUILD_TIME'] = datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
save_settings(values)
compose('config', '--quiet')
compose('build', 'orbit')
build_image(values)
# 完成构建后再优雅停止旧写节点,避免迁移期间混用凭据存储版本。
compose('stop', 'orbit')
compose('up', '-d', 'mysql', 'verify', 'archive-init', 'credential-key-init')