fix: 统一前端Harbor镜像发布与拉取部署
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { options, sourceInfo, run, fail } from './release.mjs'
|
||||
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' } })
|
||||
if (args.help) console.log('pnpm build:docker [--tag VERSION] [--source-ref FRONTEND_COMMIT]')
|
||||
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)
|
||||
run('docker', ['build', '-f', 'deploy/Dockerfile', '--build-arg', `VERSION=${info.version}`, '--build-arg', `SOURCE_REVISION=${info.revision}`, '--build-arg', `SOURCE_TREE=${info.tree}`, '-t', `sw2/frontend:${info.version}`, '.'])
|
||||
console.log(`镜像:sw2/frontend:${info.version}`)
|
||||
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) }
|
||||
|
||||
Reference in New Issue
Block a user