dcmbrown
dcmbrown

Reputation: 1109

capistrano upload! thinks ~ referenced local directory is on remote server

So every example I've looked up indicates this is how one is supposed to do it but I think I may have found a bug unless there's another way to do this. I'm using upload! to upload assets to a remote list of servers. The task looks like this:

  desc "Upload grunt compiled css/js."
  task :upload_assets do
    on roles(:all) do 
      %w{/htdocs/css /htdocs/js}.each do |asset|
          upload! "#{fetch(:local_path) + asset}", "#{release_path.to_s + '/' + asset}", recursive: true
      end
    end
  end

If local_path is defined as an absolute path such as:

set :local_path:,  '/home/dcmbrown/projects/ABC'

This works fine. However if I do the following:

set :local_path:,  '~/projects/ABC'

I end up getting the error:

The deploy has failed with an error: Exception while executing on ec2-54-23-88-125.us-west-2.compute.amazon.com: No such file or directory - ~/projects/ABC/htdocs/css

It's not a ' vs " issue as I've tried both (and I didn't think capistrano paid attention to that anyway).

Is this a bug? Is there a work around? Am I just doing it wrong?

Upvotes: 2

Views: 603

Answers (2)

dcmbrown
dcmbrown

Reputation: 1109

I ended up discovering the best way to do this is to actually use path expansion! (headsmack)

irb> File.expand_path('~dcmbrown/projects/ABC')
=> "/home/dcmbrown/projects/ABC"

Of course what I'd like is to do automatic path expansion but you can't have everything. I think I was mostly dumbstruck that it didn't automatically; so much so I spent a couple of hours trying to figure out why it didn't work and ended up wasting time asking here. :(

Upvotes: 2

SupaIrish
SupaIrish

Reputation: 766

I don't think the error is coming from the remote server, it just looks like it since it's running that upload command in the context of a deploy.

I just created a single cap task to just do an upload using the "~" character and it also fails with

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@XXX: No such file or directory @ rb_file_s_stat - ~/Projects/testapp/public/404.html

It appears to be a Ruby issue not Capistrano as this also fails in a Ruby console

~/Projects/testapp $ irb
2.2.2 :003 > File.stat('~/Projects/testapp/public/404.html')

Errno::ENOENT: No such file or directory @ rb_file_s_stat - ~/Projects/testapp/public/404.html
from (irb):3:in `stat'
from (irb):3
from /Users/supairish/.rvm/rubies/ruby-2.2.2/bin/irb:11:in `<main>'

Upvotes: 0

Related Questions