GitLab + Drone 构建 CI&CD 环境
环境
操作系统: Centos 7.4
Docker版本: 17.03
Docker-Compose版本: 1.22
搭建Drone
- Gitlab生成ClientID与Secret
- 构建docker-compose.yaml
version: '2'
services:
drone-server:
image: drone/drone:0.8
ports:
- 8000:8000
- 9000
volumes:
- /home/data1/drone/drone-data:/var/lib/drone/
restart: always
environment:
- DRONE_OPEN=true
- DRONE_GITLAB=true
- DRONE_GITLAB_CLIENT=3b026a57ef85bd05181a670ad32ded6b0d58e711e81c79864fd4801569e1c580 # 这个在Gitlab UserSettings/Application 中生成
- DRONE_GITLAB_SECRET=2bb590a29eb0de0ad345811da5253527d33c2c166ecf8bff17480396c8e7dff5 # 这个在Gitlab UserSettings/Application 中生成
- DRONE_GITLAB_URL=http://gitlab.dev # gitlab地址
- DRONE_HOST=http://drone.dev # drone地址
- DRONE_SECRET=123456
drone-agent:
image: drone/agent:0.8
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_SERVER=drone-server:9000
- DRONE_SECRET=123456
- 启动Drone
docker-compose up -v
授权
点击授权即可
开启CI & CD
Drone CI&CD的配置
用过Travis CI你肯定也会很快掌握 Drone CI的配置,大同小异
教程已Laravel为例子
你需要在项目根目录建立.drone.yml
文件
pipeline:
backend:
image: motecshine/laravelphp71
commands:
- composer install
- cp .env.example .env
- php artisan key:generate
- ./vendor/bin/phpunit
- rm -rf vendor
# - git tag ${DRONE_COMMIT_SHA} #这里打上tag
# - git push origin ${DRONE_COMMIT_SHA} # 提交这个tag
frontend:
image: node:8
commands:
- npm install
- npm audit fix
- npm run prod
- rm -rf node_module
#publish:
# 这里完成CD, 也许你还需要一个 Deploy镜像去完成你的部署工作,步骤都一样,这里就不详细谈了、
大功告成
上面被注释掉的是关于CD的步骤,这里就不详细叙述了,Drone 相比于Jenkins来说简单易用,已部署,轻量,适合小型的开发团队。
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由系统于 5年前 自动加精
推荐文章: