Skip to content
Browse files

Merge pull request #3 from MirantisDellCrowbar/master

Updating barclamp-git
  • Loading branch information...
2 parents 478a045 + 954d645 commit 7ba6f40c747eee98a488726d7a08e648a5e6b8ee @aabes aabes committed Nov 7, 2012
View
31 git_repos.rb → build/build.rb
@@ -9,24 +9,29 @@
Dir.glob("#{ENV['CROWBAR_DIR']}/barclamps/*/crowbar.yml").each do |yml|
data = YAML.load_file(yml)
- next if data["git_repos"].nil?
+ next if data["git_repo"].nil?
bc_name = yml.split('barclamps/').last.split('/').first
repo_data[bc_name] = []
- data["git_repos"].each do |repo|
- origin, repo_name = repo.split(' ')
- repo_data[bc_name] << { repo_name => origin }
+ data["git_repo"].each do |repo|
+ repo_name, origin = repo.split(' ')
+ branches = repo.split(' ').drop(2) || []
+ repo_data[bc_name] << { repo_name => {"origin" => origin, "branches" => branches } }
end
end
p repo_data.inspect if debug
# populate git cookbook attributes
-File.open(attr_file, 'w') {|f| f.write("default[:repo_data] = #{repo_data.inspect}") }
+File.open(attr_file, 'w') {|f| f.write("default[:git][:repo_data] = #{repo_data.inspect}") }
repo_data.each do |bc_name, repos|
repos.each do |repo|
- repo.each do |repo_name, origin|
+ repo.each do |repo_name, val|
+ origin = val["origin"]
+ branches = val["branches"]
repos_path = "#{ENV['BC_CACHE']}/files/git_repos/#{bc_name}"
+ pip_cache_path = "#{ENV['BC_CACHE']}/files/pip_cache"
system "mkdir -p #{repos_path}"
+ system "mkdir -p #{pip_cache_path}"
if File.exists? "#{repos_path}/#{repo_name}.tar.bz2"
# it seems that pre-cloned repo is already existing
p "updating repo #{repo_name} from #{origin}" if debug
@@ -37,6 +42,20 @@
p "cloning #{origin} to #{repo_name}.git" if debug
system "git clone --mirror #{origin} #{repos_path}/#{repo_name}.git"
end
+ if branches.empty?
+ raw_data = `cd #{repos_path}/#{repo_name}.git && git for-each-ref --format='%(refname)' refs/heads`
+ branches = raw_data.split("\n").map{|x| x.split("refs/heads/").last}
+ end
+ p "caching pip requires packages from branches #{branches.join(' ')}" if debug
+ system "git clone #{repos_path}/#{repo_name}.git tmp"
+ if File.exists? "tmp/tools/pip-requires"
+ branches.each do |branch|
+ system "cd tmp && git checkout origin/#{branch}"
+ system "pip2tgz #{pip_cache_path} -r tmp/tools/pip-requires"
+ end
+ end
+ system "rm -fr tmp"
+ system "dir2pi #{pip_cache_path}"
p "packing #{repo_name}.git to #{repo_name}.tar.bz2" if debug
system "cd #{repos_path} && tar cjf #{repo_name}.tar.bz2 #{repo_name}.git/"
p "cleaning #{repo_name}.git" if debug
View
3 build.sh → build/build.sh
@@ -6,5 +6,6 @@ bc_needs_build() {
}
bc_build() {
- $BC_DIR/git_repos.rb
+ pip install pip2pi
+ $BC_DIR/build/build.rb
}
View
8 chef/cookbooks/git/definitions/create_user_and_dirs.rb
@@ -1,8 +1,10 @@
define :create_user_and_dirs, :action => :enable do
- user_name = params[:name]
+ user_name = params[:user_name] || params[:name]
+ comp_name = params[:comp_name] || params[:name]
+ dir_group = params[:dir_group] || "root"
dirs = ["/var/lib", "/var/log", "/var/lock", "/etc"]
- dirs.map! { |d| d += "/" + user_name }
+ dirs.map! { |d| d += "/" + comp_name }
dirs.concat(params[:opt_dirs]) if params[:opt_dirs]
user user_name do
@@ -16,7 +18,7 @@
dirs.each do |d|
directory d do
owner user_name
- group "root"
+ group dir_group
end
end
end
View
70 chef/cookbooks/git/definitions/pfs_and_install_deps.rb
@@ -2,46 +2,70 @@
comp_name = params[:name]
install_path = params[:path] || "/opt/#{comp_name}"
- ref = params[:reference] || node[@cookbook_name][:git_refspec]
+ cbook = params[:cookbook] || @cookbook_name
+ cnode = params[:cnode] || node
+ ref = params[:reference] || cnode[cbook][:git_refspec]
package("git")
package("python-setuptools")
package("python-pip")
- if node[@cookbook_name][:use_gitbarclamp]
- gitserver = search(:node, "roles:git").first
- git_url = "git@#{gitserver[:fqdn]}:#{@cookbook_name}/#{comp_name}.git"
+ if cnode[cbook][:use_gitbarclamp]
+ env_filter = " AND git_config_environment:git-config-#{cnode[cbook][:git_instance]}"
+ gitserver = search(:node, "roles:git#{env_filter}").first
+ git_url = "git@#{gitserver[:fqdn]}:#{cbook}/#{comp_name}.git"
else
- git_url = node[@cookbook_name][:gitrepo]
+ git_url = cnode[cbook][:gitrepo]
+ end
+ if cnode[cbook][:use_pip_cache]
+ provisioner = search(:node, "roles:provisioner-server").first
+ proxy_addr = provisioner[:fqdn]
+ proxy_port = provisioner[:provisioner][:web_port]
+ pip_cmd = "pip install --index-url http://#{proxy_addr}:#{proxy_port}/files/pip_cache/simple/"
+ else
+ pip_cmd = "pip install"
end
git install_path do
repository git_url
reference ref
action :sync
end
- execute "cleanup_pip_reqs_for_#{comp_name}" do
- command "echo > #{install_path}/tools/pip-requires"
- only_if {File.exists? "#{install_path}/tools/pip-requires"}
+ if cnode[comp_name]
+ unless cnode[comp_name][:pfs_deps].nil?
+ deps = cnode[comp_name][:pfs_deps].dup
+ apt_deps = deps.dup.delete_if{|x| x.include? "pip://"}
+ pip_deps = deps - apt_deps
+ pip_deps.map!{|x| x.split('//').last}
+
+ #agordeev: add setuptools-git explicitly
+ pip_deps.unshift("setuptools-git")
+
+ pip_pythonclients = pip_deps.select{|x| x.include? "client"} || []
+ apt_deps.each do |pkg|
+ pkg_version = pkg.split("==").last
+ package pkg do
+ version pkg_version if pkg_version != pkg
+ end
+ end
+ (pip_deps - pip_pythonclients).each do |pkg|
+ execute "pip_install_#{pkg}" do
+ command "#{pip_cmd} '#{pkg}'"
+ end
+ end
+ end
end
unless params[:without_setup]
+ execute "pip_install_requirements_#{comp_name}" do
+ cwd install_path
+ command "#{pip_cmd} -r tools/pip-requires"
+ end
execute "setup_#{comp_name}" do
cwd install_path
command "python setup.py develop"
creates "#{install_path}/#{comp_name == "nova_dashboard" ? "horizon":comp_name}.egg-info"
end
- end
- if node[comp_name]
- unless node[comp_name][:pfs_deps].nil?
- node[comp_name][:pfs_deps].each do |pkg|
- if pkg.include? "pip://"
- pkg = pkg.split('//').last
- execute "pip_install_#{pkg}" do
- command "pip install '#{pkg}'"
- end
- else
- pkg_version = pkg.split("==").last
- package pkg do
- version pkg_version if pkg_version != pkg
- end
- end
+ # post install clients
+ pip_pythonclients.each do |pkg|
+ execute "pip_install_clients_#{pkg}_for_#{comp_name}" do
+ command "#{pip_cmd} '#{pkg}'"
end
end
end
View
25 chef/cookbooks/git/recipes/config.rb
@@ -58,9 +58,10 @@
proxy_addr = provisioner[:fqdn]
proxy_port = provisioner[:provisioner][:web_port]
-node[:repo_data].each do |bc, repos|
+node[:git][:repo_data].each do |bc, repos|
repos.each do |repo|
- repo.each do |repo_name, repo_url|
+ repo.each do |repo_name, val|
+ repo_url = val["origin"]
file_url = "http://#{proxy_addr}:#{proxy_port}/files/git_repos/#{bc}/#{repo_name}.tar.bz2"
file_path = "#{dst_dir}/#{bc}/#{repo_name}.tar.bz2"
repo_dir = "#{home_dir}/#{bc}/#{repo_name}.git"
@@ -88,15 +89,19 @@
cwd repo_dir
user git_username
only_if do
- require 'ping'
- if repo_url.include?('@')
- repo_host = repo_url.split('@')[1].split(':').first
+ if node[:git][:update_origins]
+ require 'ping'
+ if repo_url.include?('@')
+ repo_host = repo_url.split('@')[1].split(':').first
+ else
+ repo_host = repo_url.split('/')[2]
+ end
+ begin
+ Ping.pingecho repo_host, 5
+ rescue Exception => msg
+ false
+ end
else
- repo_host = repo_url.split('/')[2]
- end
- begin
- Ping.pingecho repo_host, 5
- rescue Exception => msg
false
end
end
View
2 chef/data_bags/crowbar/bc-template-git.json
@@ -3,7 +3,7 @@
"description": "provides a git installation",
"attributes": {
"git": {
- "foo": "bar"
+ "update_origins": false
}
},
"deployment": {
View
2 chef/data_bags/crowbar/bc-template-git.schema
@@ -12,7 +12,7 @@
"type": "map",
"required": true,
"mapping": {
- "foo": { "type": "str", "required": true }
+ "update_origins": { "type": "bool", "required": true }
}
}
}
View
9 crowbar.yml
@@ -40,7 +40,9 @@ locale_additions:
git_refspec: refspec (branch, tag, commit, etc.)
use_gitbarclamp: Use barclamp git for pull from source
use_gitrepo: Use pull from source
+ git_instance: Git instance
deps: Pull from source dependencies list sepatared by a semicolon
+ use_pip_cache: Use cached pip packages
debs:
pkgs:
@@ -50,8 +52,5 @@ debs:
ubuntu-12.04:
build_pkgs:
- ruby
- build_cmd: build.sh
-
-git_repos:
- # this repo is for smoketests only
- - http://github.com/MirantisDellCrowbar/barclamp-git.git git
+ - python-pip
+ build_cmd: build/build.sh
View
6 crowbar_framework/app/views/barclamp/git/_pfsdeps.html.haml
@@ -8,9 +8,15 @@
%label{ :for => :use_gitbarclamp }= t('.use_gitbarclamp')
= select_tag :use_gitbarclamp, options_for_select([['true','true'], ['false', 'false']], @proposal.raw_data['attributes'][@proposal.barclamp]["use_gitbarclamp"].to_s), :onchange => "update_value('use_gitbarclamp', 'use_gitbarclamp', 'boolean')"
%p
+ %label{ :for => :use_pip_cache }= t('.use_pip_cache')
+ = select_tag :use_pip_cache, options_for_select([['true','true'], ['false', 'false']], @proposal.raw_data['attributes'][@proposal.barclamp]["use_pip_cache"].to_s), :onchange => "update_value('use_pip_cache', 'use_pip_cache', 'boolean')"
+%p
%label{ :for => :use_gitrepo }= t('.use_gitrepo')
= select_tag :use_gitrepo, options_for_select([['true','true'], ['false', 'false']], @proposal.raw_data['attributes'][@proposal.barclamp]["use_gitrepo"].to_s), :onchange => "update_value('use_gitrepo', 'use_gitrepo', 'boolean')"
%p
+ %label{ :for => :git_instance }= t('.git_instance')
+ = instance_selector("git", :git_instance, "git_instance", @proposal)
+%p
%label{ :for => :deps }= t('.deps')
%textarea{ :id => "pfs_deps", :onchange => "update_deps()"}
= @proposal.raw_data['attributes'][@proposal.barclamp]["pfs_deps"].join('; ')

0 comments on commit 7ba6f40

Please sign in to comment.
Something went wrong with that request. Please try again.