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.
235 lines
5.1 KiB
235 lines
5.1 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:
|
|
- echo ${api}
|
|
- env
|
|
- go build -ldflags "-w -s" -o tmp/carp main.go
|
|
volumes:
|
|
- name: pkgdeps
|
|
path: /go/pkg
|
|
when:
|
|
event:
|
|
- push
|
|
- custom
|
|
- tag
|
|
|
|
# 发布,编译镜像并推送到私有镜像仓库
|
|
- name: publish
|
|
image: plugins/docker
|
|
pull: if-not-exists
|
|
depends_on:
|
|
- build
|
|
settings:
|
|
dockerfile: ./Dockerfile
|
|
use_cache: true
|
|
insecure: true
|
|
registry: http://192.168.31.136:5000 # 测试腾讯云上的仓库
|
|
repo: 192.168.31.136:5000/guandao/test # docker仓库地址
|
|
daemon_off: true
|
|
launch_debug: true
|
|
debug: true
|
|
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: 192.168.31.146
|
|
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: 192.168.31.146 # 远程连接地址
|
|
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
|
|
# depends_on:
|
|
# - build
|
|
# - publish
|
|
# - deploy
|
|
# settings:
|
|
# token: 5072d4ac-febf-4b35-87f8-caab612785b7
|
|
# secret: ElkWgQETGKlfXTH8GiEDc8jOYMpD65pZ
|
|
# sha_link: true
|
|
# when:
|
|
# status:
|
|
# - failure
|
|
# event:
|
|
# - push
|
|
|
|
# - name: feishu-notification-success
|
|
# pull: if-not-exists
|
|
# image: ghcr.io/drizztdu/drone-feishu:linux-amd64
|
|
# depends_on:
|
|
# - build
|
|
# - publish
|
|
# - deploy
|
|
# settings:
|
|
# Webhook: https://open.feishu.cn/open-apis/bot/v2/hook/5072d4ac-febf-4b35-87f8-caab612785b7
|
|
# when:
|
|
# status:
|
|
# - success
|
|
# event:
|
|
# - push
|
|
|
|
# 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: upx
|
|
image: cnbattle/drone-upx
|
|
depends_on:
|
|
- win-build
|
|
settings:
|
|
level: 5 //default 5
|
|
save_file: archive/carp_pack.exe
|
|
original_file: archive/carp.exe
|
|
when:
|
|
event:
|
|
- tag
|
|
|
|
- name: release
|
|
image: plugins/gitea-release
|
|
depends_on:
|
|
- win-build
|
|
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: http://192.168.31.146:3000
|
|
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: 192.168.31.146
|
|
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: 192.168.31.146 # 远程连接地址
|
|
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
|