-
Git repo in your app
-
Create account on heroku.com
- Add your SSH key to Heroku so you can push to your heroku remote repo. Hopefully you already have an SSH key for GitHub, in which case you can run the following:
See here for more info.$ heroku keys:add Found the following SSH public keys: 1) github_rsa.pub 2) id_rsa.pub Which would you like to use with your Heroku account? 2 Uploading SSH public key /Users/helenhood/.ssh/id_rsa.pub... done
- Heroku toolbelt installed (& logged in)
- Download here and install
- Login on the command line:
$ heroku login Enter your Heroku credentials. Email: <your_email> Password (typing will be hidden): Authentication successful.
Heroku runs on Git. We can create an app on heroku and connect it as essentially another remote repository to our local git repo.
Just like we would add a remote github repo to our app like so, we can add a remote repo named heroku
that, when we push to it, will update our app on heroku.
Create a file called config.ru
in your app/
directory like so:
# config.ru
require './app' # or './server', if you have a server.rb file instead of app.rb
run Sinatra::Application
In your app's root directory, run:
$ heroku create
Creating <SOME_RANDOM_WEIRD_NAME>... done, stack is cedar-14
https://<SOME_RANDOM_WEIRD_NAME>.herokuapp.com/ | [email protected]:<SOME_RANDOM_WEIRD_NAME>.git
Git remote heroku added
That will create a new app on your Heroku account and connect it to your local repo. If we run git remote -v
(which will list, in long form, all of the remote repos connected to our local git repo), we should now see somthing like:
$ git remote -v
heroku https://git.heroku.com/<SOME_RANDOM_WEIRD_NAME>.git (fetch)
heroku https://git.heroku.com/<SOME_RANDOM_WEIRD_NAME>.git (push)
Now we can deploy our app by (1) pushing to our heroku
repo and (2) creating our database and running any necessary migrations.
$ git push heroku master
This step takes a while to complete.
The Heroku toolbelt allows us to run rake tasks like rake db:migrate
on our production database. Read more on this here.
The database should already have been created. You just need to migrate:
$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.4761
== 20141205192204 CreateTchotchkes: migrating =================================
-- create_table(:tchotchkes)
-> 0.0851s
== 20141205192204 CreateTchotchkes: migrated (0.0854s) ========================
If you have a seeder file (in db/seeds.rb
) that you're using to seed your database, you can run:
$ heroku run rake db:seed
Running `rake db:seed` attached to terminal... up, run.9852
Run heroku open
to try opening your app in the browser.
If you just ran heroku open
and you see an "Application Error" message, something has gone wrong! Oh no!
You can run heroku logs
to get output about what went wrong. Using the --tail
flag will allow you to leave the logs running while you navigate around your site.