2016-05-30 113 views
1

我试图使用github webhooks和capistrano实现持续部署例程。当通过github webhook执行capistrano部署shell脚本失败

我的计划是将我的capistrano rake任务放在一个shell脚本中,并从另一个rails项目(这是github webhook)的控制器操作中调用它。

这里是shell脚本(wallet_deploy.sh)

#!/bin/bash 
cd $HOME/work/wallet 
bundle exec cap production deploy > wallet_deploy_log 2>&1 

这里是日志

/home/deploy/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:304:in `block in replace_gem': capistrano is not part of the bundle. Add it to Gemfile. (Gem::LoadError) 
    from /home/deploy/.rbenv/versions/2.2.4/bin/cap:22:in `<main>' 

这里是控制器动作

def release_request 
    system("./wallet_deploy.sh") 
    #DeployWorker.perform_async // tried using a worker too with no success 

    render :text => params.to_s 
end 

章部署完美的作品时,我在shell中手动执行它

[email protected]:~/apps/ci/current$ ./wallet_deploy.sh 

不知道我在做什么错,是否有不同的方法来实现这个?

回答

0

您正在监听webhook的Rails应用程序已经拥有自己的Bundler环境。当您尝试使用system来诠释您的脚本时,该脚本会继承当前的Bundler环境。这可能是你为什么得到“capistrano不是捆绑包”的错误。

为了确保新鲜捆扎机的环境中使用您的脚本,试试这个:

Bundler.with_clean_env do 
    system("./wallet_deploy.sh") 
end 

从捆扎机的bundle execdocumentation

打开一个子shell(如系统中的任何Ruby代码,反引号,或%x {})将自动使用当前的Bundler环境。如果您需要对不属于当前包的Ruby命令执行shell命令,请在块中使用with_clean_env方法。

和:

使用with_clean_env也是必要的,如果你是炮击了一个不同的包。任何在子shell中运行的Bundler命令都将继承当前的Gemfile,因此需要在不同bundle的上下文中运行的命令也需要使用with_clean_env。

+0

谢谢!它的工作 –

+0

@SharnJayantha你可以标记答案为接受,然后呢?谢谢 –