-
Notifications
You must be signed in to change notification settings - Fork 4
/
.drone.yml
150 lines (141 loc) · 6.84 KB
/
.drone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
kind: pipeline # 定义对象类型,还有secret和signature两种类型
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
name: gohu # 定义流水线名称
# 定义流水线宿主机挂载目录,用于共享数据
volumes:
- name: build
host:
path: /tmp/build # 从宿主机中挂载的目录
steps: # 定义流水线执行步骤,这些步骤将顺序执行
# 方式一:
# 将仓库打包发送给目标主机,目标主机然后构建镜像
- name: scp
image: appleboy/drone-scp # SSH工具镜像
# 参数说明: https://plugins.drone.io/plugins/scp
settings:
host:
from_secret: ssh_ip # 远程连接地址
port: 22 # 远程连接端口
username: root # 远程连接账号
key:
from_secret: ssh_password # 从Secret中读取SSH密码
# command_timeout: 5m # 远程执行命令超时时间
# envs:
# - PROJECT_NAME
# - DOMAIN
# - APOLLO_APP_ID
# - APOLLO_CLUSTER_NAME
# - APOLLO_IP
# - APOLLO_SECRET
tar_tmp_path: /tmp/tar
overwrite: true
rm: true
source:
- ./
target: /www/site/gohu
# 方式二:
# 将仓库代码构建成镜像后发送给镜像仓库
# 然后目标主机拉取镜像
# - name: build # 流水线名称
# image: golang:1.19.0-alpine3.16 # 定义创建容器的Docker镜像
# # 定义容器挂载目录
# volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
# - name: build
# path: /build
# environment:
# PROJECT_NAME:
# from_secret: project_name
# GO111MODULE: on
# CGO_ENABLED: 0
# GOOS: linux
# GOARCH: amd64
# GOPROXY: 'https://goproxy.cn,direct'
# commands: # 定义在Docker容器中执行的shell命令
# - echo '----------build go----------'
# - go build -o ./app/service/oauth/api/gohu-oauth-api -v ./app/service/oauth/api/oauth.go
# - go build -o ./app/service/oauth/rpc/token/enhancer/gohu-oauth-token-enhancer-rpc -v ./app/service/oauth/rpc/token/enhancer/token_enhancer.go
# - go build -o ./app/service/oauth/rpc/token/store/gohu-oauth-token-store-rpc -v ./app/service/oauth/rpc/token/store/token_store.go
# - go build -o ./app/service/user/api/gohu-user-api -v ./app/service/user/api/user.go
# - go build -o ./app/service/user/rpc/crud/gohu-user-crud-rpc -v ./app/service/user/rpc/crud/crud.go
# - go build -o ./app/service/user/rpc/vip/gohu-user-vip-rpc -v ./app/service/user/rpc/vip/vip.go
# - echo '----------complete----------'
# - echo '----------packing----------'
# - tar -czvf $PROJECT_NAME.tar.gz ./*
# - chmod 777 ./$PROJECT_NAME.tar.gz
# - cp ./$PROJECT_NAME.tar.gz /build
# - echo '----------complete----------'
# 运行镜像
- name: run
image: appleboy/drone-ssh # SSH工具镜像
# 从drone中提取secret到环境变量中
environment:
PROJECT_NAME:
from_secret: project_name
DOMAIN:
from_secret: domain
APOLLO_APP_ID:
from_secret: apollo_app_id
APOLLO_CLUSTER_NAME:
from_secret: apollo_cluster_name
APOLLO_IP:
from_secret: apollo_ip
APOLLO_SECRET:
from_secret: apollo_secret
# 参数说明: https://plugins.drone.io/plugins/ssh
settings:
host:
from_secret: ssh_ip # 远程连接地址
port: 22 # 远程连接端口
username: root # 远程连接账号
key:
from_secret: ssh_password # 从Secret中读取SSH密码
command_timeout: 20m # 远程执行命令超时时间
envs:
- PROJECT_NAME
- DOMAIN
- APOLLO_APP_ID
- APOLLO_CLUSTER_NAME
- APOLLO_IP
- APOLLO_SECRET
script:
- bash
- source ~/.bashrc
- cd /www/site/$PROJECT_NAME
- ls
- env
- echo '----------build go----------'
- go build -o ./app/service/oauth/api/gohu-oauth-api ./app/service/oauth/api/oauth.go
- go build -o ./app/service/oauth/rpc/token/enhancer/gohu-oauth-rpc-token-enhancer ./app/service/oauth/rpc/token/enhancer/token_enhancer.go
- go build -o ./app/service/oauth/rpc/token/store/gohu-oauth-rpc-token-store ./app/service/oauth/rpc/token/store/token_store.go
- go build -o ./app/service/user/api/gohu-user-api ./app/service/user/api/user.go
- go build -o ./app/service/user/rpc/crud/gohu-user-rpc-crud ./app/service/user/rpc/crud/crud.go
- go build -o ./app/service/user/rpc/info/gohu-user-rpc-info ./app/service/user/rpc/info/info.go
- go build -o ./app/service/user/rpc/vip/gohu-user-rpc-vip ./app/service/user/rpc/vip/vip.go
- go build -o ./app/service/question/api/gohu-question-api ./app/service/question/api/question.go
- go build -o ./app/service/question/rpc/crud/gohu-question-rpc-crud ./app/service/question/rpc/crud/crud.go
- go build -o ./app/service/question/rpc/info/gohu-question-rpc-info ./app/service/question/rpc/info/info.go
- go build -o ./app/service/comment/api/gohu-comment-api ./app/service/comment/api/comment.go
- go build -o ./app/service/comment/rpc/crud/gohu-comment-rpc-crud ./app/service/comment/rpc/crud/crud.go
- go build -o ./app/service/comment/rpc/info/gohu-comment-rpc-info ./app/service/comment/rpc/info/info.go
- go build -o ./app/service/notification/api/gohu-notification-api ./app/service/notification/api/notification.go
- go build -o ./app/service/notification/rpc/crud/gohu-notification-rpc-crud ./app/service/notification/rpc/crud/crud.go
- go build -o ./app/service/notification/rpc/info/gohu-notification-rpc-info ./app/service/notification/rpc/info/info.go
- go build -o ./app/service/mq/asynq/scheduler/gohu-mq-asynq-scheduler ./app/service/mq/asynq/scheduler/scheduler.go
- go build -o ./app/service/mq/asynq/processor/gohu-mq-asynq-processor ./app/service/mq/asynq/processor/processor.go
- go build -o ./app/service/mq/nsq/consumer/gohu-mq-nsq-consumer ./app/service/mq/nsq/consumer/consumer.go
- chmod 777 ./app/service/mq/nsq/consumer/gohu-mq-nsq-consumer
- echo '----------complete----------'
- echo '----------export envs----------'
- export APOLLO_APP_ID=$APOLLO_APP_ID
- export APOLLO_CLUSTER_NAME=$APOLLO_CLUSTER_NAME
- export APOLLO_IP=$APOLLO_IP
- export APOLLO_SECRET=$APOLLO_SECRET
- echo '----------complete----------'
- echo '----------docker compose----------'
- docker-compose down --rmi all
- echo '----------build docker image----------'
- chmod 775 ./build.sh
- ./build.sh $PROJECT_NAME 19
- echo '----------complete----------'
- docker-compose up -d
- echo '----------complete----------'