CONSUL
Search…
Heroku

Manual deployment

This tutorial assumes that you have already managed to clone CONSUL on your machine and gotten it to work.
    1.
    First, create a Heroku account if it isn't already done.
    2.
    Install the Heroku CLI and sign in using
    1
    heroku login
    Copied!
    3.
    Go to your CONSUL repository and instantiate the process
    1
    cd consul
    2
    heroku create your-app-name
    Copied!
    You can add the flag --region eu if you want to use their European servers instead of the US ones.
    If your-app-name is not already taken, Heroku should now create your app.
    4.
    Create a database using
    1
    heroku addons:create heroku-postgresql
    Copied!
    You should now have access to an empty Postgres database whose address was automatically saved as an environment variable named DATABASE_URL. CONSUL will automatically connect to it when deployed.
    5.
    Add a file name heroku.yml at the root of your project and paste the following in it
    1
    build:
    2
    languages:
    3
    - ruby
    4
    packages:
    5
    - imagemagick
    6
    run:
    7
    web: bundle exec rails server -e ${RAILS_ENV:-production}
    Copied!
    6.
    Now, generate a secret key and save it to an ENV variable named SECRET_KEY_BASE using
    1
    heroku config:set SECRET_KEY_BASE=`ruby -rsecurerandom -e "puts SecureRandom.hex(64)"
    Copied!
    You need to let the app know where the secret key is stored by adding a link to the ENV variable in config/secrets.yml
    1
    production:
    2
    secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
    Copied!
    and commit this file in the repo by commenting out the corresponding line in the .gitignore.
    1
    #/config/secrets.yml
    Copied!
    Remember not to commit the file if you have any sensitive information in it!
    7.
    You can now push your app using
    1
    git push heroku your-branch:master
    Copied!
    8.
    It won't work straight away because the database doesn't contain the tables needed. To create them, run
    1
    heroku run rake db:migrate
    2
    heroku run rake db:seed
    Copied!
    If you want to add the test data in the database, move gem 'faker', '~> 1.8.7' outside of group :development and run
    1
    heroku config:set DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
    2
    heroku config:set DATABASE_CLEANER_ALLOW_PRODUCTION=true
    3
    heroku run rake db:dev_seed
    Copied!
    9.
    Your app should now be ready to use. You can open it with
    1
    heroku open
    Copied!
    You also can run the console on heroku using
    1
    heroku console --app your-app-name
    Copied!
    10.
    Heroku doesn't allow to save images or documents in its servers, so it's necessary make this changes
    On app/models/image.rb:47 and app/models/document.rb:39
    Change URI.parse(cached_attachment) to URI.parse("http:" + cached_attachment)
    Create a new file on config/initializers/paperclip.rb with the following content
    1
    Paperclip::UriAdapter.register
    Copied!
    See our S3 guide for more details about configuring Paperclip with S3.
Install rails_12factor and specify the Ruby version
As recommended by Heroku, you can add the gem rails_12factor and specify the version of Ruby you want to use. You can do so by adding
1
gem 'rails_12factor'
2
3
ruby 'x.y.z'
Copied!
in the file Gemfile_custom, where x.y.z is the version defined in the .ruby-version file in the CONSUL repository. Don't forget to run
1
bundle install
Copied!
to generate Gemfile.lock before commiting and pushing to the server.
Use Puma as a web server
Heroku recommends to use Puma instead of the default web server to improve the responsiveness of your app on a number of levels. First, add the gem in your Gemfile_custom file:
1
gem 'puma'
Copied!
Then you need to create a new file named puma.rb (your config folder is a good place to store it). Here is a standard content for this file:
1
workers Integer(ENV['WEB_CONCURRENCY'] || 1)
2
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
3
threads threads_count, threads_count
4
5
preload_app!
6
7
rackup DefaultRackup
8
port ENV['PORT'] || 3000
9
environment ENV['RACK_ENV'] || 'production'
10
11
on_worker_boot do
12
# Worker specific setup for Rails 4.1+
13
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
14
ActiveRecord::Base.establish_connection
15
end
Copied!
You can find an explanation for each of these settings in the Heroku tutorial.
The last part is to change the web task to use Puma by changing it to this in your heroku.yml file:
1
web: bundle exec puma -C config/puma.rb
Copied!
Last modified 6mo ago