From 0a0aa440656a499adb7c37f84654da80d4d2836e Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 5 May 2011 15:36:08 -0400 Subject: [PATCH] Added apt::repo recipe. Move vpc::apt to vpc::apt_config. Updated vpc::apt_config so that it waits for the local APT repo to load and adds the local repo's sources.list.d config file. --- cookbooks/apt/attributes/apt.rb | 3 + cookbooks/apt/definitions/reprepro.rb | 18 +++ cookbooks/apt/files/default/apt-noauth.conf | 1 + .../recipes/apt.rb => apt/recipes/noauth.rb} | 21 ++-- cookbooks/apt/recipes/repo.rb | 114 ++++++++++++++++++ cookbooks/apt/templates/default/Release.erb | 6 + .../apt/templates/default/distributions.erb | 8 ++ .../apt/templates/default/nginx.conf.erb | 20 +++ cookbooks/apt/templates/default/options.erb | 1 + .../server_names_hash_bucket_size.conf.erb | 1 + cookbooks/vpc/attributes/apt.rb | 4 +- cookbooks/vpc/recipes/apt_config.rb | 61 ++++++++++ cookbooks/vpc/recipes/default.rb | 2 +- cookbooks/vpc/recipes/dev_setup.rb | 2 +- cookbooks/vpc/recipes/nova_compute_setup.rb | 8 -- roles/apt-repo.rb | 14 +++ roles/glance-api.rb | 3 +- roles/glance-registry.rb | 3 +- roles/nova-base.rb | 3 +- 19 files changed, 266 insertions(+), 27 deletions(-) create mode 100644 cookbooks/apt/attributes/apt.rb create mode 100644 cookbooks/apt/definitions/reprepro.rb create mode 100644 cookbooks/apt/files/default/apt-noauth.conf rename cookbooks/{vpc/recipes/apt.rb => apt/recipes/noauth.rb} (64%) create mode 100644 cookbooks/apt/recipes/repo.rb create mode 100644 cookbooks/apt/templates/default/Release.erb create mode 100644 cookbooks/apt/templates/default/distributions.erb create mode 100644 cookbooks/apt/templates/default/nginx.conf.erb create mode 100644 cookbooks/apt/templates/default/options.erb create mode 100644 cookbooks/apt/templates/default/server_names_hash_bucket_size.conf.erb create mode 100644 cookbooks/vpc/recipes/apt_config.rb create mode 100644 roles/apt-repo.rb diff --git a/cookbooks/apt/attributes/apt.rb b/cookbooks/apt/attributes/apt.rb new file mode 100644 index 0000000..3b97edd --- /dev/null +++ b/cookbooks/apt/attributes/apt.rb @@ -0,0 +1,3 @@ +default[:apt][:repo_codename] = "maverick" +default[:apt][:repo_name] = "ubuntu" +default[:apt][:repo_archs] = "amd64" diff --git a/cookbooks/apt/definitions/reprepro.rb b/cookbooks/apt/definitions/reprepro.rb new file mode 100644 index 0000000..a235826 --- /dev/null +++ b/cookbooks/apt/definitions/reprepro.rb @@ -0,0 +1,18 @@ +define :add_deb_to_repo do + +filename=params[:name] # use name param as the repo name +codename=params[:codename] +repo_dir=params[:repo_dir] + +bash "reprepro deb: #{filename}" do + cwd "/tmp" + user "root" + code <<-EOH + cd #{repo_dir} + reprepro includedeb "#{codename}" "#{filename}" + rm "#{filename}" + EOH + only_if { File.exists?(filename) } +end + +end diff --git a/cookbooks/apt/files/default/apt-noauth.conf b/cookbooks/apt/files/default/apt-noauth.conf new file mode 100644 index 0000000..77edd28 --- /dev/null +++ b/cookbooks/apt/files/default/apt-noauth.conf @@ -0,0 +1 @@ +APT::Get::AllowUnauthenticated 1; diff --git a/cookbooks/vpc/recipes/apt.rb b/cookbooks/apt/recipes/noauth.rb similarity index 64% rename from cookbooks/vpc/recipes/apt.rb rename to cookbooks/apt/recipes/noauth.rb index 3b86f3f..7214184 100644 --- a/cookbooks/vpc/recipes/apt.rb +++ b/cookbooks/apt/recipes/noauth.rb @@ -1,8 +1,8 @@ # -# Cookbook Name:: Rackspace -# Recipe:: packages +# Cookbook Name:: apt +# Recipe:: noauth # -# Copyright 2011, Rackspace +# Copyright 2011, Dan Prince # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,14 +16,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -include_recipe 'apt' - -apt_repository "openstack" do - key "2A2356C9" - keyserver "keyserver.ubuntu.com" - uri "http://ppa.launchpad.net/nova-core/trunk/ubuntu" - distribution node[:apt][:distro] - components(["main"]) - action :add +cookbook_file "/etc/apt/apt.conf.d/02noauth" do + source "apt-noauth.conf" + owner "root" + group "root" + mode 0644 end diff --git a/cookbooks/apt/recipes/repo.rb b/cookbooks/apt/recipes/repo.rb new file mode 100644 index 0000000..43c452a --- /dev/null +++ b/cookbooks/apt/recipes/repo.rb @@ -0,0 +1,114 @@ +# +# Cookbook Name:: apt +# Recipe:: repo +# +# Copyright 2011, Dan Prince. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package "reprepro" do + action :install +end + +["/var/packages", "/var/packages/#{node[:apt][:repo_name]}", "/var/packages/#{node[:apt][:repo_name]}/conf", "/var/packages/#{node[:apt][:repo_name]}/dists", "/var/packages/#{node[:apt][:repo_name]}/dists/#{node[:apt][:repo_codename]}", "/var/packages/#{node[:apt][:repo_name]}/dists/#{node[:apt][:repo_codename]}/main"].each do |dirname| + directory dirname do + owner "root" + group "root" + mode 0755 + action :create + end +end + +template "/var/packages/#{node[:apt][:repo_name]}/conf/distributions" do + source "distributions.erb" + mode 0644 + variables( + :repo_archs => node[:apt][:repo_archs], + :repo_name => node[:apt][:repo_name], + :code_name => node[:apt][:repo_codename] + ) +end + +file "/var/packages/#{node[:apt][:repo_name]}/conf/override.#{node[:apt][:repo_codename]}" do + action :touch +end + +template "/var/packages/#{node[:apt][:repo_name]}/conf/options" do + source "options.erb" + mode 0644 +end + +if node[:apt][:upload_package_dir] then + rbfiles = File.join(node[:apt][:upload_package_dir], "*.deb") + Dir.glob(rbfiles).each do |deb| + add_deb_to_repo deb do + repo_dir "/var/packages/#{node[:apt][:repo_name]}" + codename node[:apt][:repo_codename] + end + end +end + +# create default Release file (also created by reprepro +release_file="/var/packages/#{node[:apt][:repo_name]}/dists/#{node[:apt][:repo_codename]}/Release" +template release_file do + source "Release.erb" + mode 0644 + variables( + :repo_archs => node[:apt][:repo_archs], + :repo_name => node[:apt][:repo_name], + :code_name => node[:apt][:repo_codename] + ) + not_if { File.exists?(release_file) } +end + +# create empty Packages.gz files if needed +node[:apt][:repo_archs].each do |arch| + directory "/var/packages/#{node[:apt][:repo_name]}/dists/#{node[:apt][:repo_codename]}/main/binary-#{arch}/" do + owner "root" + group "root" + mode 0755 + action :create + end + packages_list = "/var/packages/#{node[:apt][:repo_name]}/dists/#{node[:apt][:repo_codename]}/main/binary-#{arch}/Packages.gz" + execute "echo -n | gzip > #{packages_list}" do + not_if { File.exists?(packages_list) } + end +end + +package "nginx" do + action :install +end + +template "/etc/nginx/conf.d/server_names_hash_bucket_size.conf" do + source "server_names_hash_bucket_size.conf.erb" + mode 0644 +end + +vhost_conf="/etc/nginx/sites-available/vhost-#{node[:apt][:repo_name]}.conf" +template vhost_conf do + source "nginx.conf.erb" + variables( + :server_name => node[:fqdn] + ) + mode 0644 +end + +link "/etc/nginx/sites-enabled/vhost-#{node[:apt][:repo_name]}.conf" do + to vhost_conf +end + +service "nginx" do + action :start + subscribes :restart, resources(:template => vhost_conf) +end diff --git a/cookbooks/apt/templates/default/Release.erb b/cookbooks/apt/templates/default/Release.erb new file mode 100644 index 0000000..b4c0356 --- /dev/null +++ b/cookbooks/apt/templates/default/Release.erb @@ -0,0 +1,6 @@ +Origin: <%= @repo_name %> +Label: <%= @repo_name %> +Codename: <%= @code_name %> +Architectures: <%= @repo_archs %> +Components: main +Description: <%= @repo_name %> Apt Repo diff --git a/cookbooks/apt/templates/default/distributions.erb b/cookbooks/apt/templates/default/distributions.erb new file mode 100644 index 0000000..1a8bf53 --- /dev/null +++ b/cookbooks/apt/templates/default/distributions.erb @@ -0,0 +1,8 @@ +Origin: <%= @repo_name %> +Label: <%= @repo_name %> +Codename: <%= @code_name %> +Architectures: <%= @repo_archs %> +Components: main +Description: <%= @repo_name %> Apt Repo +DebOverride: override.<%= @code_name %> +DscOverride: override.<%= @code_name %> diff --git a/cookbooks/apt/templates/default/nginx.conf.erb b/cookbooks/apt/templates/default/nginx.conf.erb new file mode 100644 index 0000000..6d15b48 --- /dev/null +++ b/cookbooks/apt/templates/default/nginx.conf.erb @@ -0,0 +1,20 @@ +server { + listen 80; + server_name <%= @server_name %>; + + access_log /var/log/nginx/packages-error.log; + error_log /var/log/nginx/packages-error.log; + + location / { +root /var/packages; +index index.html; + } + + location ~ /(.*)/conf { +deny all; + } + + location ~ /(.*)/db { +deny all; + } +} diff --git a/cookbooks/apt/templates/default/options.erb b/cookbooks/apt/templates/default/options.erb new file mode 100644 index 0000000..aa3e99c --- /dev/null +++ b/cookbooks/apt/templates/default/options.erb @@ -0,0 +1 @@ +basedir . diff --git a/cookbooks/apt/templates/default/server_names_hash_bucket_size.conf.erb b/cookbooks/apt/templates/default/server_names_hash_bucket_size.conf.erb new file mode 100644 index 0000000..9fdc6f1 --- /dev/null +++ b/cookbooks/apt/templates/default/server_names_hash_bucket_size.conf.erb @@ -0,0 +1 @@ +server_names_hash_bucket_size 64; diff --git a/cookbooks/vpc/attributes/apt.rb b/cookbooks/vpc/attributes/apt.rb index 2277f80..0cd8843 100644 --- a/cookbooks/vpc/attributes/apt.rb +++ b/cookbooks/vpc/attributes/apt.rb @@ -1 +1,3 @@ -default[:apt][:distro] = "maverick" +default[:vpc][:apt][:distro] = "maverick" +default[:vpc][:apt][:ppa_url] = "http://ppa.launchpad.net/nova-core/trunk/ubuntu" +default[:vpc][:apt][:local_url] = "http://login.vpc/openstack" diff --git a/cookbooks/vpc/recipes/apt_config.rb b/cookbooks/vpc/recipes/apt_config.rb new file mode 100644 index 0000000..3a3956f --- /dev/null +++ b/cookbooks/vpc/recipes/apt_config.rb @@ -0,0 +1,61 @@ +# +# Cookbook Name:: vpc +# Recipe:: apt_config +# +# Copyright 2011, Rackspace +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe 'apt' + +ruby_block "block until local APT repo is online" do + block do + require 'net/http' + + repo_loaded=false + until repo_loaded == true do + + begin + if Net::HTTP.get_response(URI.parse("#{node[:vpc][:apt][:local_url]}/dists/#{node[:vpc][:apt][:distro]}/Release")).class == Net::HTTPOK + repo_loaded=true + Chef::Log.info("APT repo is online.") + else + Chef::Log.info("Waiting on APT repo to load...") + sleep 5 + end + rescue + Chef::Log.info("Waiting on APT repo to load...") + sleep 5 + end + + end + end + not_if do File.exists?("/etc/apt/sources.list.d/local-source.list") end +end + +apt_repository "local" do + uri node[:vpc][:apt][:local_url] + distribution node[:vpc][:apt][:distro] + components(["main"]) + action :add +end + +apt_repository "ppa" do + key "2A2356C9" + keyserver "keyserver.ubuntu.com" + uri node[:vpc][:apt][:ppa_url] + distribution node[:vpc][:apt][:distro] + components(["main"]) + action :add +end diff --git a/cookbooks/vpc/recipes/default.rb b/cookbooks/vpc/recipes/default.rb index 142e52a..4e13f68 100644 --- a/cookbooks/vpc/recipes/default.rb +++ b/cookbooks/vpc/recipes/default.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: rackspace +# Cookbook Name:: vpc # Recipe:: default # # Copyright 2011, Rackspace diff --git a/cookbooks/vpc/recipes/dev_setup.rb b/cookbooks/vpc/recipes/dev_setup.rb index 87ef2da..b907c83 100644 --- a/cookbooks/vpc/recipes/dev_setup.rb +++ b/cookbooks/vpc/recipes/dev_setup.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: rackspace +# Cookbook Name:: vpc # Recipe:: def_setup # # Copyright 2011, Rackspace diff --git a/cookbooks/vpc/recipes/nova_compute_setup.rb b/cookbooks/vpc/recipes/nova_compute_setup.rb index f17a2a8..539aa46 100644 --- a/cookbooks/vpc/recipes/nova_compute_setup.rb +++ b/cookbooks/vpc/recipes/nova_compute_setup.rb @@ -1,14 +1,6 @@ # This recipe contains setup steps required for Nova Compute to work # correctly on our Stock Ubuntu Cloud Servers images -# NOTE: (dprince) Inside of our VPC environments we already have a virbr0 -# bridge interface so we can use that - -#package "bridge-utils" -#execute "brctl addbr br100" do - #not_if "brctl show | grep br100" -#end - directory "/dev/cgroup" do owner "root" group "root" diff --git a/roles/apt-repo.rb b/roles/apt-repo.rb new file mode 100644 index 0000000..55e16a6 --- /dev/null +++ b/roles/apt-repo.rb @@ -0,0 +1,14 @@ +name "apt-repo" + +run_list( + "recipe[apt::repo]" +) + +default_attributes( + "apt" => { + "repo_name" => "openstack", + "repo_codename" => "maverick", + "repo_archs" => "amd64", + "upload_package_dir" => "/root/openstack-packages" + } +) diff --git a/roles/glance-api.rb b/roles/glance-api.rb index 5846574..adb6ada 100644 --- a/roles/glance-api.rb +++ b/roles/glance-api.rb @@ -1,6 +1,7 @@ name "glance-api" run_list( - "recipe[vpc::apt]", + "recipe[apt::noauth]", + "recipe[vpc::apt_config]", "recipe[glance::api]" ) diff --git a/roles/glance-registry.rb b/roles/glance-registry.rb index a7f2951..6c50a77 100644 --- a/roles/glance-registry.rb +++ b/roles/glance-registry.rb @@ -1,6 +1,7 @@ name "glance-registry" run_list( - "recipe[vpc::apt]", + "recipe[apt::noauth]", + "recipe[vpc::apt_config]", "recipe[glance::registry]" ) diff --git a/roles/nova-base.rb b/roles/nova-base.rb index d0b5a6a..f5ef842 100644 --- a/roles/nova-base.rb +++ b/roles/nova-base.rb @@ -1,7 +1,8 @@ name "nova-base" run_list( - "recipe[vpc::apt]", + "recipe[apt::noauth]", + "recipe[vpc::apt_config]", "recipe[nova::common]" )