1

I am trying to deploy a Django project with Capistrano. Capistrano deploys the code to my server and finishes deploy steps.

But when I try add a custom task like this...

task :collect_static do
  on roles(:app) do |host|
    execute "cd #{release_path}/myproject"
    execute "workon myproject"
    execute "./manage.py collectstatic"
  end
end

after "deploy:updated", "collect_static"

It throws the following error...

02 bash: workon: command not found

After the deploy, if I SSH manually onto server and run workon command it works fine(same user). Just Capistrano doesn't recognise it?

polarcare
  • 575
  • 1
  • 6
  • 24
  • Probably an issue with .bashrc or .profile not being loaded, see [this answer](https://stackoverflow.com/questions/4978564/invoking-bash-aliases-in-rake). What does `type workon` return? – ConorSheehan1 Sep 12 '18 at 11:06
  • Yeah I've tried "source ~/.bashrc and .profile" but no joy. Not sure how to get Capistrano to acknowledge it. – polarcare Sep 12 '18 at 11:18
  • Could also be that you're using execute instead of system. What does `type workon` return when you enter it in the console? – ConorSheehan1 Sep 12 '18 at 11:23
  • type workon returns "workon is a function \n workon() {function code displayed}" – polarcare Sep 12 '18 at 12:07

1 Answers1

2

workon is not a program but a shell function from virtualenvwrapper. For bash to find it you have to source virtualenvwrapper.sh in the shell.

phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    Switching from "workon" to "source /path/to/.virtualenvs/myproject/bin/activate" works. Thank you for your help. – polarcare Sep 12 '18 at 15:08