| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- kind: pipeline
- type: docker
- name: ym-router-deploy
- volumes: # 声明数据卷
- - name: build-artifacts
- host:
- path: /home/ABServer/webroot/omega-router-server
- - 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://api.nuget.org/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/omega-template.dockerfile /context/Dockerfile
- - cp -r /dockerfiles/fonts /context/fonts
- - sed -i 's/{ImageName}/OmegaRouter/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
- SERVER_NAME: omega-router-server
- 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/$$SERVER_NAME:$TAG" .
- - docker push "harbor.seasidecity.cn/omega/$$SERVER_NAME:$TAG"
- - docker rmi "harbor.seasidecity.cn/omega/$$SERVER_NAME:$TAG"
- trigger:
- branch:
- - prod-router
- event:
- - push
|