| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- kind: pipeline
- type: docker
- name: ym-gateway-prod
- volumes: # 声明数据卷
- - name: targetDir
- host:
- path: /ym-gateway
- clone:
- disable: false # 启用代码拉取
- steps:
- - name: build-project
- image: mcr.microsoft.com/dotnet/sdk:7.0
- pull: if-not-exists
- depends_on: [clone] # 依赖的步骤
- volumes: # 挂载数据卷
- - name: targetDir
- path: /drone/src/dist/
- commands: # 执行命令
- - echo '' > ~/.nuget/NuGet/NuGet.Config
- - echo '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><add key="nuget.org" value="https://nuget.cdn.azure.cn/v3/index.json" protocolVersion="3" /></packageSources></configuration>' > ~/.nuget/NuGet/NuGet.Config
- - rm -rf /drone/src/dist/*
- - dotnet publish -c release -o ./publish -r linux-x64
- - cp -r ./publish/* /drone/src/dist # 复制文件
- when:
- status:
- - success # 当前步骤成功时执行
- - name: scp-project
- image: appleboy/drone-scp
- pull: if-not-exists
- depends_on: [build-project] # 依赖的步骤
- volumes: # 挂载数据卷
- - name: targetDir # 数据卷名称
- path: /ym-gateway # 容器内目录 绝对路径
- settings:
- host:
- from_secret: ym-gateway-host-a
- username:
- from_secret: username
- password:
- from_secret: userpwd
- port: 22
- command_timeout: 2m
- target: /home/ABServer/deploy-ready/
- source:
- - echo ====开始拷贝=======
- - /ym-gateway/*
- - echo ====结束拷贝=======
- when:
- status:
- - success # 当前步骤成功时执行
- - name: deploy-project
- image: appleboy/drone-ssh
- pull: if-not-exists
- depends_on: [scp-project] # 依赖的步骤
- settings:
- host:
- from_secret: ym-gateway-host-a
- username:
- from_secret: username
- password:
- from_secret: userpwd
- port: 22
- command_timeout: 2m
- script:
- - echo ====备份线上文件=======
- - cp -r /home/ABServer/webroot/ym-gateway /home/ABServer/deploy-bak/
- - echo ====开始部署=======
- - cd /home/ABServer/
- - cp -r /home/ABServer/deploy-ready/ym-gateway /home/ABServer/webroot/
- - docker restart ym-gateway
- - echo ====等待容器启动=======
- - sleep 10 # 等待容器启动
- - echo ====部署成功=======
- when:
- status:
- - success # 当前步骤成功时执行
- - name: scp-project-b
- image: appleboy/drone-scp
- pull: if-not-exists
- depends_on: [deploy-project] # 依赖的步骤
- volumes: # 挂载数据卷
- - name: targetDir # 数据卷名称
- path: /ym-gateway # 容器内目录 绝对路径
- settings:
- host:
- from_secret: ym-gateway-host-b
- username:
- from_secret: username
- password:
- from_secret: userpwd
- port: 22
- command_timeout: 10m
- target: /home/ABServer/deploy-ready/
- source:
- - echo ====开始拷贝=======
- - /ym-gateway/*
- - echo ====结束拷贝=======
- when:
- status:
- - success # 当前步骤成功时执行
- - name: deploy-project-b
- image: appleboy/drone-ssh
- pull: if-not-exists
- depends_on: [scp-project-b] # 依赖的步骤
- settings:
- host:
- from_secret: ym-gateway-host-b
- username:
- from_secret: username
- password:
- from_secret: userpwd
- port: 22
- command_timeout: 10m
- script:
- - echo ====备份线上文件=======
- - cp -r /home/ABServer/webroot/ym-gateway /home/ABServer/deploy-bak/ym-gateway
- - echo ====开始部署=======
- - cd /home/ABServer/
- - cp -r /home/ABServer/deploy-ready/ym-gateway /home/ABServer/webroot/
- - docker restart ym-gateway
- # - docker restart nodeServer1
- - echo ====部署成功=======
- when:
- status:
- - success # 当前步骤成功时执行
- trigger:
- branch:
- - release-ym-gateway
- event:
- - push
- #排除合并请求
- exclude:
- - ref: refs/pull/*
- ---
- kind: pipeline
- type: docker
- name: ym-gateway-deploy
- volumes: # 声明数据卷
- - name: build-artifacts
- host:
- path: /home/ABServer/webroot/ym-gateway
- - name: dockerfile-source
- host:
- path: /home/ABServer/dockfile
- - name: timezone
- host:
- path: /etc/localtime
- - name: docker-socket
- host:
- path: /var/run/docker.sock
- clone:
- disable: false # 启用代码拉取
- steps:
- # 阶段1: 构建
- - name: build-project
- image: mcr.microsoft.com/dotnet/sdk:7.0
- volumes:
- - name: build-artifacts
- path: /drone/src/dist/
- pull: if-not-exists
- depends_on: [clone] # 依赖的步骤
- commands: # 执行命令
- - echo '' > ~/.nuget/NuGet/NuGet.Config
- - echo '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><add key="nuget.org" value="https://nuget.cdn.azure.cn/v3/index.json" protocolVersion="3" /></packageSources></configuration>' > ~/.nuget/NuGet/NuGet.Config
- - rm -rf /drone/src/dist/*
- - dotnet publish -c release -o ./publish -r linux-x64
- - cp -r ./publish/* /drone/src/dist/ # 复制文件
- - ls -alR /drone/src/dist/
- when:
- status:
- - success # 当前步骤成功时执行
- # 阶段2: 准备Docker上下文(关键修正部分)
- - name: prepare-docker-context
- image: alpine:3.21.3
- depends_on: [ build-project ]
- volumes:
- - name: build-artifacts
- path: /context
- - name: dockerfile-source
- path: /dockerfiles
- commands:
- - cp /dockerfiles/template.dockerfile /context/Dockerfile
- - cp -r /dockerfiles/fonts /context/fonts
- - sed -i 's/{ImageName}/OmegaGateway/g' /context/Dockerfile
- # - echo -e "*\n!*.dll\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
- - ls -alR /context
- # 阶段3: 构建并推送镜像
- - name: docker-build-push
- image: docker:24.0-cli
- depends_on: [ prepare-docker-context ]
- volumes:
- - name: build-artifacts
- path: /context
- - name: timezone
- path: /etc/localtime
- - name: docker-socket
- path: /var/run/docker.sock
- environment:
- HARBOR_USER:
- from_secret: harbor_robot
- HARBOR_PASS:
- from_secret: harbor_token
- commands:
- - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.seasidecity.cn
- - cd /context
- - ls .
- - TAG=prod-$(date +%Y%m%d%H%M%S)
- - docker build -t "harbor.seasidecity.cn/omega_lib/ym-gateway:$TAG" .
- - docker push "harbor.seasidecity.cn/omega_lib/ym-gateway:$TAG"
- - docker rmi "harbor.seasidecity.cn/omega_lib/ym-gateway:$TAG"
- trigger:
- branch:
- - prod-gateway
- event:
- - push
|