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.
135 lines
3.2 KiB
135 lines
3.2 KiB
kind: pipeline
|
|
type: docker
|
|
name: TEST
|
|
|
|
platform:
|
|
os: linux
|
|
arch: amd64
|
|
|
|
steps:
|
|
# 使用缓存进行存储
|
|
- name: restore-cache
|
|
image: meltwater/drone-cache
|
|
pull: always
|
|
settings:
|
|
backend: "filesystem"
|
|
restore: true
|
|
cache_key: '{{ .Repo.Name }}_{{ checksum "go.mod" }}_{{ checksum "go.sum" }}_{{ arch }}_{{ os }}'
|
|
archive_format: "gzip"
|
|
filesystem_cache_root: "/tmp/repotest"
|
|
mount:
|
|
- pkg.mod
|
|
- pkg.build
|
|
volumes:
|
|
- name: cache
|
|
path: /tmp/repotest
|
|
|
|
# golang 编译
|
|
- name: build
|
|
image: golang:1.17
|
|
pull: if-not-exists
|
|
environment:
|
|
GO111MODULE: "on"
|
|
GOPROXY: "https://goproxy.io"
|
|
CGO_ENABLED: 1
|
|
GOMODCACHE: '/drone/src/pkg.mod'
|
|
GOCACHE: '/drone/src/pkg.build'
|
|
commands:
|
|
- go build -ldflags "-w -s" -o /tmp/carp main.go
|
|
volumes:
|
|
- name: cache
|
|
path: /tmp/repotest
|
|
when:
|
|
event:
|
|
- push
|
|
- tag
|
|
|
|
# 缓存编译
|
|
- name: rebuild-cache
|
|
image: meltwater/drone-cache
|
|
pull: if-not-exists
|
|
settings:
|
|
backend: "filesystem"
|
|
rebuild: true
|
|
cache_key: '{{ .Repo.Name }}_{{ checksum "go.mod" }}_{{ checksum "go.sum" }}_{{ arch }}_{{ os }}'
|
|
archive_format: "gzip"
|
|
filesystem_cache_root: "/tmp/repotest"
|
|
mount:
|
|
- pkg.mod
|
|
- pkg.build
|
|
volumes:
|
|
- name: cache
|
|
path: /tmp/repotest
|
|
|
|
# 发布,编译镜像并推送到私有镜像仓库
|
|
- 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工具镜像
|
|
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: cache
|
|
temp: {}
|