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.
This commit is contained in:
Dan Prince 2011-05-05 15:36:08 -04:00
parent 7d18856a45
commit 0a0aa44065
19 changed files with 266 additions and 27 deletions

View File

@ -0,0 +1,3 @@
default[:apt][:repo_codename] = "maverick"
default[:apt][:repo_name] = "ubuntu"
default[:apt][:repo_archs] = "amd64"

View File

@ -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

View File

@ -0,0 +1 @@
APT::Get::AllowUnauthenticated 1;

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,6 @@
Origin: <%= @repo_name %>
Label: <%= @repo_name %>
Codename: <%= @code_name %>
Architectures: <%= @repo_archs %>
Components: main
Description: <%= @repo_name %> Apt Repo

View File

@ -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 %>

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
basedir .

View File

@ -0,0 +1 @@
server_names_hash_bucket_size 64;

View File

@ -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"

View File

@ -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

View File

@ -1,5 +1,5 @@
#
# Cookbook Name:: rackspace
# Cookbook Name:: vpc
# Recipe:: default
#
# Copyright 2011, Rackspace

View File

@ -1,5 +1,5 @@
#
# Cookbook Name:: rackspace
# Cookbook Name:: vpc
# Recipe:: def_setup
#
# Copyright 2011, Rackspace

View File

@ -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"

14
roles/apt-repo.rb Normal file
View File

@ -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"
}
)

View File

@ -1,6 +1,7 @@
name "glance-api"
run_list(
"recipe[vpc::apt]",
"recipe[apt::noauth]",
"recipe[vpc::apt_config]",
"recipe[glance::api]"
)

View File

@ -1,6 +1,7 @@
name "glance-registry"
run_list(
"recipe[vpc::apt]",
"recipe[apt::noauth]",
"recipe[vpc::apt_config]",
"recipe[glance::registry]"
)

View File

@ -1,7 +1,8 @@
name "nova-base"
run_list(
"recipe[vpc::apt]",
"recipe[apt::noauth]",
"recipe[vpc::apt_config]",
"recipe[nova::common]"
)