You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

195 lines
4.2 KiB

kind: pipeline
type: docker
name: Build-Deploy
platform:
os: linux
arch: amd64
steps:
# golang 编译
- name: build
image: golang:1.17
pull: if-not-exists
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.io"
CGO_ENABLED: 0
commands:
- go build -ldflags "-w -s" -o tmp/carp main.go
volumes:
- name: pkgdeps
path: /go/pkg
when:
event:
- push
- tag
# 发布,编译镜像并推送到私有镜像仓库
- name: publish
image: plugins/docker
pull: if-not-exists
depends_on:
- build
settings:
dockerfile: ./Dockerfile
use_cache: true
registry: https://ccr.ccs.tencentyun.com # 测试腾讯云上的仓库
repo: ccr.ccs.tencentyun.com/guandao/test # docker仓库地址
username: 100011296659
password:
from_secret: repo_pw
tags:
- ${DRONE_TAG=latest} # 默认latest,会自动同步git tag
when:
event:
- push
- tag
# scp,复制文件
- name: scp
image: appleboy/drone-scp
pull: if-not-exists
settings:
host: 159.75.130.72
username: root
key:
from_secret: ssh_key
port: 22
target: /root/repo/mytest
source:
- docker-compose.yaml
when:
event:
- push
- tag
# 部署,拉取对应镜像并重启docker compose
- name: deploy
image: appleboy/drone-ssh # SSH工具镜像
depends_on:
- publish
settings:
host: 159.75.130.72 # 远程连接地址
username: root # 远程连接账号
ssh_key:
from_secret: ssh_key
port: 22 # 远程连接端口
command_timeout: 10m # 远程执行命令超时时间
script:
- cd /root/repo/mytest # 进入宿主机构建目录
- docker pull ccr.ccs.tencentyun.com/guandao/test
- docker-compose down
- docker-compose up -d
when:
event:
- push
- tag
- name: feishu-notification
pull: if-not-exists
image: serialt/drone-feishu-message
settings:
token: 5072d4ac-febf-4b35-87f8-caab612785b7
secret: ElkWgQETGKlfXTH8GiEDc8jOYMpD65pZ
sha_link: true
when:
status:
- failure
# golang win编译
- name: win-build
image: golang:1.17
pull: if-not-exists
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.io"
CGO_ENABLED: 0
GOOS: "windows"
GOARCH: "amd64"
commands:
- go build -ldflags "-w -s" -o archive/carp.exe main.go
volumes:
- name: pkgdeps
path: /go/pkg
when:
event:
- tag
- name: release
image: plugins/gitea-release
depends_on:
- publish
settings:
# 参看一下链接获取api key
# https://docs.gitea.io/en-us/api-usage/#generating-and-listing-api-tokens
api_key:
from_secret: release_api_key
base_url: https://git.cobb.wang
files: archive/*
when:
event:
- tag
volumes: # 挂载,持久化数据
- name: pkgdeps
host:
path: /tmp/pkg/repotest
---
kind: pipeline
type: docker
name: Rollback
platform:
os: linux
arch: amd64
steps:
# scp,复制文件
- name: rollback-scp
image: appleboy/drone-scp
pull: if-not-exists
settings:
host: 159.75.130.72
username: root
key:
from_secret: ssh_key
port: 22
target: /root/repo/mytest
source:
- docker-compose.yaml
# 部署,拉取对应镜像并重启docker compose
- name: rolllback-deploy
image: appleboy/drone-ssh # SSH工具镜像
pull: if-not-exists
depends_on:
- rollback-scp
settings:
host: 159.75.130.72 # 远程连接地址
username: root # 远程连接账号
ssh_key:
from_secret: ssh_key
port: 22 # 远程连接端口
command_timeout: 10m # 远程执行命令超时时间
script:
- tag=${DRONE_TAG}
- echo "rollback to" $tag
- cd /root/repo/mytest # 进入宿主机构建目录
- docker pull ccr.ccs.tencentyun.com/guandao/test:$tag # 指定回退版本
- docker-compose down
- docker-compose up -d
trigger:
event:
- promote
- rollback
target:
- production
when:
branch:
- master