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

Variables set in "deploy.rb" can't be fetched in "staging files" and "task files" #1519

Closed
Oliboy50 opened this Issue Oct 29, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@Oliboy50
Contributor

Oliboy50 commented Oct 29, 2015

Everything is in the title.

Since, I didn't find anything about this huge problem, I presume this is due to a mistake on my side.

Here is my whole configuration:

Ubuntu 14.04
foo@bar:~$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
foo@bar:~$ cap -v
Capistrano Version: 3.4.0 (Rake Version: 10.4.2)

Capfile

set :deploy_config_path, 'capistrano/deploy.rb'
set :stage_config_path, 'capistrano/environments'

require 'capistrano/setup'

require 'capistrano/deploy'

Dir.glob('capistrano/tasks/*.cap').each { |r| import r }

capistrano/deploy.rb

lock '3.4.0'

set :application, 'FooBarProject'
set :keep_releases, 3

set :scm, :git
set :repo_url, 'git@github.com:Something/FooBarProject.git'

set :linked_dirs, fetch(:linked_dirs, []).push('build', 'app/logs', 'web/uploads')
set :linked_files, fetch(:linked_files, []).push('app/config/parameters.yml')

capistrano/environments/staging.rb

set :stage, :staging

set :ssh_user, 'oliboy25'
set :tmp_dir, -> { "/home/#{fetch(:ssh_user)}/tmp/capistrano" }

set :branch, 'master'
set :deploy_to, -> { "/var/www/html/#{fetch(:application)}" }

server 'my-own-domain.com',
  roles: %w{web app db},
  user: fetch(:ssh_user),
  ssh_options: {
    auth_methods: %w(publickey),
    keys: %w(staging/id_rsa)
  }

capistrano/tasks/check.cap

desc "Check that we can access everything"
task :check_write_permissions do
  on roles(:all) do |host|
    if test("[ -w #{fetch(:deploy_to)} ]")
      info "#{fetch(:deploy_to)} is writable on #{host}"
    else
      error "#{fetch(:deploy_to)} is not writable on #{host}"
    end
  end
end

Output (when using task with this configuration)

foo@bar:~$ cap staging check_write_permissions
DEBUG [dba57f80] Running /usr/bin/env [ -w /var/www/html/ ] as oliboy25@my-own-domain.com
DEBUG [dba57f80] Command: [ -w /var/www/html/ ]
DEBUG [dba57f80] Finished in 0.598 seconds with exit status 0 (successful).
INFO /var/www/html/ is writable on my-own-domain.com

Output (when I put everything in the staging file "capistrano/environments/staging.rb")

foo@bar:~$ cap staging check_write_permissions
DEBUG [dba57f80] Running /usr/bin/env [ -w /var/www/html/FooBarProject ] as oliboy25@my-own-domain.com
DEBUG [dba57f80] Command: [ -w /var/www/html/FooBarProject ]
DEBUG [dba57f80] Finished in 0.543 seconds with exit status 0 (successful).
INFO /var/www/html/ is writable on my-own-domain.com

I wonder if this happen because I changed the deploy_config_path... anyway, every variables I set in my deploy.rb file seems to be completely ignored...

Any ideas?

@mattbrictson

This comment has been minimized.

Show comment
Hide comment
@mattbrictson

mattbrictson Oct 29, 2015

Member

Yes, this is a bit tricky.

The problem is that :deploy_config_path must be an absolute path. Otherwise it will search in Ruby's default load path. So when you write this:

set :deploy_config_path, 'capistrano/deploy.rb'

You are actually instructing capistrano to load its own deploy.rb. In other words, it's as if you had written:

require "capistrano/deploy"

The solution is to pass an absolute path, which you can do in your Capfile like this:

set :deploy_config_path, File.expand_path('capistrano/deploy.rb')
Member

mattbrictson commented Oct 29, 2015

Yes, this is a bit tricky.

The problem is that :deploy_config_path must be an absolute path. Otherwise it will search in Ruby's default load path. So when you write this:

set :deploy_config_path, 'capistrano/deploy.rb'

You are actually instructing capistrano to load its own deploy.rb. In other words, it's as if you had written:

require "capistrano/deploy"

The solution is to pass an absolute path, which you can do in your Capfile like this:

set :deploy_config_path, File.expand_path('capistrano/deploy.rb')
@Oliboy50

This comment has been minimized.

Show comment
Hide comment
@Oliboy50

Oliboy50 Oct 30, 2015

Contributor

Great, it works just fine now. Thank you @mattbrictson

This should be in the doc :)

I keep this open until it's done. Feel free to close it :)

Contributor

Oliboy50 commented Oct 30, 2015

Great, it works just fine now. Thank you @mattbrictson

This should be in the doc :)

I keep this open until it's done. Feel free to close it :)

@mattbrictson

This comment has been minimized.

Show comment
Hide comment
@mattbrictson

mattbrictson Oct 30, 2015

Member

Could you open an issue for the missing documentation in the capistrano/documentation repository here?: https://github.com/capistrano/documentation/issues (this is the repo for the capistranorb.com site)

If you want to submit a PR to add the docs that would also help us a lot! 😃

Member

mattbrictson commented Oct 30, 2015

Could you open an issue for the missing documentation in the capistrano/documentation repository here?: https://github.com/capistrano/documentation/issues (this is the repo for the capistranorb.com site)

If you want to submit a PR to add the docs that would also help us a lot! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment