Files
2026-06-18 14:36:13 +08:00

320 lines
9.9 KiB
YAML

kind: pipeline # 定义对象类型,还有secret和signature两种类型
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
name: cicd # 定义流水线名称
clone:
disable: true
steps: # 定义流水线执行步骤,这些步骤将顺序执行
- name: clone
image: alpine/git
pull: if-not-exists
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
commands:
- git config --global core.compression 0
- git clone https://github.com/dataelement/bisheng.git .
- git checkout $DRONE_COMMIT
- name: set poetry
pull: if-not-exists
image: golang
environment:
RELEASE_VERSION: 99.99.99
NEXUS_PUBLIC:
from_secret: NEXUS_PUBLIC
NEXUS_PUBLIC_PASSWORD:
from_secret: NEXUS_PUBLIC_PASSWORD
REPO:
from_secret: PY_NEXUS
PROXY:
from_secret: APT-GET
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
- name: bisheng-cache
path: /app/build/
commands:
- cd ./src/backend
- echo $REPO
- REPO2=$(echo $REPO | sed 's/http:\\/\\///g')
- sed '/apt-get/ s|$| '"$PROXY"'|' Dockerfile
# 删掉 `&& uv cache clean`(连同 && 一起删,避免留下悬空操作符导致 sh 语法错误 exit 2)
- sed -i -E 's/[[:space:]]*&&[[:space:]]*uv cache clean.*$//' Dockerfile
# 在 `RUN uv sync` 行之前插入国内镜像 ENV:用 awk 按内容锚定(不依赖行号,Dockerfile 改动也不会插错位),ENV 在 uv sync 之前生效
- awk '/^RUN uv sync/ && !x {print "ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_DEFAULT_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; x=1} {print}' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile
- cat Dockerfile
- name: build_docker
pull: if-not-exists
image: docker:24.0.6
privileged: true
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
- name: apt-cache
path: /var/cache/apt/archives # 将应用打包好的Jar和执行脚本挂载出来
- name: socket
path: /var/run/docker.sock
- name: pro-cache
path: /root/.local/share/pypoetry
- name: uv-cache
path: /root/.cache/uv
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: release
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-backend
docker_user:
from_secret: NEXUS_USER
docker_password:
from_secret: NEXUS_PASSWORD
commands:
- cd ./src/backend/
- docker login -u $docker_user -p $docker_password $docker_registry
- docker build -t $docker_repo:$version .
- docker push $docker_repo:$version
- name: build_docker_frontend
pull: if-not-exists
image: docker:24.0.6
privileged: true
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
- name: apt-cache
path: /var/cache/apt/archives # 将应用打包好的Jar和执行脚本挂载出来
- name: socket
path: /var/run/docker.sock
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: release
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-frontend
docker_user:
from_secret: NEXUS_USER
docker_password:
from_secret: NEXUS_PASSWORD
commands:
- cd ./src/frontend/
- docker login -u $docker_user -p $docker_password $docker_registry
- docker build -t $docker_repo:$version .
- docker push $docker_repo:$version
- name: ssh deploy
image: appleboy/drone-ssh
pull: if-not-exists
settings:
host: 192.168.106.116
username: root
password:
from_secret: sshpwd
script:
- echo =======找到目录=======
- cd /opt/server/bisheng-test
- echo =======直接启动=======
- docker compose pull
- docker compose up -d
- name: notify-start # notify
pull: if-not-exists
image: plugins/webhook
settings:
debug: true
urls:
from_secret: FEISHU_URL
content_type: application/json
template: |
{
"msg_type": "interactive",
"card": {
"type": "template",
"data": {
"template_id": "AAqkI9bnY5FUs",
"template_variable": {
"repo_name": "{{ repo.name }}",
"build_branch": "{{build.branch}}",
"build_author": "{{ DRONE_COMMIT_AUTHOR }}",
"link": "{{build.link}}",
"commit_msg": "{{ trim build.message }}",
"build_tag":"{{build.tag}}",
"build_start":"{{build.started}}",
"status": "{{ build.status }}"
}
}
}
}
when: # 成功
status:
- success
trigger:
branch:
- release
event:
- push
volumes:
- name: bisheng-cache
host:
path: /opt/drone/data/bisheng/
- name: pro-cache
host:
path: /opt/drone/data/pro/
- name: apt-cache
host:
path: /opt/drone/data/bisheng/apt/
- name: socket
host:
path: /var/run/docker.sock
---
kind: pipeline # 定义对象类型,还有secret和signature两种类型
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
name: feat_cicd # 定义流水线名称
clone:
disable: true
steps: # 定义流水线执行步骤,这些步骤将顺序执行
- name: clone
image: alpine/git
pull: if-not-exists
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
commands:
- git config --global core.compression 0
- git clone https://github.com/dataelement/bisheng.git .
- git checkout $DRONE_COMMIT
- name: set uv mirrors
pull: if-not-exists
image: golang
environment:
PROXY:
from_secret: APT-GET
volumes:
- name: bisheng-cache
path: /app/build/
commands:
- cd ./src/backend
# 删掉 `&& uv cache clean`(连同 && 一起删,避免留下悬空操作符导致 sh 语法错误 exit 2)
- sed -i -E 's/[[:space:]]*&&[[:space:]]*uv cache clean.*$//' Dockerfile
# 在 `RUN uv sync` 行之前插入国内镜像 ENV:用 awk 按内容锚定(不依赖行号,Dockerfile 改动也不会插错位),ENV 在 uv sync 之前生效
- awk '/^RUN uv sync/ && !x {print "ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_DEFAULT_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple"; print "ENV UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple"; x=1} {print}' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile
- cat Dockerfile
- name: build_docker
pull: if-not-exists
image: docker:24.0.6
privileged: true
volumes:
- name: apt-cache
path: /var/cache/apt/archives
- name: socket
path: /var/run/docker.sock
- name: pro-cache
path: /root/.local/share/pypoetry
- name: uv-cache
path: /root/.cache/uv
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: ${DRONE_BRANCH}
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-backend
docker_user:
from_secret: NEXUS_USER
docker_password:
from_secret: NEXUS_PASSWORD
commands:
- echo "old tag is $version"
- version=$(echo $version | sed 's/\\//_/g')
- echo "build image tag is $version"
- cd ./src/backend/
- docker login -u $docker_user -p $docker_password $docker_registry
- docker build -t $docker_repo:$version .
- docker push $docker_repo:$version
- name: build_docker_frontend
pull: if-not-exists
image: docker:24.0.6
privileged: true
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
- name: apt-cache
path: /var/cache/apt/archives # 将应用打包好的Jar和执行脚本挂载出来
- name: socket
path: /var/run/docker.sock
environment:
http_proxy:
from_secret: PROXY
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: ${DRONE_BRANCH}
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-frontend
docker_user:
from_secret: NEXUS_USER
docker_password:
from_secret: NEXUS_PASSWORD
commands:
- echo "old tag is $version"
- version=$(echo $version | sed 's/\\//_/g')
- echo "build image tag is $version"
- cd ./src/frontend/
- docker login -u $docker_user -p $docker_password $docker_registry
- docker build -t $docker_repo:$version .
- docker push $docker_repo:$version
# - name: ssh deploy backend
# image: appleboy/drone-ssh
# pull: if-not-exists
# settings:
# host: 192.168.106.105
# username: root
# password:
# from_secret: sshpwd
# port: 22
# command_timeout: 10m
# script: |
# echo "=======同步 105 backend ======="
# cd /opt/server/dm/bisheng-dm/docker
# docker compose pull
# docker compose up -d
trigger:
branch:
- feat/**
event:
- push
volumes:
- name: bisheng-cache
host:
path: /opt/drone/data/bisheng/
- name: pro-cache
host:
path: /opt/drone/data/pro/
- name: apt-cache
host:
path: /opt/drone/data/bisheng/apt/
- name: socket
host:
path: /var/run/docker.sock
- name: uv-cache
host:
path: /opt/drone/data/uv/