Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use existing version if present, otherwise upload deployment-package #8

Closed
dhimmel opened this issue Jan 24, 2020 · 9 comments

Comments

@dhimmel
Copy link

dhimmel commented Jan 24, 2020

From the readme:

You can also use the action to deploy an existing version. To do this simply omit the deployment-package input parameter. The action will then assume that the version you pass in throught version_label already exists in Beanstalk and attempt to deploy that.

I am interested in a solution to the situation where the desired behavior is to:

  1. use the already deployed version if it exists
  2. otherwise, create the version from deployment-package

Basically, ignore deployment-package if the version already exists on s3.

This would address the following error that occurs if you deploy to multiple environments as demonstrated in #5 (comment):

Deployment failed: Error: Version XXXX already exists in S3!

In our case, XXXX is the source commit hash, so we don't have to worry about version being ambiguous.

@einaregilsson
Copy link
Collaborator

Basically, ignore deployment-package if the version already exists on s3.

Hmmm, interesting. I can see that it would be useful for some cases, but adds some complexity. So your use case is you're deploying the same build to two environments, and only want to create the version once and then deploy to both? Wouldn't a simple workaround being defining two tasks, where the first creates the version and deploys to env 1 and the second deploys the existing version to env 2?

@dhimmel
Copy link
Author

dhimmel commented Jan 25, 2020

We are deploying to staging or production based on monitoring commit messages. If a commit message contains [deploy staging], we want to deploy to staging. If the commit message contains [deploy production] we want to deploy to production.

Our workflow is like:

    - name: deploy to staging
      if: contains(github.event.head_commit.message, '[deploy staging]')
      uses: einaregilsson/beanstalk-deploy
      with:
        environment_name: staging
        version_label: ${{ github.sha }}
        deployment_package: src/deploy.zip
    - name: deploy to production
      if: github.event_name == 'push' && contains(github.event.head_commit.message, '[deploy production]')
      uses: einaregilsson/beanstalk-deploy
      with:
        environment_name: production
        version_label: ${{ github.sha }}
        deployment_package: src/deploy.zip

This works fine, unless the commit message be like:

[deploy production]
[deploy staging]

In this case, [deploy staging] will fail because the version already exists.

I could imagine a similar issue arising if we were to git reset --hard to a prior commit, and rerun the CI to redeploy it.

Basically, it seems like there could be a range of situations where a version already exists but the workflow step doesn't actually know if it does.

@dhimmel
Copy link
Author

dhimmel commented Jan 25, 2020

One workaround would be adding a timestamp to version_label, but then we'd lose all efficiency gains by not having to store the same content twice.

@einaregilsson
Copy link
Collaborator

I kinda wish I'd done it like you said from the beginning. But now I'm thinking whether to add the feature directly, or add it as some kind of option. Could possibly add some kind of optional use_existing_version_if_available: true or something like that.

@dhimmel
Copy link
Author

dhimmel commented Jan 26, 2020

Could possibly add some kind of optional use_existing_version_if_available: true or something like that

I think the option makes sense for backwards compatibility and out of precaution... I could imagine situations where users don't intend to create a duplicate version number and perhaps the failure would be good in that case.

OTOH there are presumably few users currently, so backwards incompatibility probably is not a huge deal. And given the usefulness of this action, I presume it will have many more users in the future. So not a bad time to make changes.

Anyways no strong opinion here. Whatever form it's implemented, I think it'd be useful!

@einaregilsson
Copy link
Collaborator

einaregilsson commented Jan 28, 2020

I've just published v5 of the action which adds this parameter, use_existing_version_if_available . Set it to true to get the desired behaviour. Let me know if there are problems with it 🙂

dhimmel added a commit to ResearchHub/researchhub-backend that referenced this issue Jan 28, 2020
refs einaregilsson/beanstalk-deploy#8

allows us to deploy an already existing version via commit message,
for example if we want to deploy the same commit to production
and staging.
@juan-ntsprint
Copy link

Just FYI, I just tested that attaching AWSElasticBeanstalkWebTier and AWSElasticBeanstalkService managed policies to the user is enough for a successful deployment.

@einaregilsson
Copy link
Collaborator

@juan-ntsprint Thanks, I'll add that to the docs 🙂

@Aladdin4u
Copy link

I'm having the same problem, will I have to keep emptying and deleting S3 bucket if a deployment goes wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants