Capistrano 3在目录中执行 [英] Capistrano 3 execute within a directory

查看:199
本文介绍了Capistrano 3在目录中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Capistrano 3编写一个任务,该任务涉及在当前版本的目录中执行composer install。它看起来像这样:

I'm trying to write a task for Capistrano 3 that involves executing 'composer install' within the directory of the current release. It looks something like this:

namespace :composer do
  desc 'Install dependencies with Composer'
  task :install do
    on roles(:web) do
      within release_path do
        execute "#{fetch(:composer_command)} install"
      end
    end
  end
end

composer_command 在临时文件和生产文件中设置 - 在我的特殊情况下设置为 php /home/user/composer.phar

composer_command is set in the staging and production files - in my particular case to php /home/user/composer.phar

由于某种原因,此命令实际上不在当前发布目录中运行,而是在父目录(包含当前,共享,发布等)中运行

For some reason this command does not actually run in the current release directory, but instead runs in the parent directory (containing current, shared, releases, etc)

更进一步,发现当我运行一个单字命令,如:

I delved into this a bit further and found that when I ran a single word command, like:

within release_path do
    execute "pwd"
end

它工作正常,并运行当前版本中的命令目录。 但是... 当我使用空格运行命令时,例如:

It works just fine, and runs the command in the current release directory. But... when I run a command with spaces, like:

within release_path do
    execute "pwd && ls"
end

目录,而不是由块中设置的目录。

It runs in the parent directory, and not the directory set by the within block.

有人可以说明一下吗?谢谢!

Can someone shed some light on this? Thanks!

推荐答案

臭味就像第3章的错误。

Smells like a Cap 3 bug.

建议只是保证你是你想从shell角度:

I suggest just guaranteeing you are where you want to be from the shell perspective:

execute "cd '#{release_path}'; #{fetch(:composer_command)} install"

这篇关于Capistrano 3在目录中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆