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.
 
 

102 lines
2.3 KiB

kind: pipeline
type: docker
name: TEST
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: t-b494ae8df34526b98ce133b4936e55ea318f4fd4
secret: ElkWgQETGKlfXTH8GiEDc8jOYMpD65pZ
sha_link: true
when:
status: [failure, success]
volumes: # 挂载,持久化数据
- name: pkgdeps
host:
path: /tmp/pkg/repotest