Files
cnb/.cnb/template.yml
xiongxiao 65da3f8c60 test env
2026-01-15 23:41:10 +08:00

120 lines
3.6 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.
.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
.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_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_tempalte: &dev_tempalte
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
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}"