drone ci 自动部署

839 阅读1分钟

介绍 项目官网 www.drone.io/ 基础服务配置

#配置基础容器 本文采用docker-compose配置 并使用github仓库
#docker-compose.yml
version: '2'
services:
  drone:
    networks:
      default:
        ipv4_address: 172.18.1.10
    environment:
      DRONE_GITHUB_CLIENT_ID: "xxx"
      DRONE_GITHUB_CLIENT_SECRET: "xxx"
      DRONE_RPC_SECRET: "xxx"
      DRONE_SERVER_HOST: "192.168.159.128"
      DRONE_SERVER_PROTO: "http"
      DRONE_USER_CREATE: "username:zhihuihu,machine:false,admin:true,token:55f24eb3d61ef6ac5e83d550178638dc"
      TZ: "Asia/Shanghai"
    image: "drone/drone:1"
    container_name: "drone"
    volumes:
      - "/var/lib/drone:/data"
    ports:
      - "4280:80"
      - "4281:443"
  drone-runner:
    networks:
      default:
        ipv4_address: 172.18.1.11
    environment:
      DRONE_RPC_PROTO: "http"
      DRONE_RPC_HOST: "192.168.159.128:4280"
      DRONE_RPC_SECRET: "xxx"
      DRONE_RUNNER_CAPACITY: "2"
      DRONE_RUNNER_NAME: "drone-runner"
      DRONE_RUNNER_NETWORKS: "huzhihui"
    image: "drone/drone-runner-docker:1"
    container_name: drone-runner
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
      - "4282:3000"
networks:
  default:
    external:
      name: huzhihui

按照上面配置启动容器 docker-compose up -d

编写.drone.yml

kind: pipeline
name: home
type: docker
steps:
  - name: build
    image: maven:3-jdk-8
    commands:
      - mvn install -Dmaven.test.skip=true
    volumes:
      - name: mvn-config
        path: /root/.m2
      - name: mvn-repo
        path: /usr/local/java/apache-maven-3.6.1/repo
  - name: docker-build-push
    image: plugins/docker
    settings:
      registry: 192.168.8.13#私服地址
      repo: 192.168.8.13/library/tomcat8
      username: #私服用户名称
      password: #私服密码
      use_cache: true
      insecure: true
      tags:
        - test

volumes:
  - name: mvn-config
    host:
      path: /usr/local/java/apache-maven-3.6.1/conf
  - name: mvn-repo
    host:
      path: /usr/local/java/apache-maven-3.6.1/repo

上面的配置包括项目打包和docker镜像打包并上传