Permissions for the capistrano-env file

I am using gem capistrano-env and found a little problem. My deployment script:

 Capistrano::Env.use do |env| env.add 'DB_DSN', 'mysql:host=localhost;dbname=dbname' env.add 'DB_USER', 'user' env.add 'DB_PASS', 'pass' end 

And this code creates the .env file on the server after deployment. But! .env File permissions are 640, and my PHP script cannot read it. I can run the chmod after each deployment, but is there probably another nice solution?

EDIT

I created a pull request and added a new filemode parameter to this gem. So now the solution is:

 Capistrano::Env.use do |env| env.add 'DB_DSN', 'mysql:host=localhost;dbname=dbname' env.add 'DB_USER', 'user' env.add 'DB_PASS', 'pass' env.filemode = 0644 end 
+6
source share
2 answers

You have several options to make it better.

  • It does not seem like capistrano-env supports a custom permissions setting, but perhaps this feature can be added! Open the problem on GitHub and maybe the project developer will add it.

  • You can modify your deploy.rb to execute the desired chmod for you. This way, you do not have to manually run chmod after each deployment.

Something like that:

 # In deploy.rb after "capenv:copy", "capenv:chmod" do on roles(:all) do execute "chmod", "a+r", "#{release_path}/#{Capistrano::Env.filename}" end end 
+5
source

Looking at the capevn code , loading is done in one task. You can locally override the definition of this task to change file permissions. Put in deploy.rb something like the following:

 namespace :capenv do desc 'copy .env to release_path' task :copy do on roles(:all) do upload! StringIO.new(Capistrano::Env.to_s), "#{release_path}/#{Capistrano::Env.filename}", mode: 'a+r' end end end 
+4
source

Source: https://habr.com/ru/post/989297/


All Articles