简体   繁体   中英

ruby on rails app deployment using chef cookbook ec

I am trying to deploy ruby on rails application with chef, I am facing an issue. During the code deployment I need to run bundle update/bundle install. I am trying to figure out how do I run the command. I tried with "bundler true" the chef threw error while deploying. So I wrote a function

execute "bundler" do
command "bundle install"
ssh_wrapper "/home/ubuntu/.ssh/chef_ssh_deploy_wrapper.sh"
end

Since my gemfile includes gems and code repo's for github and other bit bucket accounts, it stops to add it to known_hosts and chef fails to move further.

How do avoid such issue and do a smooth deployment. Kindly suggest.

Typically I would use

  • chef for provisioning servers
  • capistrano for deploying code (including installing gems)

That being said you can configure the user account with ssh config to not have strict checking

# files/ssh_config
Host github.com
    StrictHostKeyChecking no    

# recipes/user_setup.rb
user = "someuser"
cookbook_file "/home/#{user}/.ssh/config" do
  source "ssh_config"
  owner "#{user}"
  group "#{user}"
  mode "0600"
end

You may run into issues trying to bundle install gems during chef deployment, as chef is using its own isolated ruby install for the purpose of executing chef scripts, you don't want to bundle into this ruby, but into the installed ruby you have specified

Again I would recommend using capistrano for deployment

Also recommend using the ubuntu user for provisioning using chef, but a secondary account for running your rails application, capistrano would deploy using this application account

Your issue comes from not having established an initial ssh connections to github, etc. I use the following configuration in my .ssh/config file:

Host github StrictHostKeyChecking no UserKnownHostsFile=/dev/null LogLevel=ERROR User yourdeployuser IdentityFile ~/.ssh/somefile.pem

The gist of this, is that you're expressly telling ssh that you don't need, or want to make use of the known hosts feature in ssh when connecting to github.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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