Heroku

Manual deployment

This tutorial assumes that you have already managed to clone Consul Democracy 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:

heroku login
  1. Go to your Consul Democracy repository and instantiate the process:

cd consuldemocracy
heroku create your-app-name

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.

  1. Create a database using:

heroku addons:create heroku-postgresql

You should now have access to an empty Postgres database whose address was automatically saved as an environment variable named DATABASE_URL. Consul Democracy will automatically connect to it when deployed.

  1. Now, generate a secret key and save it to an ENV variable named SECRET_KEY_BASE using:

heroku config:set SECRET_KEY_BASE=$(rails secret)

Also add your server address:

heroku config:set SERVER_NAME=myserver.address.com

You need to let the app know where the configuration variables are stored by adding a link to the ENV variables in config/secrets.yml

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  server_name: <%= ENV["SERVER_NAME"] %>

and commit this file in the repo by commenting out the corresponding line in the .gitignore.

#/config/secrets.yml

Remember not to commit the file if you have any sensitive information in it!

  1. To ensure Heroku correctly detects and uses the node.js and ruby versions defined in the project, we need to make the following changes:

In package.json, add the node.js version:

"engines": {
  "node": "18.20.3"
}

and apply:

heroku buildpacks:add heroku/nodejs

In Gemfile, add the ruby version and run bundle:

ruby file: ".ruby-version"

and apply:

heroku buildpacks:set heroku/ruby
  1. You can now push your app using:

git push heroku your-branch:master
  1. It won't work straight away because the database doesn't contain the tables needed. To create them, run:

heroku run rake db:migrate
heroku run rake db:seed
  1. Your app should now be ready to use. You can open it with:

heroku open

You also can run the console on Heroku using:

heroku console --app your-app-name
  1. Heroku doesn't allow saving images or documents in its servers, so it's necessary to setup a permanent storage space.

See our S3 guide for more details about configuring ActiveStorage with S3.

Configure Twilio Sendgrid

Add the Twilio SendGrid add-on in Heroku. This will create a Twilio SendGrid account for the application with a username and allow you to create a password. This username and password can be stored in the application’s environment variables on Heroku:

heroku config:set SENDGRID_USERNAME=example-username SENDGRID_PASSWORD=xxxxxxxxx

Now add this to config/secrets.yml, under the production: section:

  mailer_delivery_method: :smtp
  smtp_settings:
    :address: "smtp.sendgrid.net"
    :port: 587
    :domain: "heroku.com"
    :user_name: ENV["SENDGRID_USERNAME"]
    :password: ENV["SENDGRID_PASSWORD"]
    :authentication: "plain"
    :enable_starttls_auto: true

Important: Turn on one worker dyno so that emails get sent.

Last updated