Gogs+Drone实现自动化部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gogs+Drone实现自动化部署相关的知识,希望对你有一定的参考价值。
参考技术A 最近产品希望把PRD部署到服务器上,方便大家查看,为了让产品可以方便的把PRD部署到服务器上,于是想到了自动部署,但是公司用的Jenkins,感觉过于雍总,而且对于环境还有些要求,所以我就想到了自建持续集成服务,这时候,Gogs+Drone的组合就很方便了。参考 使用Docker + Gogs搭建git私服
Drone也使用docker安装
先启动drone server
再启动runner,我这儿是用的ssh执行器,具体用啥执行器,根据业务自定判定
至此,环境搭建就好了,接下来就是配置自动部署了
因为我的服务器上已经安装了nginx,我这边需要做的事情就是每次产品提交prd后,将对应的文件复制到nginx的目录下,所以我这儿是通过shell命令来操作的
drone通过在仓库中添加 .drone.yml 来实现自定义流程,具体配置可以参考drone官方文档
附上我的文件
持续部署平台搭建
https://gogs.io/
https://drone.io/
https://goharbor.io/
gogs+drone+harbor方式构建,不哆嗦直接上
安装docker
curl -sSL https://get.daocloud.io/docker | sh
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
curl -L https://github.com/docker/compose/releases/download/1.23.0-rc3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
卸载docker
# 卸载Docker CE
#sudo apt-get purge docker-ce
# 卸载Docker EE
#sudo apt-get purge docker-ee
# 删除Docker镜像、容器、数据卷等文件
#sudo rm -rf /var/lib/docker
部署平台
version: '3'
services:
db:
image: postgres:10
hostname: gogs
hostname: gogs-db
container_name: gogs-db
restart: always
environment:
POSTGRES_PASSWORD: postgres
volumes:
- ./gogsdb:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
cinet:
ipv4_address: '172.72.72.72'
gogs:
image: gogs/gogs
hostname: gogs
container_name: gogs
restart: always
volumes:
- ./gogs:/data
ports:
- "8022:22"
- "3000:3000"
networks:
cinet:
ipv4_address: '172.72.72.69'
depends_on:
- db
drone-server:
image: drone/drone:1.3.1
hostname: drone
container_name: drone
restart: always
ports:
- "9000:80"
networks:
cinet:
ipv4_address: '172.72.72.96'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_RUNNER_CAPACITY=2
- DRONE_DEBUG=true
- DRONE_OPEN= false
- DRONE_LOGS_TRACE=true
- DRONE_TLS_AUTOCERT=false
- DRONE_AGENTS_ENABLED=true
- DRONE_GIT_ALWAYS_AUTH=false
- DRONE_GOGS_SERVER=http://172.72.72.69:3000
- DRONE_RPC_SECRET=123456
- DRONE_SERVER_PROTO=http
- DRONE_SERVER_HOST=172.72.72.96
- DRONE_DATABASE_DRIVER=postgres
- DRONE_DATABASE_DATASOURCE=postgres://drone:password@172.72.72.72:5432/drone?sslmode=disable
drone-agent:
image: drone/agent:latest
hostname: drone-agent
container_name: drone-agent
restart: always
networks:
cinet:
ipv4_address: '172.72.72.99'
environment:
- DRONE_DEBUG=true
- DRONE_RPC_PROTO=http
- DRONE_RPC_SERVER=http://172.72.72.96:80
- DRONE_RPC_SECRET=123456
- DRONE_RUNNER_CAPACITY=2
- DRONE_RUNNER_NAME=agent
volumes:
- /etc/localtime:/etc/localtime
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- drone-server
networks:
cinet:
ipam:
driver: default
config:
- subnet: 172.72.72.0/16
Pipeline
---
kind: pipeline
type: docker
name: build
clone:
git clone:
image: plugins/git
skip_verify: true
workspace:
base: /app
path: .
pipeline:
build& push:
image: plugins/docker
username: username
password:
from_secret: password
debug: true
build_args:
- ENV=prod
tag:
- $CI_COMMIT_SHA:0:10
insecure: true
dockerfile: cicd/Dockerfile
registry: harbor-repo-url
repo: image-url
when:
branch: master
event: [push,tag]
pipeline:
notification:
image: guoxudongdocker/drone-dingtalk
token:
from_secret: password
type: markdown
message_color: true
message_pic: true
sha_link: true
when:
status: [success, failure]
以上是关于Gogs+Drone实现自动化部署的主要内容,如果未能解决你的问题,请参考以下文章
2022-03-12:k8s如何搭建gogs+drone实现自动化部署cicd,yaml如何写?
再见 Jenkins !几行脚本搞定自动化部署,这款神器有点厉害!
再见 Jenkins!几行脚本搞定自动化部署,这款神器有点厉害