drone实践记录

drone组成:

1、drone-server 主服务,对接git server的 webhook ,解析流水线配置yml,web管理界面,路由并管理runner

2、drone-runner 运行流水线,有多种runner,docker,裸机,k8s

3、drone-plugin 插件,改变默认的运行方式

drone部署:

1、drone-server 需要配置好对接的git server

2、drone-runner 需要配置好对接的drone-serve

3、drone-plugin 可选非必须
a、一种是配合runner,server的,需要在部署的时候和runner对应,在docker-compose写好配置即可
b、一种是在流水线运行的时候调用,直接在流水线里用即可

drone流水线:

step 步骤

每个步骤调用一个docker镜像

比如:

  - name: test # 步骤名称 必须
    image: daocloud.io/xxxxx/php7.2:1.0.0  # 使用的镜像 必须
    environment: # 设置环境变量 可选
      GOOS: windows
      CGO_ENABLED:0 
      GOOS:linux 
      GOARCH:amd64
    commands: # 命令 必须 
      - go build
    when: # 简单的逻辑条件  可选
      event:
       - tag  

drone插件:

http://plugins.drone.io/

drone秘钥管理:

在dron里拉镜像是内置的,推镜像是插件提供的,所以要配置两个秘钥

1、拉秘钥

两种管理方式,推荐使用第二种方式

一、每个仓库设置一次

先在本机docker login,会有一个config.json, cat ~/.docker/config.json
在drone的管理界面把config.json的内容填入,并勾选allow如图:

在.drone.yml里最后添加下面的配置

image_pull_secrets:
  - dockerconfig  # 和在web界面配置的一样

二、全局设置,使用 drone/registry-plugin
在部署dorne的时候配置好

  drone-registry-plugin:
      image: drone/registry-plugin
      container_name: drone-registry-plugin
      ports:
        - 3030:3000
      environment: 
        - DRONE_DEBUG=true 
        - DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 
        - DRONE_CONFIG_FILE=/etc/registry_config.yml 
      volumes: 
        - /data/test/drone/registry_config.yml:/etc/registry_config.yml

其中registry_config.yml的配置如下,可以配置多项

- address: daocloud.io
  username: xxxxx
  password: xxxxxx

2、推秘钥

drone流水线并不内置docker镜像打包的操作,而是使用插件 plugins/docker ,默认是推送到docker.io
推送到自定义仓库设置如下:


  - name: docker  
    image: plugins/docker
    settings:
      username: xxxx@qq.com
      password: 
        from_secret: aliyun_pwd
      repo:  registry.cn-hangzhou.aliyuncs.com/xxx/abcd
      registry: registry.cn-hangzhou.aliyuncs.com
      auto_tag: true
      dockerfile: Dockerfile
      mirror: https://xxxx.mirror.aliyuncs.com

这个使用秘钥的方式如下:

drone缓存:

使用volume,必须在部署drone-runner的时候,就配置好。
在drone-runner的environment添加

 - DRONE_RUNNER_VOLUMES=/data/test/drone/cache:/data/cache # 宿主机目录,用于缓存

在.drone.yml里最后添加

volumes:
  - name: cache
    host:
      path: /tmp/cache/golang

使用方法:

  - name: build
    image: golang:1.13
    # pull: false
    commands:
      - export GOPROXY="http://mirrors.aliyun.com/goproxy/"
      - env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
    volumes:
      - name: cache
        path: /go  

其它设置

  • 镜像拉取方式 pull: if-not-exists

  • clone 深度,加快大仓库的构建

      clone:
         depth: 10
    
  • 流水线文档

posted @ 2020-03-20 15:56  半山th  阅读(1713)  评论(2编辑  收藏  举报