新版本的Drone CI分离成两个服务,drone和agent。agent依赖于drone。根据手册建议,新版使用docker-compose部署更加文便,但我的一直提示异常。

drone-agent_1   | rpc: error re-connecting: websocket: bad handshake
drone-server_1  | Unable to connect agent. Invalid authorization token "Bearer" does not match ""

细看文档之后才明白是DRONE_SECRET变量设置有问题,这个在drone和agent中要设置成一样的,两个服务才互相连接。然后使用docker-compose启用就可以访问了。

docker-compose -f drone-docker.yml -d up

下面是drone-docker.ymk文件的内容,供参考:

version: '2'

services:
    drone-server:
        image: drone/drone:latest
        ports:
            - 8000:8000
        volumes:
            - /var/lib/drone:/var/lib/drone/
        restart: always
        environment:
            - DRONE_OPEN=true
            - DRONE_HOST=http://192.168.2.12:8000
            - DRONE_GOGS=true
            - DRONE_GOGS_URL=http://192.168.2.12:3000
            - DRONE_SECRET="123456"
            - DRONE_GOGS_SKIP_VERIFY=true

    drone-agent:
        image: drone/drone:latest
        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="123456"
            - DOCKER_API_VERSION=1.22