Ask A Question

Notifications

You’re not receiving notifications from this thread.

Mimic Heroku CLI on Hatchbox with rake tasks

Vincent Bakker asked in Servers

Hi guys,

Weirdly enough the thing that was holding me back the most from moving away from Heroku to Hatchbox was the ease of use of the Heroku CLI in my daily workflow.

So this weekend I decided to hack together the following rake tasks to mimic heroku logs, heroku console and heroku deploy.

Display logs for the app.
rake hatchbox:logs

Connect to Rails console
rake hatchbox:console

Deploy latest version
rake hatchbox:deploy

Let me know if there is anything that needs to be changed or improved or if this is horrifically insecure. Next step might be to convert this into a gem and find a better place for the credentials.

require 'net/http'

server = "xxxx" 
app = "xxx" 
webhook = "xxx" 

namespace :hatchbox do

  desc "Display logs for the app"
  task logs: :environment do
      command = "ssh deploy@#{server} journalctl --user --unit=#{app.parameterize}-server -n 100 --no-pager"
      puts "Running #{command}..."
      exec(command)
  end

  desc "Connect to Rails console"
  task console: :environment do
    command = "ssh -t deploy@#{server} 'cd #{app}/current && bundle exec rails console'"
    puts "Running #{command}..."
    exec(command)
  end

  desc "Deploy latest version"
  task deploy: :environment do    
    uri = URI.parse(webhook)
    command = Net::HTTP.post(uri, 'latest=true') 
    puts "Deploying latest commit"
  end

end
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.