travis-ci / dpl

Dpl (dee-pee-ell) is a deploy tool made for continuous deployment.
MIT License
1.29k stars 367 forks source link

Elastic Beanstalk: Deploy to different environments from different branches #266

Closed bennycode closed 8 years ago

bennycode commented 9 years ago

Hello,

We use the experimental Elastic Beanstalk deployment and it works really good. But it would be great if you could deploy to different Beanstalk environments based on the branch.

For example: We want to deploy our "staging" branch to our staging environment and our "production" branch to our production enviroment.

Our configuration at the moment looks like this:

deploy:
  edge: true
  skip_cleanup: true
  zip-file: 'aws/s3/ebs.zip'
  provider: elasticbeanstalk
  access-key-id: ...
  secret-access-key:
    secure: ...
  region: eu-west-1
  app: webapp
  bucket_name: webapp-bucket
  env: webapp-staging
  on:
    repo: organization/repository
    branch: staging

Can this configuration be extended to deploy the "production" branch to an env called webapp-production? Because we don't want to have 2 seperate .travis.yml files.

jasny commented 9 years ago

You can deploy to multiple providers or in this case the same provider twice with different settings.

deploy:
  - edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    provider: elasticbeanstalk
    access-key-id: ...
    secret-access-key:
      secure: ...
    region: eu-west-1
    app: webapp
    bucket_name: webapp-bucket
    env: webapp-staging
    on:
      repo: organization/repository
      branch: staging
  - edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    provider: elasticbeanstalk
    access-key-id: ...
    secret-access-key:
      secure: ...
    region: eu-west-1
    app: webapp
    bucket_name: webapp-bucket
    env: webapp-production
    on:
      repo: organization/repository
      branch: production

There no way around the duplicate settings at this moment afaik.

bennycode commented 9 years ago

Hey @jasny,

Thank you for your great tip! I've tried it and it works! However, I think that Travis gets a bit confused with having two declarations for provider: elasticbeanstalk. Because I have noticed, that if the "production" declaration is on top and I merge to "staging", then it reports: Skipping a deployment with the elasticbeanstalk provider because this branch is not permitted. Therefore, at first I thought that your approach is not working. But it is. :smile:

Travis just reports: "Skipping a deployment with the elasticbeanstalk provider because this branch is not permitted." if your branch does not match the branch declared in the first deployment declaration. I think that should be fixed. :grin:

But I am happy right now. Thank you!

My final configuration:

deploy:
  # Staging environment
  - provider: elasticbeanstalk
    edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    access-key-id: ...
    secret-access-key:
      secure: ...
    region: eu-west-1
    app: webapp
    env: webapp-staging
    bucket_name: webapp-bucket
    on:
      repo: organization/repository
      branch: staging

  # Production environment
  - provider: elasticbeanstalk
    edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    access-key-id: ...
    secret-access-key:
      secure: ...
    region: eu-west-1
    app: webapp
    env: webapp-production
    bucket_name: webapp-bucket
    on:
      repo: organization/repository
      branch: production
BanzaiMan commented 9 years ago

@bennyn Can I look at the build log in which you used 2 deploy targets? We should be going through each of them, and decide for each of them whether to run deployment or not.

bennycode commented 9 years ago

@BanzaiMan - Sure! Just drop me an email to benny@wire.com and we can discuss the details.

bennycode commented 8 years ago

Problem solved. :smiley:

dmichael commented 8 years ago

What was the final solution? I am seeing similar behavior in a deployment to elastic beanstalk with an array of providers. When the matched provider is the first in the array, Travis does do the deploy properly, but still reports Skipping a deployment with the elasticbeanstalk provider because this branch is not permitted

bennycode commented 8 years ago

@dmichael, our config file (.travis.yml) looks like this:

# https://github.com/travis-ci/dpl#elastic-beanstalk
deploy:
  - provider: elasticbeanstalk
    edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    access-key-id:
      secure: MpVUBkrtmIPqYLzrsYisYsE/UnOFU6q0ufgfWNBxHAFm/mDST9v+Kk1ZvhNKYskgMzJllQJBBqiRn05Fegam+DQ0oclbPr7Eg4mQrPbsrLIsc2qEpqw3fk8bqOssnHkKe1wlz7ihW3eQ78zOgsS/w95Zyd7wWiDzz8s7KvRPN8DLRGu2ksDdkPfM6RCbs9qsdSA5k8+DhZRXZCL/IHalE3plqOOJgCgTq9kzMRvxnFnVy0tLGzWQJvGOLYpjRwaAoqoLK7AX+WLfMSnBn+MuWCGmqPdk9Xto4cJnC5toASjNtu/bGYWuy4ShpzTivuwioJbxt5JGiq78j/MVu/5oBjzosJlSpNlY5++wrkLvfpkWMuJSC3/V40LkpLa+XF/MP18Bpbi44GmLTOCq4wJ/WRrYMAt4yQWURNJAv9tKqLyqgJ47HLBMEYABWUdr81apZm3ZKbqqmyu4GLclc7ivnVBjfmf5oDxMDUqp8owQO9YOsUX9t8Rw9XiPdasjx5EQ+EcvoAyBCPV6qlnFi7pj7wWnxu1DNhzxeW70BKhXizYwcBqSlvX88pbgCxc273Id0dAilrCgvD0/B2mvLPIVbJsscMyykjC7ZZOaznhfHQqeu/fXdfcVawVt+annovbFOWxjX5232ghbq12ux6qZ+2GNziW9vtEJeitPZ3XRPMc=
    secret-access-key:
      secure: aCiIP0To/YPm9E3G/q/JIHASRN0b69R23w8WYovmMsBFHddh0MBXnhh+Kf5Cuos+NdVatNs7mAqulLdmBF8TZhreEhLOd9PppEXPVXJrlvdDKejX3S6czUWD8tb4fSE4/qF9H8XYVa+Aznn/2Vlu3fFggAcAMv8lm7igTNb8rc2YZkaByNvwDjauoB1CwgvMsJiptDNy/m9EOJST9RqS/SDAFsPEFQLih0BRWbSYnEZ6yYtQ7T+ROOjjBxTefqf9E6s6PuXI9zrDzGtKE3mwibASts5lfVcKWBp/m1Droog7QxRgixUo9CoE4bK3tcSqpgBx/Mn1RL43C8pt2n2yxeXr6Rl1rdnpvVmz/7XbQqBtbX+atot63PKW4fuTlwCmnQfBWwsAqUZmnCHs0EgcFQR6VoO1D5FLKAWOFeo4RBCQ3mOr/kU3wTG0OrDVf3C1VpTD8W07AVIwcYm/jOSPJYgWwDk+OPz0f8UYbJTe8UO14LU/Wy6QT81cjEwjXJdCcv6IZS50iDNq9PxaACoOqAmfDZNwxuQBxN0kR1eWEobE+zucIfpa6OteA980X22xQIimPcVmmBcDjYce//o/12UNKZprUXeUqSPJsXWw8p3CIbJP8lI35aiTR3kjOG7XBG0QO1HyBHKudZHPGo3RU6dXVegu6POujy+oxbkQNyo=
    region: eu-west-1
    app: Webapp
    env: wire-webapp-dev
    bucket_name: wire-webapp
    on:
      repo: wireapp/wire-webapp
      branch: dev

  - provider: elasticbeanstalk
    edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    access-key-id:
      secure: MpVUBkrtmIPqYLzrsYisYsE/UnOFU6q0ufgfWNBxHAFm/mDST9v+Kk1ZvhNKYskgMzJllQJBBqiRn05Fegam+DQ0oclbPr7Eg4mQrPbsrLIsc2qEpqw3fk8bqOssnHkKe1wlz7ihW3eQ78zOgsS/w95Zyd7wWiDzz8s7KvRPN8DLRGu2ksDdkPfM6RCbs9qsdSA5k8+DhZRXZCL/IHalE3plqOOJgCgTq9kzMRvxnFnVy0tLGzWQJvGOLYpjRwaAoqoLK7AX+WLfMSnBn+MuWCGmqPdk9Xto4cJnC5toASjNtu/bGYWuy4ShpzTivuwioJbxt5JGiq78j/MVu/5oBjzosJlSpNlY5++wrkLvfpkWMuJSC3/V40LkpLa+XF/MP18Bpbi44GmLTOCq4wJ/WRrYMAt4yQWURNJAv9tKqLyqgJ47HLBMEYABWUdr81apZm3ZKbqqmyu4GLclc7ivnVBjfmf5oDxMDUqp8owQO9YOsUX9t8Rw9XiPdasjx5EQ+EcvoAyBCPV6qlnFi7pj7wWnxu1DNhzxeW70BKhXizYwcBqSlvX88pbgCxc273Id0dAilrCgvD0/B2mvLPIVbJsscMyykjC7ZZOaznhfHQqeu/fXdfcVawVt+annovbFOWxjX5232ghbq12ux6qZ+2GNziW9vtEJeitPZ3XRPMc=
    secret-access-key:
      secure: aCiIP0To/YPm9E3G/q/JIHASRN0b69R23w8WYovmMsBFHddh0MBXnhh+Kf5Cuos+NdVatNs7mAqulLdmBF8TZhreEhLOd9PppEXPVXJrlvdDKejX3S6czUWD8tb4fSE4/qF9H8XYVa+Aznn/2Vlu3fFggAcAMv8lm7igTNb8rc2YZkaByNvwDjauoB1CwgvMsJiptDNy/m9EOJST9RqS/SDAFsPEFQLih0BRWbSYnEZ6yYtQ7T+ROOjjBxTefqf9E6s6PuXI9zrDzGtKE3mwibASts5lfVcKWBp/m1Droog7QxRgixUo9CoE4bK3tcSqpgBx/Mn1RL43C8pt2n2yxeXr6Rl1rdnpvVmz/7XbQqBtbX+atot63PKW4fuTlwCmnQfBWwsAqUZmnCHs0EgcFQR6VoO1D5FLKAWOFeo4RBCQ3mOr/kU3wTG0OrDVf3C1VpTD8W07AVIwcYm/jOSPJYgWwDk+OPz0f8UYbJTe8UO14LU/Wy6QT81cjEwjXJdCcv6IZS50iDNq9PxaACoOqAmfDZNwxuQBxN0kR1eWEobE+zucIfpa6OteA980X22xQIimPcVmmBcDjYce//o/12UNKZprUXeUqSPJsXWw8p3CIbJP8lI35aiTR3kjOG7XBG0QO1HyBHKudZHPGo3RU6dXVegu6POujy+oxbkQNyo=
    region: eu-west-1
    app: Webapp
    env: wire-webapp-staging
    bucket_name: wire-webapp
    on:
      repo: wireapp/wire-webapp
      branch: staging

  - provider: elasticbeanstalk
    edge: true
    skip_cleanup: true
    zip-file: 'aws/s3/ebs.zip'
    access-key-id:
      secure: MpVUBkrtmIPqYLzrsYisYsE/UnOFU6q0ufgfWNBxHAFm/mDST9v+Kk1ZvhNKYskgMzJllQJBBqiRn05Fegam+DQ0oclbPr7Eg4mQrPbsrLIsc2qEpqw3fk8bqOssnHkKe1wlz7ihW3eQ78zOgsS/w95Zyd7wWiDzz8s7KvRPN8DLRGu2ksDdkPfM6RCbs9qsdSA5k8+DhZRXZCL/IHalE3plqOOJgCgTq9kzMRvxnFnVy0tLGzWQJvGOLYpjRwaAoqoLK7AX+WLfMSnBn+MuWCGmqPdk9Xto4cJnC5toASjNtu/bGYWuy4ShpzTivuwioJbxt5JGiq78j/MVu/5oBjzosJlSpNlY5++wrkLvfpkWMuJSC3/V40LkpLa+XF/MP18Bpbi44GmLTOCq4wJ/WRrYMAt4yQWURNJAv9tKqLyqgJ47HLBMEYABWUdr81apZm3ZKbqqmyu4GLclc7ivnVBjfmf5oDxMDUqp8owQO9YOsUX9t8Rw9XiPdasjx5EQ+EcvoAyBCPV6qlnFi7pj7wWnxu1DNhzxeW70BKhXizYwcBqSlvX88pbgCxc273Id0dAilrCgvD0/B2mvLPIVbJsscMyykjC7ZZOaznhfHQqeu/fXdfcVawVt+annovbFOWxjX5232ghbq12ux6qZ+2GNziW9vtEJeitPZ3XRPMc=
    secret-access-key:
      secure: aCiIP0To/YPm9E3G/q/JIHASRN0b69R23w8WYovmMsBFHddh0MBXnhh+Kf5Cuos+NdVatNs7mAqulLdmBF8TZhreEhLOd9PppEXPVXJrlvdDKejX3S6czUWD8tb4fSE4/qF9H8XYVa+Aznn/2Vlu3fFggAcAMv8lm7igTNb8rc2YZkaByNvwDjauoB1CwgvMsJiptDNy/m9EOJST9RqS/SDAFsPEFQLih0BRWbSYnEZ6yYtQ7T+ROOjjBxTefqf9E6s6PuXI9zrDzGtKE3mwibASts5lfVcKWBp/m1Droog7QxRgixUo9CoE4bK3tcSqpgBx/Mn1RL43C8pt2n2yxeXr6Rl1rdnpvVmz/7XbQqBtbX+atot63PKW4fuTlwCmnQfBWwsAqUZmnCHs0EgcFQR6VoO1D5FLKAWOFeo4RBCQ3mOr/kU3wTG0OrDVf3C1VpTD8W07AVIwcYm/jOSPJYgWwDk+OPz0f8UYbJTe8UO14LU/Wy6QT81cjEwjXJdCcv6IZS50iDNq9PxaACoOqAmfDZNwxuQBxN0kR1eWEobE+zucIfpa6OteA980X22xQIimPcVmmBcDjYce//o/12UNKZprUXeUqSPJsXWw8p3CIbJP8lI35aiTR3kjOG7XBG0QO1HyBHKudZHPGo3RU6dXVegu6POujy+oxbkQNyo=
    region: eu-west-1
    app: Webapp
    env: wire-webapp-prod-next
    bucket_name: wire-webapp
    on:
      repo: wireapp/wire-webapp
      branch: prod

In our config we have configured the deployment for 3 different branches (dev, staging & prod). Please note that on a successful deploy, Travis will still write Skipping a deployment with the elasticbeanstalk provider because this branch is not permitted two times to the log, because it can only deploy to 1 out of the configured 3 branches, which means that it cannot deploy for the other 2 (that's why the skipping warning appears two times).

dmichael commented 8 years ago

Good morning @bennyn thanks for the config - ours is very similar with our master branch moved to the bottom (after finding this thread). Now the master branch still says Skipping a deployment with the elasticbeanstalk provider because this branch is not permitted. but it is not at the end of the trace - the good ole Deploying application shows up at the end, which is better than nothing.

In summary, order here still seems to matter with regards to messaging, even though the behavior is correct.

Anupkarmacharya commented 7 years ago

how can we deploy same appliction version to three different environement in single travis file?

bennycode commented 7 years ago

@Anupkarmacharya Just have a look at: https://github.com/wireapp/wire-webapp/blob/2017-07-18-12-50/.travis.yml#L79

Anupkarmacharya commented 7 years ago

thank you @bennyn, but the problem I am facing is to deploy on same branch with same commit version on git. The example you reference is for different branch.

rajkumaranuk commented 7 years ago

I also have the similar issue. It fails with the following error when deploying from master branch into 3 beanstalk environments. (but works fine when deploying from different branches) /home/travis/.rvm/gems/ruby-2.2.7/gems/rubyzip-1.2.1/lib/zip/file.rb:396:in `check_entry_exists': add failed. Entry .ebextensions/30-elb.config already exists (Zip::EntryExistsError)

Please advice. Thanks for any help.

rajkumaranuk commented 7 years ago

this works for me