Files
kra-new/web/deploy/build-docker.mjs
T

18 lines
1.2 KiB
JavaScript
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.
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) }