-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Deploying your application on heroku
Finally, our basic blog has been built and we should deploy our application so
the world can check it out! The easiest way to do this quickly and for free is
to use a service such as Heroku. Let's deploy our application to Heroku right
now.
The best way to get started using Heroku is by following the
Heroku Quickstart Guide. As explained in the guide, be sure to have Git installed and
setup a Heroku account as
well as
install the Heroku command-line tool before continuing this tutorial.
Now, to deploy to Heroku, the application needs to be set up as a Git
repository:
$ cd sample-blog-updated
$ git init
$ git add .
$ git commit -m "initial commit for app"This initializes the Git repository, adds all the contents and commit them to
the repo.
Currently Padrino defaults to SQLite but Heroku only supports
PostgreSQL, so we'll need to add pg gem as a dependency for production as well add sqlite3
for development.
# Gemfile
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
endNow you can bundle :
$ bundleand then commit these changes to your git repository:
$ git add --all
$ git commit -m "added pg dependency"Next, the application must be set up on Heroku.
$ heroku login
Enter your Heroku credentials.
Email: <your-email>
Password (typing will be hidden):
Logged in as <your-email>
$ heroku create
Creating app... done, ⬢ secret-taiga-32690
https://secret-taiga-32690.herokuapp.com/ | https://git.heroku.com/secret-taiga-32690.git
$ git push heroku masterThat's it, your app is now running on Heroku! To see if we have a database addon connected
to out heroku app, run heroku addons:
$ heroku addons
Add-on Plan Price
─────────────────────────────────────────── ───────── ─────
heroku-postgresql (postgresql-taiga-32690) hobby-dev free
└─ as DATABASEand configure the config/database.rb for production:
# config/database.rb
Sequel::Model.plugin(:schema)
Sequel::Model.raise_on_save_failure = false # Do not throw exceptions on failure
Sequel::Model.db = case Padrino.env
when :development then Sequel.connect("sqlite://db/blog_tutorial_development.db", :loggers => [logger])
when :production then Sequel.connect("<your-url>", :loggers => [logger])
when :test then Sequel.connect("sqlite://db/blog_tutorial_test.db", :loggers => [logger])
endYou can get the value of <your-url> via heroku config.
Run heroku open to open your site in your default web browser.
Now run our migrations/seeds:
$ heroku run rake sq:migrate
$ heroku run rake sq:seedYou'll see something like:
$ heroku run rake ar:migrate
Running rake ar:migrate on calm-tor-92217.... up, run.7316
== 1 CreateAccounts: migrating ================================================
-- create_table(:accounts)
-> 0.0162s
== 1 CreateAccounts: migrated (0.0164s) =======================================
== 2 CreatePosts: migrating ===================================================
-- create_table(:posts)
-> 0.0078s
== 2 CreatePosts: migrated (0.0080s) ==========================================
== 3 AddAccountToPost: migrating ==============================================
-- change_table(:posts)
-> 0.0048s
== 3 AddAccountToPost: migrated (0.0254s) =====================================
$ heroku run rake seed
Running rake seed on calm-tor-92217.... up, run.9169
Which email do you want use for logging into admin?
Tell me the password to use:
=================================================================
Account has been successfully created, now you can login with:
=================================================================
email: info@padrinorb.com
password: *****
=================================================================Now let's open our newly deployed app:
$ heroku openand surf. You can see posts and the
admin screen.
Enjoy!