phallstrom / slackistrano

Slack integration for Capistrano deployments.
MIT License
373 stars 74 forks source link

Weird issue with slackistrano, capistrano, and sinatra #38

Closed synth closed 8 years ago

synth commented 8 years ago

This is super weird, brace yourself.

After installing slackistrano to my app, deployments to our staging server were crashing. Capistrano did not give any useful info other than it was crashing during any rails task such as precompiling or migrating with an error such as:

cap aborted!
SSHKit::Command::Failed: rake stdout: Nothing written
rake stderr: Nothing written
/Users/synth/.rvm/gems/ruby-2.2.2/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='

After much hair pulling, I finally figured out that SSHKit was crashing on the following command

cd /home/web/sites/mysite.com/releases/20160106224143 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate )

I logged into staging and ran it and low and behold:

$ cd /home/web/sites/site.com/releases/20160106224143 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
rake aborted!
NoMethodError: undefined method `each_pair' for "slack:deploy:updating":String
/home/web/sites/site.com/shared/bundle/ruby/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1602:in `compile!'
/home/web/sites/site.com/shared/bundle/ruby/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1344:in `add_filter'
/home/web/sites/site.com/shared/bundle/ruby/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1331:in `before'
/home/web/sites/site.com/shared/bundle/ruby/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1989:in `block (2 levels) in delegate'
/home/web/sites/site.com/shared/bundle/ruby/2.2.0/gems/slackistrano-1.0.0/lib/slackistrano/tasks/slack.rake:121:in `<top (required)>'

What the hell is Sinatra doing there and why is it being called?

I then realized that my app had some gems in production that weren't supposed to be there(mailcatcher) that were using Sinatra. I moved them over to development, and boom, back in business.

However, this highlights a bigger issue that there seems to be a name collision with Capistrano and Sinatra.

I'm reporting this in Slackistrano for two reasons. One I discovered it while using this gem. Also, and more importantly because I'm wondering if there could be a better way to show errors to the console while loading Slackistrano during a deployment.

phallstrom commented 8 years ago

That is weird. I haven't used Sinatra in a long time, but my guess is that Sinatra adds some before hooks into Rake that are getting picked up. Except they do different things than capistrano.

This line in particular: https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/tasks/slack.rake#L121

before 'deploy:updating', 'slack:deploy:updating'

As for lack of errors, that is strange. Capistrano should be logging those in more detail somewhere. I think.

synth commented 8 years ago

slackistrano does have require: false in our Gemfile,and is just in the main group, ie not assigned to development, test or production. Its cool. We can close this, but I wanted to document the issue and make you aware.

chansuke commented 7 years ago

I put gem 'slackistrano' in main group of my Gemfile,this wired error comes out(sinatra is also in main group).

I commented out before "bundle_rsync:rsync_release", "precompile" line in lib/tasks/hoge.rake and it worked.