Skip to content

Commit 3ce47fa

Browse files
authored
feat(@142vip/utils): 增加buildImage参数,支持日志打印、镜像推送 (#773)
* feat(@142vip/utils): 增加`buildImage`参数,支持日志打印、镜像推送 * chore: update
1 parent a491234 commit 3ce47fa

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

packages/utils/src/core/docker.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface BuildImageDockerOptions extends DockerOptions {
2222
// build命令时,GC限制内存大小
2323
memory?: number
2424
platform?: string
25+
progress?: 'plain' | 'auto' | boolean
2526
}
2627

2728
interface UserLoginDockerOptions extends DockerOptions {
@@ -235,8 +236,11 @@ async function buildImage(args: BuildImageDockerOptions): Promise<void> {
235236
const targetParams = args.target != null ? `--target ${args.target}` : ''
236237
const memoryParams = args.memory != null ? `--memory=${args.memory}mb` : ''
237238
const platformParams = args.platform != null ? `--platform=${args.platform}` : ''
239+
const pushParams = args.push ? '--push' : ''
240+
const progressParmas = args.progress ? `--progress=${args.progress}` : ''
238241

239-
const command = `docker build ${buildArg} ${targetParams} ${memoryParams} ${platformParams} -t '${args.imageName}' .`
242+
// 支持buildx
243+
const command = `DOCKER_BUILDKIT=1 docker buildx build ${buildArg} ${pushParams} ${progressParmas} ${targetParams} ${memoryParams} ${platformParams} -t '${args.imageName}' .`
240244

241245
if (args.logger) {
242246
vipLogger.log(`执行的命令:\n`, { startLabel: VipSymbols.success })
@@ -246,15 +250,6 @@ async function buildImage(args: BuildImageDockerOptions): Promise<void> {
246250

247251
await scriptExecutor(command)
248252

249-
if (args.push) {
250-
const exist = await isExistImage(args.imageName)
251-
252-
if (exist) {
253-
vipLogger.log(args.imageName, { startLabel: '推送镜像' })
254-
await pushImage(args.imageName)
255-
}
256-
}
257-
258253
// 推送完删除
259254
if (args.push && args.delete) {
260255
vipLogger.log(args.imageName, { startLabel: '删除镜像' })

0 commit comments

Comments
 (0)