drone 脚本

部署go项目脚本

kind: pipeline
name: default

steps:

  - name: build
    image: golang:latest
    environment:
      GOPROXY: https://goproxy.cn,direct
    commands:
      - pwd
      - go version
      - go get -u github.com/swaggo/swag/cmd/swag
      - swag init
      - CGO_ENABLED=0 go build -o main
      - echo "build project success"
    when:
      event: push
      branch: [ develop,master ]

  # 定制镜像,镜像发布
  - name: structure
    image: plugins/docker
    settings:
      dockerfile: Dockerfile
      registry: registry.cn-hangzhou.aliyuncs.com
      repo: registry.cn-hangzhou.aliyuncs.com/yiui/shoptool
      username: username
      password: 123456
      tags:
        - 'latest'
      insecure: true
    volumes:
      - name: docker
        path: /var/run/docker.sock

  # 启动容器
#  - name: rancher-deploy
#    image: pelotech/drone-rancher  # drone-rancher插件,利用此插件来启动rancher
#    settings:
#      url: 'rancher-server:port'
#      access_key: username
#      secret_key: 123456
#      service: yiui/shoptool
#      docker_image: registry.cn-hangzhou.aliyuncs.com/yiui/shoptool:latest # 镜像地址及版本号
#      start_first: false
#      confirm: true
#      timeout: 305
#      volumes:
#        - name: docker
#          host:
#            path: /var/run/docker.sock
#      when:
#        branch: master



        #开发环境
  - name: dev scp files
    image: appleboy/drone-scp
    settings:
      host: 192.168.10.163
      username: dever
      password: dever
      port: 22
      target: /www/shop
      source:
        - main
        - config
        - shell_restart.sh
      script:
        - echo "copy file success"
    when:
      event: push
      branch: develop

  #部署正式环境
  - name: prod scp files
    image: appleboy/drone-scp
    settings:
      host: 192.168.10.202
      username: dever
      password: dever
      port: 22
      target: /www/shop
      source:
        - main
        - config
        - docker_restart.sh
        - Dockerfile
      script:
        - echo "copy file success"
    when:
      event: push
      branch: master


  #测试环境
  - name: dev ssh commands
    image: appleboy/drone-ssh
    settings:
      host: 192.168.10.163
      username: dever
      password: dever
      port: 22
      script_stop: true
      command_timeout: 5m
      script:
        - pwd
        - cd /www/shop
        - pwd
        - ls -al
        - chmod +x shell_restart.sh
        - ./shell_restart.sh 9999
    when:
      event: push
      branch: develop

  #正式环境
  - name: prod ssh commands
    image: appleboy/drone-ssh
    settings:
      host: 192.168.10.202
      username: dever
      password: dever
      port: 22
      script_stop: true
      command_timeout: 3m
      script:
        - pwd
        - cd /www/shop
        - chmod +x docker_restart.sh
        #端口,镜像 容器
        - ./docker_restart.sh 9999:9999  yiui/shop shop
        - echo "everything is fine "
    when:
      event: push
      branch: master


  #钉钉通知
  - name: dingtalk
    image: lddsb/drone-dingtalk-message
    settings:
      token: 59f6e8e74531f44db1a30e55ec01cb2908dc2afb19071db65
      type: markdown
      message_color: true
      message_pic: true
      sha_link: true
      secret: SEC78a04ba07c1009467a756186f4229b217aa8e6333769cecafd09d14bb4509
    when: #执行条件
      status:
        #        - success
        - changed
        - failure
branches: [ develop,master ]
View Code

 

posted @ 2020-09-29 21:04  jiuchen  阅读(266)  评论(0编辑  收藏  举报