Files
cnb/.cnb/template.yml
2026-01-28 10:39:04 +08:00

173 lines
5.4 KiB
YAML
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.
# 同步代码到gitea模板
.common_sync_to_gitea_template: &common_sync_to_gitea_template
services:
- docker
imports:
- https://cnb.cool/kevisual/env/-/blob/main/.env.development
# env:
# TO_REPO: kevisual/cnb
# TO_URL: git.xiongxiao.me
stages:
- name: '显示 git remote'
script: git remote -v
- name: sync to gitea
image: tencentcom/git-sync
settings:
target_url: https://${TO_URL}/${TO_REPO}.git
auth_type: https
username: "oauth2"
password: ${GITEA_TOKEN}
git_user: "abearxiong"
git_email: "xiongxiao@xiongxiao.me"
sync_mode: rebase
branch: main
# 同步gitea代码到当前仓库
.common_sync_from_gitea_template: &common_sync_from_gitea_template
services:
- docker
imports:
- https://cnb.cool/kevisual/env/-/blob/main/.env.development
# env:
# TO_REPO: kevisual/cnb
# TO_URL: git.xiongxiao.me
stages:
- name: '添加 gitea的origin'
script: |
git remote remove gitea 2>/dev/null || true
git remote add gitea https://oauth2:${GITEA_TOKEN}@${TO_URL}/${TO_REPO}.git
- name: '同步gitea代码到当前仓库'
script: git pull gitea main
- name: '提交到原本的origin'
script: git push origin main
# main:
# web_trigger_sync_to_gitea:
# - <<: *common_sync_to_gitea_template
# web_trigger_sync_from_gitea:
# - <<: *common_sync_from_gitea_template
# api_trigger_sync_to_gitea:
# - <<: *common_sync_to_gitea_template
# api_trigger_sync_from_gitea:
# - <<: *common_sync_from_gitea_template
# kubectl 部署模版
.kubectl_deploy_template: &kubectl_deploy_template
services:
- docker
docker:
image: docker.cnb.cool/kevisual/dev-env:latest
imports:
- https://cnb.cool/kevisual/env/-/blob/main/.env.development
stages:
- name: '部署k8s模块'
script: |
echo "${KUBECONFIG_DATA}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
# 如果设置了 KUBE_CONTEXT则切换上下文
if [ -n "${KUBE_CONTEXT}" ]; then
kubectl config use-context "${KUBE_CONTEXT}"
fi
export NAMESPACE=${KUBE_NAMESPACE:-default}
kubectl rollout restart deployment/${KUBE_DEPLOYMENT} -n ${NAMESPACE}
# 打包并发布镜像
.build_images_app_template: &build_images_app_template
services:
- docker
docker:
image: docker.cnb.cool/kevisual/dev-env:latest
stages:
- name: 检查环境是否需要打包
script:
- |
if [ -f "package.json" ]; then
echo "📦 开始前端构建流程"
pnpm install
pnpm run build || echo "⚠️ 构建失败或无 build script"
else
echo "🔍 非前端项目,跳过打包"
fi
- name: Docker build
script: docker build -t ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:latest .
- name: Docker push
script: docker push ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:latest
# 开发环境模版
.dev_template: &dev_template
services:
- vscode
docker:
image: docker.cnb.cool/kevisual/dev-env:latest
stages:
- name: 软链 .env.development 文件到工作目录(仓库根目录)
script: |
if [ -e "/root/.cnb/.env.development" ]; then
ln -sf /root/.cnb/.env.development ./.env
else
echo "文件不存在"
fi
printenv > ~/.env
if [ -f "package.json" ]; then
echo "📦 开始安装前端页面"
pnpm install
else
echo "🔍 非前端项目,跳过安装"
fi
init_stages:
- name: '安装依赖'
script: |
pnpm install
if [ -e "/root/.cnb/.env" ]; then
ln -sf /root/.cnb/.env ./.env
else
echo "文件不存在"
fi
# 结束状态模版
.end_state_template: &end_state_template
endStages:
- name: '结束'
script: echo "流水线执行完毕,当前状态:${CNB_PIPELINE_STATUS}"
# 预览模板
.preview_template: &preview_template
services:
- name: vscode
options:
# 启用预览模式
onlyPreview: true
# 启动业务端口的命令,端口必须启动在 8686
launch: node index.js
# 保活时间,单位毫秒,不设置默认 10 分钟没有心跳(检测不到开发环境内的 http 连接)即关闭开发环境
keepAliveTimeout: 3600000
# 是否守护进程模式,默认为 false非守护进程模式
# true以守护进程模式启动即 launch 启动预览业务服务时,会直接运行在后台
# false非守护进程模式启动执行 launch 启动预览业务服务时,可以看到日志,且需要等待 launch 启动完成并主动退出,才会继续执行后续流程
# 推荐设置为 false由用户自己实现业务启动成功后退出进程并后台运行这样可以看到业务启动日志方便定位问题
daemon: true
- docker
# 构建知识库模版
.knowledge_template: &knowledge_template
stages:
- name: 搭建知识库
image: cnbcool/knowledge-base
settings:
include:
- "docs/**.md"
- "blogs/**.md"
- "data/**.md"
.dev_vscode_template: &dev_vscode_template
vscode:
- runner:
cpus: 2
services:
- vscode
- docker
stages:
- name: ls
script: ls -al