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

Environment variables #20

Open
4 of 5 tasks
AleksSenkou opened this issue Jan 28, 2017 · 4 comments
Open
4 of 5 tasks

Environment variables #20

AleksSenkou opened this issue Jan 28, 2017 · 4 comments
Assignees

Comments

@AleksSenkou
Copy link

AleksSenkou commented Jan 28, 2017

Conversation

Add gem and file for environment variables?
          1)  None
          2)  Add .env with Foreman

Purpose

Use dotenv gem + .env file + initializers by default

Checklist for changes:

  • Add gem 'dotenv-rails' to Gemfile

  • Add .env.sample file to the app root with content:

# NOTE: don't forget to:
# 1) add a variable to .env on server
# 2) stop and start puma process (right after you added new variables)

RAILS_ENV=development
  • Add script to setup script(copies vars from env sample file to env):
  unless File.exist?(".env")
    cp ".env.sample", ".env"
  end
  • Add script to update script(updates env vars from sample file):
def env_sample_vars
  File.read('.env.sample').each_line.inject({}) do |variables, line|
    variable = line.split('=')[0]
    variables.merge({variable => line})
  end
end

def try_to_add_new_env_vars
  env_file = File.read('.env')

  File.open('.env', 'a') do |file|
    env_sample_vars.each do |var_name, var_definition|
      file << var_definition unless env_file.include?(var_name)
    end
  end
end

if File.exist?(".env")
  try_to_add_new_env_vars
else
  cp ".env.sample", ".env"
end

More info about setup and update scripts here

P.S. Ping me if you are not agree, or have better idea.
  • Check figaro gem, and update if this will be necussary:
@roman-dubrovsky
Copy link

@AleksSenkou 👍

@MProG
Copy link

MProG commented Feb 7, 2017

@AleksSenkou I think https://github.com/laserlemon/figaro is better. Please investigate
this gem too

@AleksSenkou
Copy link
Author

@MProG can we close this issue?

@MProG
Copy link

MProG commented Feb 9, 2017

@AleksSenkou Not now. I want check how work figaro

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

4 participants