@Kais(VagrantPi)
Drone
, CI/CD
, 簡報
Bitbucket 設定 > View profile > OAuth
詳細步驟可以直接參考上面第一篇連結,或是看我寫的
Re: 從零開始的 CI 生活 - Drone
version: '2'
services:
drone-server:
image: drone/drone:0.8
ports:
- 80:8000
- 9000
volumes:
- /var/lib/drone:/var/lib/drone/
restart: always
environment:
- DRONE_OPEN=true
# drone-server IP,如果要在 local 端測試,可以使用 ngrok
- DRONE_HOST=${DRONE_HOST}
# Set to true to enable the Bitbucket driver.
+ - DRONE_BITBUCKET=true
# Bitbucket oauth2 client id
+ - DRONE_BITBUCKET_CLIENT=${DRONE_BITBUCKET_CLIENT}
# Bitbucket oauth2 client secret
+ - DRONE_BITBUCKET_SECRET=${DRONE_BITBUCKET_SECRET}
# drone server 與 agent 溝通的 secret key
- DRONE_SECRET=${DRONE_SECRET}
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=drone-server:9000
# 跟上面的一樣
- DRONE_SECRET=${DRONE_SECRET}
services:
drone-server:
image: drone/drone:0.8
environment:
+ - DRONE_OPEN= true
+ - DRONE_ORGS: kaislin,joe_hsu
services:
drone-server:
image: drone/drone:0.8
environment:
- - DRONE_OPEN=true
+ - DRONE_OPEN=false
+ - DRONE_ADMIN=kaislin,joe_hsu
這樣只能透過 admin 去手動添加 user
drone user add <username>
跟 docker-compose 有 87% 像
workspace:
base: /go/src
path: hello-drone
clone:
git:
image: plugins/git
tags: true
services:
database:
image: mongo:4.0.2
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
- MONGO_INITDB_DATABASE=MYDB
$ drone secret add \
--name MONGO_INITDB_ROOT_USERNAME \
--value admin \
--image mongo:4.0.2 \
--repository kaislin/hello-drone
or
services:
database:
image: mongo:4.0.2
+ secrets: [ MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD]
environment:
- - MONGO_INITDB_ROOT_USERNAME=admin
- - MONGO_INITDB_ROOT_PASSWORD=admin
- MONGO_INITDB_DATABASE=MYDB
test:
image: golang:1.9.4
volumes:
- /home/ubuntu/hello-drone-config:/etc/mrt
commands:
- cp -rf config/hello-drone/router /hello-drone/mrt/
- cp -rf config/hello-drone/smtp /hello-drone/mrt/
- go test ./...
- go test -cover
pipeline:
backend:
+ group: build
image: golang
commands:
- go build
- go test
frontend:
+ group: build
image: node
commands:
- npm install
- npm run test
- npm run build
publish:
image: plugins/docker
repo: octocat/hello-world
pipeline:
build:
image: golang
commands:
- go build
- go test
-branches: master
-branches: [ master, develop ]
+branches: [ master, feature/* ]
pipeline:
build:
image: golang
commands:
- go build
- go test
+branches:
+ include: [ master, feature/* ]
pipeline:
build:
image: golang
commands:
- go build
- go test
+branches:
+ exclude: [ develop, feature/* ]
when:
event: tag
用法跟 docker-compose 差不多
pipeline:
build:
image: docker
commands:
- docker build --rm -t octocat/hello-world .
- docker run --rm octocat/hello-world --test
- docker push octocat/hello-world
- docker rmi octocat/hello-world
volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
pipeline:
build:
image: golang
+ environment:
+ - CGO=0
+ - GOOS=linux
+ - GOARCH=amd64
commands:
- go build
- go test
pipeline:
build:
image: golang
commands:
- go build
- go test
publish:
image: plugins/docker
registry: registry.heroku.com
repo: registry.heroku.com/my-staging-app/web
when:
+ event: deployment
+ environment: staging
publish_to_prod:
image: plugins/docker
registry: registry.heroku.com
repo: registry.heroku.com/my-production-app/web
when:
+ event: deployment
+ environment: production
部署使用 command line
drone deploy <repo> <build> <environment>
指定部署 24 到 staging 環境
drone deploy octocat/hello-world 24 staging
指定部署 24 到 production 環境
drone deploy octocat/hello-world 24 production
使用前須先從 web UI 拿到 token 才能夠透過 command 戳 drone
drone build start kaislin/hello-drone 36
drone build stop kaislin/hello-drone 36
deploy-production:
image: appleboy/drone-ssh
pull: true
host: <host ip>
username: <username>
secrets: [ ssh_password ]
script:
- docker pull XXX.XXX.XXX.XXX:5000/hello-drone
- docker tag XXX.XXX.XXX.XXX:5000/hello-drone hello-drone:latest
- cd /home/ubuntu/hello-drone/docker
- docker-compose down
- docker-compose up -d
when:
branch: develop
event: deployment
slack:
image: plugins/slack
channel: drone_test
webhook: https://hooks.slack.com/services/.....
when:
status: [ success, failure ]
如 node_module 或 vendor 之類的資料希望能夠 cache
restore-cache:
image: drillster/drone-volume-cache
restore: true
mount:
- ./vendor
volumes:
- /tmp/cache:/cache
dependency:
image: marcelocorreia/go-glide-builder
commands:
- sh docker/glide_install.sh
rebuild-cache:
image: drillster/drone-volume-cache
rebuild: true
mount:
- ./vendor
volumes:
- /tmp/cache:/cache