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

Fetch :deploy_to from stage file #22

Closed
feedmeastraycat opened this issue Jul 23, 2014 · 14 comments
Closed

Fetch :deploy_to from stage file #22

feedmeastraycat opened this issue Jul 23, 2014 · 14 comments

Comments

@feedmeastraycat
Copy link

In my deploy.rb I have set :deploy_to, '/var/www/my_app' but in my production.rb I have to have set :deploy_to, '/home/http/my_app/deploy'. Composer is downloaded and installed into /home/http/my_app/deploy/shared/ but when Capistrano tries to run it to install the vendor dir it fails because it looks for /var/www/my_app.

The only way to get around this is to move the correct set :deploy_to directly in the deploy.rb file. But now I have to change it manually each time I deploy to staging or dev.

Not sure if I have done something wrong though. :) I'm still quite new to Capistrano and my only Ruby knowledge is from Capistrano.

These are my composer settings in deploy.rb:

set :composer_install_flags, "--no-dev --no-interaction --optimize-autoloader --prefer-dist"
set :composer_roles, :all
set :composer_dump_autoload_flags, '--optimize'
set :composer_download_url, "https://getcomposer.org/installer"

SSHKit.config.command_map[:composer] = "#{shared_path.join("composer.phar")}"
@swalkinshaw
Copy link
Member

Could be a Cap bug but try defining deploy_to in a lambda like this:

set :deploy_to, -> { '/var/www/my_app' }

Some workaround like the following may work as well:

# deploy.rb
if fetch(:stage) == 'production'
  set :deploy_to, '/home/http/my_app/deploy'
else
  set :deploy_to, '/var/www/my_app'
end

@feedmeastraycat
Copy link
Author

Thanks for your input! The lambda thing didn't seem to help. The workaround would though. But I would rather have the config separate.

But you think that it could be an issue in SSHKit rather maybe? (I guess that makes more sense).

@swalkinshaw
Copy link
Member

capistrano/capistrano#845
capistrano/capistrano#815

Seem related to deploy_to in stage files.

@swalkinshaw
Copy link
Member

Oh one more thing to try is:

SSHKit.config.command_map[:composer] = "#{fetch(:shared_path).join("composer.phar")}"
# and maybe even (not sure if SSHKit supports the lambda usage)
SSHKit.config.command_map[:composer] = -> { "#{fetch(:shared_path).join("composer.phar")}" }

@feedmeastraycat
Copy link
Author

SSHKit.config.command_map[:composer] = "#{fetch(:shared_path).join("composer.phar")}"

Results in NoMethodError: undefined methodjoin' for nil:NilClass`. The lambda thing didn't work either.

The weird thing I guess, to me, is that composer.phar is downloaded to the correct path. So having :deploy_to set in both deploy.rb and production.rb/staging.rb works for everything except when capistrano/composer tries to run composer.

I'm not 100% sure but I assume its that SSHKit line. It doesn't fetch the right :shared_path somehow.

@feedmeastraycat
Copy link
Author

If I do:

warn "#{shared_path.join("composer.phar")}"

In a task in :deploy namespace after :starting for example. I get the correct path. So maybe SSHKit runs "to early" or something.

@swalkinshaw
Copy link
Member

@swalkinshaw
Copy link
Member

I guess you could try:

set :composer_path = -> { fetch(:shared_path).join('composer.phar') }
SSHKit.config.command_map[:composer] = composer_path

But not sure about that since you're supposed to use fetch but that doesn't seem to work in the command map.

@feedmeastraycat
Copy link
Author

Ah. Yeah. I Googled it but didnt find that one. -1 Google skills. :)

I moved the command_map line into that task. Which worked. So my assumption maybe was correct. I guess that's an "ok" solution.

namespace :deploy do

    before :starting, :map_composer_command do
        on roles(:app) do |server|
            SSHKit.config.command_map[:composer] = "#{shared_path.join("composer.phar")}"
        end
    end

...

Not sure that is the "right" solution though :)

@feedmeastraycat
Copy link
Author

I tried a couple of different other like your last example there. But none work.

My task solution works at least. Even though it doesn't feel like a 100% proper solution. :)

Thanks for your time though!

@davidlonjon
Copy link

anks feedmeastraycat for your solution. I had the same problem and got it working thanks to yours which is the best so far (at least for me :))

@gagarine
Copy link
Member

The "task solution" is kind of ugly. And if you have more than one executable it's not very user friendly. Can we reopen this issue?

@webdevilopers
Copy link

👍 for a constant solution @gagarine @davidlonjon ! Please also see issue #43.

@webdevilopers
Copy link

Any news on this?

@capistrano capistrano locked and limited conversation to collaborators Mar 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants