Auto commit: 2026-03-27 13:04

This commit is contained in:
xiongxiao
2026-03-27 13:04:47 +08:00
committed by cnb
parent 8984913fcd
commit 704e0d71dd
5 changed files with 229 additions and 18 deletions

View File

@@ -97,4 +97,42 @@ ${branch}:
# - name: 结束阶段
# script: zsh -i -c 'bun run end'
`
}
export const createDockerBuildConfig = (params: {
repo: string,
// 参考 redis:latest 这种格式的镜像名称,必须包含冒号和标签,如果没有标签则默认为 latest
image: string
}) => {
const toRepo = params.repo!;
let image = params.image!;
const tagIndex = image.lastIndexOf(':');
if (tagIndex === -1) {
image = `${image}:latest`;
}
const tagVersion = image.split(':').pop()!;
const imageLastPart = image.split('/').pop()!;
const imageNameWithoutTag = imageLastPart.split(':')[0];
const pullCmd = `docker pull ${image}`;
const tagCmd = `docker tag ${image} docker.cnb.cool/${toRepo}/${imageLastPart}`;
const pushCmd = `docker push docker.cnb.cool/${toRepo}/${imageLastPart}`;
let pushLatestCmd = 'echo "不需要推送 latest 标签"';
if (tagVersion !== 'latest') {
pushLatestCmd = `docker tag ${image} docker.cnb.cool/${toRepo}/${imageNameWithoutTag}:latest && docker push docker.cnb.cool/${toRepo}/${imageNameWithoutTag}:latest`;
}
return `
$:
api_trigger_event:
- docker:
image: cnbcool/default-dev-env:latest
services:
- docker
stages:
- name: '执行同步脚本'
script: |
${pullCmd}
${tagCmd}
${pushCmd}
${pushLatestCmd}
`
}