drone技术也要去运维

Drone Gogs自动构建

2017-02-21  本文已影响654人  SetZero

一、前提条件

二、安装Gogs、Drone

version: '2'

services:
  gogs:
    image: registry.saas.hand-china.com/tools/gogs:latest
    ports:
      - "10022:22"
      - 10080:3000
    volumes:
      - /vagrant/gogs-data:/data
    restart: always
  mysql:
    image: registry.saas.hand-china.com/tools/mysql:5.7.12
    ports:
      - 3306:3306
    volumes:
      - /vagrant/mysql-data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=gogs
  drone-server:
    image: registry.saas.hand-china.com/tools/drone:0.5
    ports:
      - 80:8000
    volumes:
      - /var/lib/drone:/var/lib/drone
    restart: always
    environment:
      # 开启注册,此配置允许任何人自注册和登录系统
      - DRONE_OPEN=true
      # 设置管理员用户
      - DRONE_ADMIN=adminuser
      # 开启Gogs驱动
      - DRONE_GOGS=true
      # Gogs服务器地址
      - DRONE_GOGS_URL=http://192.168.56.21:10080
      # 此SECRET为任意值
      - DRONE_SECRET=handhand
  drone-agent:
    image: registry.saas.hand-china.com/tools/drone:0.5
    command: agent
    restart: always
    depends_on: [ drone-server ]
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      # Drone Server 地址
      - DRONE_SERVER=ws://192.168.56.21/ws/broker
      # 与Drone Server一致即可
      - DRONE_SECRET=handhand

上图配置了名为demo项目触发Push事件时进行自动构建。

三、安装Drone CLI

wget http://downloads.drone.io/release/linux/amd64/drone.tar.gz | tar zx
sudo install -t /usr/local/bin drone
# drone-server地址
export DRONE_SERVER=http://192.168.56.21
# token刚才drone的管理界面account中点show_token
export DRONE_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.p2KhqJ-hl7lVdWawKtowBucWRANmYLv6ZqY64-gE660

四、自动构建yml文件配置

workspace:
  base: /go
  path: src/192.168.56.21/adminuser/demo

pipeline:
  build:
    image: registry.saas.hand-china.com/tools/golang:latest
    commands:
      - go get
      - go build
      #- go test

services:
  postgres:
    image: registry.saas.hand-china.com/tools/postgres:9.4.5
    environment:
      - POSTGRES_USER=myapp
上一篇下一篇

猜你喜欢

热点阅读