Permissions issues with bundler install

69 views
Skip to first unread message

Jeremy Rottman

unread,
Aug 2, 2012, 7:05:58 PM8/2/12
to webis...@googlegroups.com
I have been working on building out a my deployment cap file. We are using RVM to manage my ruby installs and so far it seems to be playing nicely with webistrano. I do however have one issue that I am trying to figure out. When I attempt to install gems, I get the following error: 

** loading stage recipe 'deploy'
 ** loading stage recipe 'init_config'
 ** loading stage recipe 'nginx'
    executing locally: "git ls-remote ######### ec2"
    command finished in 695ms
  * executing `deploy:setup'
    triggering before callbacks for `deploy:setup'
  * executing `init_config'
  * executing "gem install bundler"
    servers: ["ec2-23-23-24-42.compute-1.amazonaws.com"]
    [ec2-23-23-24-42.compute-1.amazonaws.com] executing command
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem (  6%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem (  7%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 14%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 16%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 19%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 21%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 24%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 26%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 29%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 30%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 33%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 35%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 38%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 42%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 43%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 49%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 55%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 60%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 62%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 67%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 72%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 75%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 78%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 79%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 84%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 91%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 93%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 97%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem ( 98%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] Fetching: bundler-1.1.5.gem (100%)
Fetching: bundler-1.1.5.gem (100%)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] 
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] ERROR:  While executing gem ... (Gem::FilePermissionError)
 ** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] You don't have write permissions into the /home/ubuntu/.rvm/gems/ruby-1.9.2-p290 directory.
    command finished in 1542ms
*** failed: "bash --login -c 'gem install bundler'" on ec2-23-23-24-42.compute-1.amazonaws.com

This is my current capfile, I have omitted some details.

load 'deploy'

# ================================================================
# ROLES
# ================================================================


    role :app, "ec2-23-23-24-42.compute-1.amazonaws.com"
  

# ================================================================
# VARIABLES
# ================================================================

# Webistrano defaults
  set :webistrano_project, "sweet_high"
  set :webistrano_stage, "staging"


  set :application, ""

  set :branch, "ec2"

  set :bundle_disable_shared_gems, "\"1\""

  set :bundle_path, "vendor/bundler_gems"

  set :default_shell, "bash --login"

  set :deploy_to, "/data/\#{application}"

  set :deploy_via, :remote_cache

  set :domain, ""

  set :environment, "staging"

  set :group, "ubuntu"

  set :nginx_conf_path, "/etc/nginx/sites-enabled"

  set :password, "deployment_user(SSH user) password"

  set :rails_env, "staging"

  set :repository, ""

  set :runner, "ubuntu"

  set :rvm_bin_path, "/home/#{user}/.rvm/bin/rvm"

  set :rvm_type, :user

  set :scm, :git

  set :scm_password, "your_SVN_password"

  set :scm_username, "your_SVN_user"

  set :ssh_options, {:forward_agent => true,:paranoid => false,:keys => ["/home/#{user}/.ssh/rails_app_server.pem"]}

  set :use_sudo, true

  set :user, "ubuntu"




# ================================================================
# TEMPLATE TASKS
# ================================================================

        # allocate a pty by default as some systems have problems without
        default_run_options[:pty] = true
      
        # set Net::SSH ssh options through normal variables
        # at the moment only one SSH key is supported as arrays are not
        # parsed correctly by Webistrano::Deployer.type_cast (they end up as strings)
        [:ssh_port, :ssh_keys].each do |ssh_opt|
          if exists? ssh_opt
            logger.important("SSH options: setting #{ssh_opt} to: #{fetch(ssh_opt)}")
            ssh_options[ssh_opt.to_s.gsub(/ssh_/, '').to_sym] = fetch(ssh_opt)
          end
        end
         


# ================================================================
# CUSTOM RECIPES
# ================================================================


  before "deploy:setup", :init_config
after "deploy:setup", :setup_cleanup
namespace :init_config do
  desc <<-DESC
       Created directory structure, changes ownership, etc...
  DESC
  
  task :default do
    run "gem install bundler"
    run "sudo mkdir -p #{deploy_to}"
    run "sudo chown -R #{user}:#{group} #{deploy_to}"
    run "mkdir -p #{shared_path}/config"
    run "mkdir -p #{shared_path}/config"
    File.open("/home/#{user}/.ssh/id_rsa", "rb").each_line{ |line|
      run "echo #{line} >> ~/.ssh/id_rsa"
    }
    run "chown #{user}:#{group} ~/.ssh/id_rsa"
    run "chmod 600 ~/.ssh/id_rsa"    
  end
end

namespace :setup_cleanup do
  task :default do
   run "sudo chown -R #{user}:#{group} #{deploy_to}"    
  end
end

namespace :deploy do
  task :bundle, :roles => :app do
    run "cd #{release_path} && mkdir -p .bundler"
    run "cd #{release_path}/.bundler && touch config"
    run "echo BUNDLE_PATH: #{bundle_path} >> #{release_path}/.bundler/config"
    run "echo BUNDLE_DISABLE_SHARED_GEMS: #{bundle_disable_shared_gems} >> #{release_path}/.bundler/config"
    run "cd #{release_path} && bundle install"

    on_rollback do
      if previous_release
        run "cd #{previous_release} && bundle install"
      else
        logger.important "no previous release to rollback to, rollback of bundler:install skipped"
      end
    end
  end

  task :bundle_new_release, :roles => :db do
    deploy.bundle
  end
  desc <<-DESC
    Restarts application
  DESC
  task :restart, :roles => :app do
    run "cd #{current_path} && touch tmp/restart.txt"
  end
end

after "deploy:rollback:revision", "deploy:bundle"
after "deploy:update_code", "deploy:bundle_new_release"

after "deploy:setup", :nginx
after :nginx, "nginx:restart"


namespace :nginx do
  desc "Create nginx.conf and generates nginx.conf symlink"
  task :default, :roles => :app do
    config_content = from_template("config/nginx.#{environment}.conf.erb")
    put config_content, "#{shared_path}/config/nginx.conf"
    run "sudo ln -nfs #{shared_path}/config/nginx.conf #{nginx_conf_path}/000-default"
  end
  
  task :restart, :roles => :app do
    run "sudo /etc/init.d/nginx restart"
  end
end 

def get_binding
  binding # So that everything can be used in templates generated for the servers
end

def from_template(file)
  require 'erb'
  template = File.read(File.join(RAILS_ROOT, "/", file))
  result = ERB.new(template).result(self.get_binding)
end



Reply all
Reply to author
Forward
0 new messages