From f6dbc1a96b9e738f09ac902a9f931fb62cf85c90 Mon Sep 17 00:00:00 2001 From: Ben Lisbakken Date: Fri, 23 Mar 2012 11:37:30 -0700 Subject: [PATCH] Add --local option in chef deployer to deploy local changes when using chef to deploy bosh. Change-Id: I30355b5a9ae4850d8586d0556d6ef24cb80c350e --- chef_deployer/Gemfile.lock | 39 +++++++++++++++--------------- chef_deployer/lib/chef_deployer.rb | 14 ++++++++--- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/chef_deployer/Gemfile.lock b/chef_deployer/Gemfile.lock index 65303cb0e40..d5c3951b6f9 100644 --- a/chef_deployer/Gemfile.lock +++ b/chef_deployer/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - chef_deployer (0.0.7) + chef_deployer (0.0.9) chef nats net-scp @@ -13,57 +13,58 @@ PATH GEM remote: http://rubygems.org/ specs: + abstract (1.0.0) bunny (0.6.0) - chef (0.9.14) + chef (0.9.12) bunny (>= 0.6.0) erubis extlib highline - json (<= 1.4.6, >= 1.4.4) + json (>= 1.4.4, <= 1.4.6) mixlib-authentication (>= 1.1.0) mixlib-cli (>= 1.1.0) mixlib-config (>= 1.1.2) mixlib-log (>= 1.2.0) moneta ohai (>= 0.5.7) - rest-client (< 1.7.0, >= 1.0.4) + rest-client (>= 1.0.4, < 1.7.0) uuidtools - daemons (1.1.2) - erubis (2.7.0) + daemons (1.1.8) + erubis (2.6.6) + abstract (>= 1.0.0) eventmachine (0.12.10) extlib (0.9.15) - highline (1.6.1) + highline (1.6.11) json (1.4.6) - json_pure (1.5.1) - mime-types (1.16) + json_pure (1.6.5) + mime-types (1.17.2) mixlib-authentication (1.1.4) mixlib-log mixlib-cli (1.2.0) mixlib-config (1.1.2) mixlib-log (1.3.0) moneta (0.6.0) - nats (0.4.8) + nats (0.4.10) daemons (>= 1.1.0) eventmachine (>= 0.12.10) json_pure (>= 1.5.1) net-scp (1.0.4) net-ssh (>= 1.99.1) - net-ssh (2.1.4) - net-ssh-gateway (1.0.1) + net-ssh (2.2.2) + net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) - ohai (0.5.8) - extlib - json (<= 1.4.6, >= 1.4.4) + ohai (0.6.10) mixlib-cli mixlib-config mixlib-log - systemu - rest-client (1.6.1) + systemu (~> 2.2.0) + yajl-ruby + rest-client (1.6.3) mime-types (>= 1.16) - systemu (1.2.0) + systemu (2.2.0) thor (0.14.6) uuidtools (2.1.2) - yajl-ruby (0.8.2) + yajl-ruby (1.1.0) PLATFORMS ruby diff --git a/chef_deployer/lib/chef_deployer.rb b/chef_deployer/lib/chef_deployer.rb index cba27fd14ca..123cf6a8f12 100644 --- a/chef_deployer/lib/chef_deployer.rb +++ b/chef_deployer/lib/chef_deployer.rb @@ -20,7 +20,7 @@ class Deploy < Thor BASE_PATH = Dir.pwd COOKBOOKS_PATH = File.join(BASE_PATH, "cookbooks") SSH_WRAPPER = File.join(File.expand_path("../../bin", __FILE__), "chef_deployer_ssh_wrapper") - ENV['GIT_SSH'] = SSH_WRAPPER + ENV["GIT_SSH"] = SSH_WRAPPER no_tasks do def mask @@ -149,9 +149,12 @@ def answer_ssh(command, password) end end - def update_remote_repo(repo, ssh_host, ssh_user, ssh_options) + def update_remote_repo(repo, options, ssh_host, ssh_user, ssh_options) Net::SSH.start(ssh_host, ssh_user, ssh_options) do |ssh| # git init is safe to run on an existing repo + if options.local + ssh.exec!("rm -rf #{@remote_repo_cache}") + end ssh.exec!("mkdir -p #{@remote_repo_cache}/#{repo} && cd #{@remote_repo_cache}/#{repo} && git init --bare") end @@ -288,6 +291,7 @@ def connect(uri) desc "deploy CLOUD", "deploy CLOUD" method_option :roles, :type => :array method_option :metadata, :type => :boolean, :default => true + method_option :local, :type => :boolean, :default => false method_option :config, :type => :string, :default => "config.yml" def deploy(cloud) if File.directory?(cloud) @@ -372,6 +376,10 @@ def deploy(cloud) say_status :config, "reading repo configuration" role_repo_mapping = {} repo_config = YAML.load_file(File.join(BASE_PATH, "config", "repos.yml")) + if options.local + repo_config["bosh"]["uri"] = `pwd`.split("/")[0..-2].join("/") + repo_config["bosh"]["SCM"] = "NONE" + end repo_config.each do |name, config| required_repo = false config["roles"].each do |role| @@ -392,7 +400,7 @@ def deploy(cloud) repos.each do |repo| say_status :repos, "uploading #{repo} to #{host}" connect(uri) do |*ssh_args| - update_remote_repo(repo, *ssh_args) + update_remote_repo(repo, options, *ssh_args) end end end