链接:https://zhuanlan.zhihu.com/p/24896056
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
这是参加Rancher 深圳站线下活动时候的一个演示项目
现在贴一下整个的步骤,供大家参考~
一,Git
可选的git系统如下,示例用gogs
- Gogs
- Gitlab
- Github
Gogs,Docker-Compose安装:
```version: '2'services: app: image: gogs/gogs:0.9.113 ports: - "10022:22" - "10080:3000" volumes: - ./gogs:/data restart: always links: - mysql:mysql environment: - Domain=${GOGS_IP} - SSH_PORT=${GOGS_SSH_PORT} mysql: image: mysql:5.7.13 restart: always volumes: - ./mysql:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE=gogs```
# envexport MYSQL_ROOT_PASSWORD={mysql_root_password}export GOGS_IP={ip}export GOGS_SSH_PORT=10022export GOGS_HTTP_PORT=10080# rundocker-compose up -d
浏览器打开:http:{ip}:{http_port} 完成安装
登录后创建测试项目:alpine-drone
二,Drone CI
Drone,Docker-compose安装(Gogs):
version: '2'services: drone-server: image: thonatos/alpine-drone # 换成drone/drone:0.5.0 ports: - 80:8000 volumes: - ./drone:/var/lib/drone/ restart: always environment: - DRONE_OPEN=true - DRONE_DEBUG=false - DRONE_GOGS=true - DRONE_GOGS_URL=http://${GOGS_IP}:${GOGS_HTTP_PORT} - DRONE_GOGS_PRIVATE_MODE=true - DRONE_GOGS_SKIP_VERIFY=true - DRONE_SECRET=${DRONE_SECRET} # - DRONE_ADMIN=suyi drone-agent: image: thonatos/alpine-drone # 换成drone/drone:0.5.0 command: agent restart: always depends_on: [ drone-server ] volumes: - /var/run/docker.sock:/var/run/docker.sock environment: - DRONE_SERVER=ws://drone-server:8000/ws/broker - DRONE_SECRET=${DRONE_SECRET}
Drone,Docker-compose安装(Github):
version: '2'services: drone-server: image: drone/drone:0.5.0 environment: DRONE_GITHUB: true DRONE_GITHUB_CLIENT: 95c0282573633eb25e82 DRONE_GITHUB_SECRET: 30f5064039e6b359e075
运行Drone:
# envexport DRONE_SECRET={secret}# rundocker-compose up -d
浏览器打开:http://{ip}:{drone_port},使用安装gogs设置的管理员账号密码登录,点击右侧account看到当前项目,点开项目旁边的构建选项即可
三,配置Docker自动构建
下载并配置 drone cli:
# macbrew tap drone/dronebrew install drone --devel# http://readme.drone.io/usage/getting-started-cli/# 下载并配置到PATH中# runexport DRONE_SERVER=http://drone.mycompany.comexport DRONE_TOKEN={} # token刚才drone的管理界面account中点show_token
在项目内创建.drone.yml文件,内容如下:
pipeline: docker: # registry: {} # 私有registry地址 # auth: {} # auth_token image: plugins/docker repo: thonatos/alpine-drone # 修改为你对应的repo名字 tags: latest # tags