import { options, sourceInfo, frontendImage, run, fail } from './release.mjs' import { spawnSync } from 'node:child_process' try { const args = options({ tag: { type: 'string' }, 'source-ref': { type: 'string' }, push: { type: 'boolean' } }) if (args.help) console.log('pnpm build:docker [--tag VERSION] [--source-ref FRONTEND_COMMIT] [--push]\npnpm push:docker 使用相同参数并将镜像推送到 Harbor。') else { const info = sourceInfo(args) const image = frontendImage(info.version) const buildx = spawnSync('docker', ['buildx', 'version'], { stdio: 'ignore' }).status === 0 // Export a single Docker-format image for the test server's Docker 18.06. const build = buildx ? ['buildx', 'build', '--platform', 'linux/amd64', '--output', 'type=docker'] : ['build'] run('docker', [...build, '-f', 'deploy/Dockerfile', '--build-arg', `VERSION=${info.version}`, '--build-arg', `SOURCE_REVISION=${info.revision}`, '--build-arg', `SOURCE_TREE=${info.tree}`, '-t', image, '.'], { env: { ...process.env, BUILDX_NO_DEFAULT_ATTESTATIONS: '1' } }) if (args.push) run('docker', ['push', image]) console.log(`${args.push ? '已推送镜像' : '镜像'}:${image}`) } } catch (error) { fail(error) }