Heroku with Rails
Learn how to make Heroku, Rails, and Dotenv Vault work together. This tutorial assumes you have already created a
.env file and synced it.
You can find a complete example repo here.
Set up Rails with Heroku
Set up your Rails app to work with Heroku.
Example shows using environment variable example
// Add 'dotenv-vault-rails' to Gemfile gem 'dotenv-vault-rails'
Run bundle install.
$ bundle install
Require it as early as possible in your Rails application. For a Rails application require dotenv-vault/load in application.rb
// config/application.rb require 'dotenv-vault/load'
Run dotenv-vault build
On your terminal at root of your project run npx dotenv-vault build to build your encrypted .env.vault file.
$ npx dotenv-vault build
Run npx dotenv-vault keys production.
$ npx dotenv-vault keys production remote: Listing .env.vault decryption keys... done dotenv://:[email protected]/vault/.env.vault?environment=production
Visit your Heroku Project’s Environment Variables under settings of your heroku application
Set DOTENV_KEY to the value returned in step 4.
Commit and push
Commit those changes safely to code and deploy to Heroku.
When the build runs, it will recognize the
DOTENV_KEY, decrypt the .env.vault file, and load the production environment variables to
ENV. If a
DOTENV_KEY is not set (like during development on your local machine) it will fall back to regular dotenv.