Drone CI on Raspberry Pi

实验环境

  • Platform: Raspberry Pi
  • OS: Arch Linux Arm
  • Docker Engine: 1.12.0
  • Docker Compose: 1.8.0

实验过程

  • 启动4个docker容器
    • drone
    • gogs
    • mysql
    • phpmyadmin
  • 安装gogs: http://192.168.31.231:3000/
    • mysql:3306
    • domain:192.168.31.231
    • ssh:2222
    • http:3000
    • root:root
  • 配置gogs:
    • 添加SSH公钥
    • 创建GIT仓库: test
  • 重启drone (无法自动sync仓库)
  • 登录drone: http://192.168.31.231:8000/
    • root:root (同gogs)
  • 配置drone:
    • 激活GIT仓库: test
    • 获取SSH公钥
    • 拷贝SSH公钥: alarm@192.168.31.241:.ssh/authorized_keys
  • 克隆gogs:
    • git clone ssh://git@192.168.31.231:2222/root/test.git
    • cd test
    • vi .drone.yml
    • git add .drone.yml
    • git commit
    • git push
  • 打开drone: http://192.168.31.231:8000/root/test
    • 观察LOG
    • 查看/tmp/output

Docker Images

  • armdrone/drone
  • easypi/gogo-arm
  • easypi/mariadb-arm
  • easypi/phpmyadmin-arm

docker-compose.yml

drone:  
  image: armdrone/drone
  ports:
    - "8000:80"
  volumes:
    - ./data:/var/lib/drone
    - /var/run/docker.sock:/var/run/docker.sock
  environment:
    - REMOTE_DRIVER=gogs
    - REMOTE_CONFIG=http://192.168.31.231:3000/?open=false
    - PLUGIN_FILTER=armdrone/*
    - GIN_MODE=release
  restart: always

gogs:  
  image: easypi/gogs-arm
  ports:
    - "2222:22"
    - "3000:3000"
  volumes:
    - ./data:/data
  links:
    - mysql
  restart: always

mysql:  
  image: easypi/mariadb-arm
  ports:
    - "3306:3306"
  environment:
    - MYSQL_ROOT_PASSWORD=root
    - MYSQL_DATABASE=gogs
  restart: always

phpmyadmin:  
  image: easypi/phpmyadmin-arm
  ports:
    - "8080:80"
  environment:
    - PMA_HOST=mysql
    - PMA_PORT=3306
  links:
    - mysql
  restart: always

Sample .drone.yml

build:  
  image: easypi/alpine-arm
  commands:
    - date > output
    - echo hello >> output
    - echo world >> output

deploy:  
  rsync:
    user: alarm
    host: 192.168.31.231
    port: 22
    source: output
    target: /tmp/output

Build Log

[info] Pulling image armdrone/drone-plugin-base
[info] Pulling image armdrone/drone-git:latest
Drone Git Plugin built from  
$ git init
Initialized empty Git repository in /drone/src/192.168.31.231/root/test/.git/  
$ git remote add origin http://192.168.31.231:3000/root/test.git
$ git fetch --no-tags origin +refs/heads/master:
From http://192.168.31.231:3000/root/test  
* branch            master     -> FETCH_HEAD
* [new branch]      master     -> origin/master
$ git reset --hard -q c0b1534fe812f1c53abf0b0967718bdce1edad68
$ date > output
$ echo hello >> output
$ echo world >> output
[info] Pulling image armdrone/drone-rsync:latest
Drone Rsync Plugin built from  
$ rsync -az -e ssh -p 22 -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o StrictHostKeyChecking=no /drone/src/192.168.31.231/root/test/output alarm@192.168.31.231:/tmp/output

Build Result

$ cat /tmp/output
Mon Aug  1 09:41:11 GMT 2016  
hello  
world  

Drone CLI

$ curl http://downloads.drone.io/drone-cli/drone_linux_amd64.tar.gz | tar zx
$ mv drone /usr/local/bin/

$ export DRONE_SERVER=http://192.168.31.231:8000
$ export DRONE_TOKEN=xxxxxxxx

$ drone build list root/test
2  
1

$ drone build logs root/test 2 1
[info] Pulling image armdrone/drone-git:latest
Drone Git Plugin built from  
...

$ drone build start root/test 2
2  
pending

$ drone build stop root/test 2
stopping build 2 job 1

$ drone user ls
username        email           admin   active  
--------        -----           -----   ------
root        root@easypi.info    true    false  

参考资料