josmo / drone-rancher

Drone plugin for triggering Rancher deployments
53 stars 35 forks source link

ability to update multiple services #11

Closed zacksiri closed 6 years ago

zacksiri commented 8 years ago

Sometimes you have multiple services running from 1 docker image, and woudl be nice to be able to update multiple services

bradrydzewski commented 8 years ago

In the short term you can add multiple rancher blocks to the yaml like this:

deploy:
  rancher:
    url: https://example.rancher.com
    service: drone/drone
    docker_image: drone/drone:latest
  rancher:
    url: https://example.rancher.com
    service: drone/drone
    docker_image: drone/drone:latest

If you are interested in the ability to update multiple services in a single block feel free to send a pull request with the functionality. I'm the core drone maintainer and I've never used Rancher -- so we rely on pull requests from the community for these sort of improvements. Cheers!

josmo commented 7 years ago

@zacksiri I'm looking over the open issues with the plugin and wondered if with the option @bradrydzewski mentioned, does it still makes sense to add multiple service upgrades due to the complexity it adds. ie. batch size, auto-upgrades, etc are often times different per services even if based on the same image. I can add the above to the docs and that should hit all use cases unless I'm missing something :)

shnhrrsn commented 6 years ago

@josmo This would be helpful in terms of keep everything DRY.

Take for instance the following config:

pipeline:

  # ...

  deploy_api:
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    service: stack/service
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: true
    confirm: true
    timeout: 300
    batch_size: 1
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

  deploy_scheduler:
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    service: stack/service-scheduler
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: false
    confirm: true
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

  deploy_queue:
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    service: stack/service-queue
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: false
    confirm: true
    batch_size: 5
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

  deploy_queue_high:
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    service: stack/service-queue-high
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: false
    confirm: true
    batch_size: 5
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

  deploy_queue_low:
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    service: stack/service-queue-low
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: false
    confirm: true
    batch_size: 5
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

It's super repetitive and if you want to change one of the more 'global' values, you need to change it in multiple spots, which can of course be fairly error prone. Refactoring the above to a single step with multiple services would be great:

pipeline:

  # ...

  deploy:
    url: https://rancher.…
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    secrets: [ rancher_access_key, rancher_secret_key ]
    services:
      - service: stack/service
        start_first: true
        confirm: true
        timeout: 300
        batch_size: 1
      - service: stack/service-scheduler
        start_first: false
        confirm: true
      - service: stack/stack/service-queue
        start_first: false
        confirm: true
        batch_size: 5
      - service: stack/stack/service-queue-high
        start_first: false
        confirm: true
        batch_size: 5
      - service: stack/stack/service-queue-low
        start_first: false
        confirm: true
        batch_size: 5
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]
bradrydzewski commented 6 years ago

@shnhrrsn have you considered using YAML anchors to reduce boilerplate? I believe this can be handled at the YAML level without having to change the plugin itself.

deploy: &deploy
    group: deploy
    image: peloton/drone-rancher
    url: https://rancher.…
    docker_image: "image:${DRONE_BRANCH}.${DRONE_COMMIT_SHA:0:8}"
    start_first: true
    confirm: true
    timeout: 300
    batch_size: 1
    secrets: [ rancher_access_key, rancher_secret_key ]
    when:
      branch: [ production ]
      event:
        exclude: [ pull_request ]

pipeline:
  deploy_api:
    <<: *deploy
    service: stack/service

  deploy_scheduler:
    <<: *deploy
    service: stack/service-scheduler
shnhrrsn commented 6 years ago

I'll give that a try, thanks for the quick reply!

walks away in shame

josmo commented 6 years ago

@shnhrrsn I just wanted to check if what Brad mentioned would work :) If it does I'm going to close this out.

shnhrrsn commented 6 years ago

Yep, worked perfect!

josmo commented 6 years ago

Glad to hear!