Rails - Mina - unable to load environment variables in database.yml file

Mina cannot load environment variables that are in the database.yml file as follows:

deploy.rb:

task :deploy => :environment do
  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    queue! "#{rake} db:seed"
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'
  end
end

vim ~ / .bash_profile:

export MYSQLUSERNAME=mysql_user_name
export MYSQLPASSWORD=mysql_password

database.yml:

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: my_db_name
  pool: 5
  username: <%= ENV['MYSQLUSERNAME'] %>
  password: <%= ENV['MYSQLPASSWORD'] %>

Error:

$ mina deploy
  .....
  .......
  -----> DB migrations unchanged; skipping DB migration
         $ RAILS_ENV="production" bundle exec rake db:seed
         rake aborted!
         Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)
               /home/user_name/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.16/lib/mysql2/client.rb:70:in `connect'

Note: If I replace the username (mysql_user_name) and password (mysql_user_name) values ​​with <% = ENV ['MYSQLUSERNAME']%> and <% = ENV ['MYSQLPASSWORD']%> in the database.yml file, it works well.

Can someone please help me on how I can load ENV variables into a * .yml file when deploying using Mina.

Thank!

+4
source share
2 answers

, , .

Figaro gem, YML. .

:

YML:

MY_ENVIRONMENT_VARIABLE: 'Hi there!'

Ruby:

<%= ENV['MY_ENVIRONMENT_VARIABLE'] %>

, SCP ( , * nix), , Mina .

+2

ENV .bashrc..bash_profile , mina .

: fooobar.com/questions/37172/...

+1

All Articles