Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Add environment lock/unlock/locked handling #96

Merged
merged 9 commits into from
Oct 29, 2014
Merged

Add environment lock/unlock/locked handling #96

merged 9 commits into from
Oct 29, 2014

Conversation

dblandin
Copy link
Contributor

This PR adds support for deploy:lock and deploy:unlock tasks.

These tasks are intercepted and handled separate from any provider.

When an attempt to deploy to a locked environment is made, we'll send up an error deployment status with a description including who locked the environment.

Addresses #55

@atmos
Copy link
Owner

atmos commented Oct 28, 2014

Looks pretty good. Can you run script/cibuild and fix the errors?

@@ -30,6 +30,21 @@
Resque.inline = true
end

config.around do |example|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this stuff for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to prevent tests from messing with the default Heaven.redis instance. Here I'm switching to a different database number on localhost.

We could alternatively use something like fakeredis or mock_redis during testing.

@dblandin
Copy link
Contributor Author

@atmos All set on the script/cibuild front. There's still a complexity warning for the main receiver #run! method but that'll take a bit more thought.

Maybe something like this would be more concise?

def run!
  unless receivers.detect { |receiver| receiver.new(event, guid, data).run! }
    Rails.logger.info "Unhandled event type, #{event}."
  end
end

private

def receivers
  [LockReceiver, DeploymentReceiver, DeploymentStatusReceiver, StatusReceiver]
end

Receivers that can't handle the event can return nil or false.

@@ -30,6 +30,14 @@
Resque.inline = true
end

config.around do |example|
original = Heaven.redis
Heaven.redis = Redis.new(:url => "redis://localhost:6379/3")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an environmental variable for this? like ENV['BOXEN_REDIS_URL'] || 'redis://localhost:6379'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing here is the /3 database number. 3 could really be any number beyond the default of 0. I don't see I way to extract the currently used redis url and tack on a different database number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can do something like this instead:

config.around do |example|
  original = Heaven.redis.client.db
  Heaven.redis.select(3)
  example.run
  Heaven.redis.flushall
  Heaven.redis.select(original)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the last database index of 15 which I doubt anyone is going to use.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's try the redis select thing on 15 and see how everything is working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed up a commit. Seems fine on my machine.

atmos added a commit that referenced this pull request Oct 29, 2014
…ed-handling

Add environment lock/unlock/locked handling
@atmos atmos merged commit 183a1bd into atmos:master Oct 29, 2014
@atmos
Copy link
Owner

atmos commented Oct 29, 2014

Can you send another pr documenting the behavior of locking?

@atmos
Copy link
Owner

atmos commented Oct 29, 2014

Maybe something like this would be more concise?

I just fixed it in something that reads a little easier than what you proprosed in 86fdcb6

@dblandin dblandin deleted the add-environment-lock-unlock-locked-handling branch October 29, 2014 01:50
@atmos atmos mentioned this pull request Oct 29, 2014
@willdurand
Copy link
Contributor

Hi! Commands deploy:lock or deploy:unlock are not intercepted, but forwarded to the deploy script (e.g. Fabric). Is there anything to do to "enable" these interceptors? (commands are sent using hubot-deploy from Slack)

@dblandin
Copy link
Contributor Author

@willdurand Looks like the GitHub deployment webhook payload has changed since this feature was implemented. We'll have to update the mapping here. Happy to do that in a PR this week if someone doesn't get to it first.

Here's where you would find the current payload structure:

https://github.com/:owner/:repo/settings/hooks

@willdurand
Copy link
Contributor

Thanks @dblandin, I created a PR (#170)

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

Successfully merging this pull request may close these issues.

None yet

3 participants