简体   繁体   English

使用Capistrano在EC2上部署Torquebox应用

[英]Deploying Torquebox app on EC2 with Capistrano

I'm running a rails app using JRuby 1.7.1 with Torquebox and trying to deploy on EC2 but I'm seeing the following error when I run 'cap deploy': 我正在将JRuby 1.7.1与Torquebox结合使用来运行Rails应用程序,并尝试在EC2上进行部署,但是在运行“ cap deploy”时遇到以下错误:

 * 2013-10-08 21:28:55 executing `deploy'
  * 2013-10-08 21:28:55 executing `deploy:update'
 ** transaction: start
  * 2013-10-08 21:28:55 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote https://github.com/mygithubhandle/myreponame.git master"
    command finished in 503ms
  * executing "if [ -d /opt/apps/myappname/shared/cached-copy ]; then cd /opt/apps/myappname/shared/cached-copy && git fetch  origin && git fetch --tags  origin && git reset  --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean  -d -x -f; else git clone -b master  /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi"myappname/shared/cached-copy && git fetch  origin && git fetch --tags  origin && git reset  --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean  -d -x -f; else git clone -b master https://github.com/mygithubhandle/myreponame.git /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi"
    servers: ["XX.XXX.XXX.XX"]
    [ec2-user@XX.XXX.XXX.XX] executing command
 ** [XX.XXX.XXX.XX :: out] sh: git: command not found
    command finished in 268ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /opt/apps/pickemup-api/releases/20131009042856; true"
    servers: ["XX.XXX.XXX.XX"]
    [ec2-user@XX.XXX.XXX.XX] executing command
    command finished in 259ms
failed: "env JRUBY_OPTS=--1.9 PATH=/opt/torquebox/current/jboss/bin:/opt/torquebox/current/jruby/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/root/bin sh -c 'if [ -d /opt/apps/myappname/shared/cached-copy ]; then cd /opt/apps/myappname/shared/cached-copy && git fetch  origin && git fetch --tags  origin && git reset  --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean  -d -x -f; else git clone -b master https://github.com/mygithubhandle/myreponame.git /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi'" on ec2-user@XX.XXX.XXX.XX

My deploy.rb file: 我的deploy.rb文件:

require 'torquebox-capistrano-support'
require 'bundler/capistrano'

set :ssh_options, {:forward_agent => true}
server       "ec2-user@XX.XXX.XXX.XX", :web, :app, :primary => true
set :repository,  "https://github.com/mygithubhandle/mygithubrepo.git"
set :branch,            "master"
set :user,              "torquebox"
set :scm,               :git
set :scm_verbose,       true
set :use_sudo,          false
set :deploy_via, :remote_cache

default_run_options[:pty] = true
ssh_options[:auth_methods] = ["publickey"]
ssh_options[:keys] = ["path/to/my/pem/key"]

set :deploy_to,         "/opt/apps/myappname"
set :torquebox_home,    "/opt/torquebox/current"
set :jboss_init_script, "/etc/init.d/jboss-as-standalone"
set :rails_env, 'production'
set :app_context,       "/"
set :app_ruby_version, '1.9'
set :application, "myappname"
set :jruby_home,      '/usr/local/jruby'

default_environment['JRUBY_OPTS'] = '--1.9'
default_environment['PATH'] = '/opt/torquebox/current/jboss/bin:/opt/torquebox/current/jruby/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/root/bin'

after 'deploy:update_code', 'deploy:assets:precompile'
after 'deploy:update', 'deploy:resymlink'
before 'deploy:finalize_update', 'deploy:assets:symlink'

namespace :deploy do
  desc "relink db directory"
   #if you use sqlite
   task :resymlink, :roles => :app do
     run "mkdir -p #{shared_path}/db; rm -rf #{current_path}/db && ln -s #{shared_path}/db #{current_path}/db && chown -R torquebox:torquebox  #{current_path}/db"
   end


   # This is a weird part. I've found that asset complation with JRuby can really hog up the memory, which can cause the application to crash
   # when doing a deploy. So, I like to compile the assets locally and SCP them to the server instead.
   # Just make sure you've commented out the load deploy/assets in your Capfile.
  namespace :assets do
    # If you want to force the compilation of assets, just set the ENV['COMPILE_ASSETS']
     task :precompile, :roles => :web do
       force_compile = ENV['COMPILE_ASSETS']
       begin # on first deploys, there is no current_revision so an error gets raised. in this case we want to just compile assets and upload them.
         from = source.next_revision(current_revision)
       rescue
         force_compile = true
       end
       if ( force_compile) or (capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 )
         run_locally("rake assets:clean && rake assets:precompile")
         run_locally "cd public && tar -jcf assets.tar.bz2 assets"
         top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
         run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
         run_locally "rm public/assets.tar.bz2"
         run_locally("rake assets:clean")
       else
        logger.info "Skipping asset precompilation because there were no asset changes"
       end
     end

     task :symlink, roles: :web do
       run ("rm -rf #{latest_release}/public/assets &&
             mkdir -p #{latest_release}/public &&
             mkdir -p #{shared_path}/assets &&
             ln -s #{shared_path}/assets #{latest_release}/public/assets")
     end
  end
end

Any ideas on what could be going wrong here? 关于这里可能出什么问题的任何想法?

Git client isn't installed on the box you are deploying to. Git客户端未安装在要部署到的盒子上。 You can fix it by logging in as root to your ec2 instance and installing get. 您可以通过以root用户身份登录到ec2实例并安装get来修复它。 (yum install git or apt-get install git) (百胜安装git或apt-get安装git)

Or you can change your deployment strategy to copy, which is slower than :remote_cache. 或者,您可以更改部署策略以进行复制,这要比:remote_cache慢。 Copy will checkout on your local machine and scp/sftp all the files over to the server being deployed to. 复制将在本地计算机上签出,然后将所有文件scp / sftp转移到要部署到的服务器上。

set :deploy_via, :copy

You need "git" in your system. 您的系统中需要“ git”。 apt-get install git should do the trick. apt-get install git应该可以解决问题。 However, there are a few more possible issues you can stumble upon. 但是,您可能会遇到其他一些可能的问题。 I have written an article on my company's blog to document my struggle and solution. 我在公司博客上写了一篇文章 ,记录了我的奋斗和解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM