Drone文件示例:
.drone.yml
kind: pipeline
type: docker
name: project-go-api
#设置挂载
volumes:
  #Go编译缓存
  - name: pkgdeps
    host:
      path: /tmp/drone/cache/project-go-api/cache
  #Docker环境
  - name: docker
    host:
      path: /var/run/docker.sock
  #Docker配置
  - name: docker-daemon
    host:
      path: /etc/docker/daemon.json
#构建步骤
steps:
  #设置缓存
  - name: clean
    image: docker:19.03.1
    network_mode: host
    # 将宿主机的 docker和配置挂载到运行的 docker 容器中,那么在容器中运行 docker 命令时,等同于在宿主机中运行该docker 命令
    volumes:
      - name: docker
        path: /var/run/docker.sock
      - name: images
        path: /images
      - name: docker-daemon
        path: /etc/docker/daemon.json
  #构建镜像
  - name: build
    image: golang:1.18.10-alpine
    pull: if-not-exists
    volumes:
      - name: pkgdeps
        path: /go/pkg
    environment:
      GOPROXY: "https://goproxy.cn,direct"
    commands:
      - CGO_ENABLED=0 go build -o jxb-prod
  #推送镜像至镜像仓库
  - name: publish
    image: plugins/docker
    pull: if-not-exists
    volumes:
      - name: docker
        path: /var/run/docker.sock
      - name: pkgdeps
        path: /cache
    settings:
      purge: false
      insecure: true
      privileged: true
      registry: xxxxx.com #我这里用的harbor 可以自行替换用阿里云或其他都可
      repo: xxxxx.com/gw/jxb-adult
      tags:
        - latest
        - sha_${DRONE_COMMIT_SHA}
      username:
        from_secret: harbor_user
      password:
        from_secret: harbor_pwd
      use_cache: true
    when:
      status:
        - "success"
#部署镜像服务
  - name: ssh commands
    image: appleboy/drone-ssh
    pull: if-not-exists
    settings:
      host:
        from_secret: ssh_ip
      port: 22
      username:
        from_secret: ssh_user_name
      password:
        from_secret: ssh_password
      script:
        - cd /home/jxb-adult
        - docker-compose down
        - docker rmi xxxxxx/gw/jxb-adult:latest #这里为镜像地址
        - docker-compose pull && docker-compose up --force-recreate -d
  #钉钉通知 这一步可以自行替换成其他的
  - name: notify
    pull: if-not-exists
    image: guoxudongdocker/drone-dingtalk:latest
    settings:
      token: 03xxxxx0ed392xxxxxxxxxxxxxxxxxxxx6612a1ab934c78
      type: markdown
      message_color: true
      message_pic: true
      sha_link: true
    when:
      status: [ failure, success ]
该drone文件适用于golang的程序 所有配置可根据自动业务进行调整
效果图
 
