Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment section #141

Open
wikimatze opened this issue May 26, 2017 · 0 comments
Open

Deployment section #141

wikimatze opened this issue May 26, 2017 · 0 comments

Comments

@wikimatze
Copy link
Member

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'
end

Now you can bundle :

$ bundle

and 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 master

That'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 DATABASE

and 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])
end

You 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:seed

You'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: [email protected]
   password: *****
=================================================================

Now let's open our newly deployed app:

$ heroku open

and surf. You can see posts and the
admin screen.

Enjoy!

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

No branches or pull requests

1 participant