Capistrano read from .env on deployment server

user3070184

I am trying to perform a database backup as part of a Capistrano (v3) deployment script (for a NON-Rails app).

The script works fine -- if I hard-code database config into it.

Now I want to load in the database config from a .env file. On my local machine, my .env file (in the repo root next to the Capfile) reads as follows:

DB_NAME='local_name'
DB_USER='local_user'
DB_PASSWORD='local_pw'
DB_HOST='127.0.0.1'

On the server, the .env file (which Capistrano has placed in the shared folder & symlined to from the current folder) reads as follows:

DB_NAME='dev_name'
DB_USER='dev_user'
DB_PASSWORD='dev_pw'
DB_HOST='127.0.0.1'

However, when running cap deploy, I get the following:

INFO [292e2535] Running /usr/bin/env mysqldump -u local_user --password='local_pw' --databases local_name -h 127.0.0.1 | bzip2 -9 > /var/www/vhosts/xxxxx/backups/database_local_name_2014-05-29_22:52:07.sql.bz2 on <server>

I.e. it's using my local .env file, when actually I'd like it to load the .env file that is present on the server. I do not want all of my team to have to manage a separate .env.production file if at all possible!

The relevant portion of my script is as follows (using the Dotenv gem):

require 'dotenv'
Dotenv.load '.env'
username, password, database, host = ENV['DB_USER'], ENV['DB_PASSWORD'], ENV['DB_NAME'], ENV['DB_HOST']

Any help would be greatly appreciated!

Krisztián Ferenczi

You can use the Dotenv::Parser.call(string). I am using with Capistrano 2.14 (this is older version!)

desc <<-desc
  ENV test
desc
task :test do
  text = capture "cat #{shared_path}/.env"
  ENV2 = Dotenv::Parser.call(text)
  puts ENV2['DB_NAME']
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Capistrano and Rails deployment, unable to access bitbucket repo from ubuntu server

From Dev

Capistrano — add a task to update repo from server before deployment if server version is newer

From Dev

/usr/bin/env and Capistrano 3 failures in Rails Deployment

From Dev

/usr/bin/env and Capistrano 3 failures in Rails Deployment

From Dev

capistrano deployment to a server without public IP through a proxy

From Dev

Ruby on rails 4.1.6 + Capistrano 3: purge gems on deployment server

From Dev

capistrano deployment to a server without public IP through a proxy

From Dev

Capistrano deployment fails when server ssh key has a passphrase

From Dev

Capistrano deployment problems

From Dev

Capistrano deployment behaviour

From Dev

Resque Capistrano Deployment in Rails

From Dev

Capistrano deployment with Bitbucket

From Dev

Deploying .env file with Capistrano

From Dev

Rails 4, Capistrano 3 and Dotenv - How to deploy using server-side .env file

From Dev

Capistrano 3 + AWS: Deployment Issues

From Dev

Capistrano deployment and devise secret key

From Dev

Capistrano 3 + AWS: Deployment Issues

From Dev

capistrano-env file permissions

From Dev

Automatic deployment from development server to Remote server

From Dev

Rails 4 + Capistrano 3 - Deploy to Production Server from Local Repo

From Dev

Setting :deploy_to from server config in Capistrano3

From Dev

server properties in loops in Capistrano

From Dev

Capistrano not pushing binstub to server

From Dev

Capistrano not pushing binstub to server

From Dev

capistrano addresses wrong server

From Dev

Capistrano deployment broken by new request for Capistrano-Harrow gem?

From Dev

Django Deployment with nginx - gunicorn from another server

From Dev

Capistrano 3 deployment for Rails 4 binstubs conflict?

From Dev

Capistrano 3.1.0 Deployment issue with Rake >= 10.2.0

Related Related

  1. 1

    Capistrano and Rails deployment, unable to access bitbucket repo from ubuntu server

  2. 2

    Capistrano — add a task to update repo from server before deployment if server version is newer

  3. 3

    /usr/bin/env and Capistrano 3 failures in Rails Deployment

  4. 4

    /usr/bin/env and Capistrano 3 failures in Rails Deployment

  5. 5

    capistrano deployment to a server without public IP through a proxy

  6. 6

    Ruby on rails 4.1.6 + Capistrano 3: purge gems on deployment server

  7. 7

    capistrano deployment to a server without public IP through a proxy

  8. 8

    Capistrano deployment fails when server ssh key has a passphrase

  9. 9

    Capistrano deployment problems

  10. 10

    Capistrano deployment behaviour

  11. 11

    Resque Capistrano Deployment in Rails

  12. 12

    Capistrano deployment with Bitbucket

  13. 13

    Deploying .env file with Capistrano

  14. 14

    Rails 4, Capistrano 3 and Dotenv - How to deploy using server-side .env file

  15. 15

    Capistrano 3 + AWS: Deployment Issues

  16. 16

    Capistrano deployment and devise secret key

  17. 17

    Capistrano 3 + AWS: Deployment Issues

  18. 18

    capistrano-env file permissions

  19. 19

    Automatic deployment from development server to Remote server

  20. 20

    Rails 4 + Capistrano 3 - Deploy to Production Server from Local Repo

  21. 21

    Setting :deploy_to from server config in Capistrano3

  22. 22

    server properties in loops in Capistrano

  23. 23

    Capistrano not pushing binstub to server

  24. 24

    Capistrano not pushing binstub to server

  25. 25

    capistrano addresses wrong server

  26. 26

    Capistrano deployment broken by new request for Capistrano-Harrow gem?

  27. 27

    Django Deployment with nginx - gunicorn from another server

  28. 28

    Capistrano 3 deployment for Rails 4 binstubs conflict?

  29. 29

    Capistrano 3.1.0 Deployment issue with Rake >= 10.2.0

HotTag

Archive