Browse files

Allow non data bag driven configuration. Provide LWRP.

  • Loading branch information...
1 parent 30bc7be commit 6fd1c6bbe55b4ddd3e93b0b7bcf9dad3476b82d3 @chrisroberts chrisroberts committed Dec 19, 2012
Showing with 129 additions and 34 deletions.
  1. +13 −0 attributes/default.rb
  2. +1 −0 metadata.rb
  3. +39 −0 providers/deb.rb
  4. +70 −33 recipes/default.rb
  5. +5 −0 resources/deb.rb
  6. +1 −1 templates/default/apt_repo.conf.erb
View
13 attributes/default.rb
@@ -0,0 +1,13 @@
+default[:reprepro][:fqdn] = fqdn
+default[:reprepro][:listen_port] = 9000
+default[:reprepro][:repo_dir] = "/srv/apt"
+default[:reprepro][:incoming] = "/srv/apt_incoming"
+default[:reprepro][:description] = "APT repository at #{fqdn}"
+default[:reprepro][:codenames] = [node.lsb.codename]
+default[:reprepro][:allow] = []
+default[:reprepro][:pgp][:email] = "apt@#{domain}"
+default[:reprepro][:pulls][:name] = node.lsb.codename
+default[:reprepro][:pulls][:from] = node.lsb.codename
+default[:reprepro][:pulls][:component] = "main"
+default[:reprepro][:architectures] = %w[amd64]
+default[:reprepro][:gnupg_home] = '/root/.gnupg'
View
1 metadata.rb
@@ -8,5 +8,6 @@
depends "build-essential"
depends "apache2"
+recommends "gpg"
recipe "reprepro", "Installs and configures reprepro for an apt repository"
View
39 providers/deb.rb
@@ -0,0 +1,39 @@
+def load_current_resource
+ unless(new_resource.package)
+ new_resource.package new_resource.name
+ end
+ unless(new_resource.distribution)
+ new_resource.distribution node.lsb.codename
+ end
+end
+
+action :add do
+ p_name = %x{dpkg-deb -f #{new_resource.package} package}.strip
+ p_version = %x{dpkg-deb -f #{new_resource.package} version}.strip
+ e = execute "Add deb package (#{::File.basename(new_resource.package)})" do
+ command "reprepro -Vb #{node[:reprepro][:repo_dir]} includedeb #{new_resource.distribution} #{new_resource.package}"
+ cwd ::File.dirname(new_resource.package)
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if do
+ ex = %x{reprepro -b #{node[:reprepro][:repo_dir]} list #{new_resource.distribution} #{p_name}}
+ ex.to_s.strip.split(' ').last == p_version
+ end
+ end
+ new_resource.updated_by_last_action(e.updated_by_last_action?)
+end
+
+action :remove do
+ if(::File.exists?(new_resource.package))
+ p_name = %x{dpkg-deb -f #{new_resource.package} package}.strip
+ else
+ p_name = ::File.basename(new_resource.package.sub('.deb', ''))
+ end
+ e = execute "Remove package (#{::File.basename(new_resource.package)})" do
+ command "reprepro -Vb #{node[:reprepro][:repo_dir]} remove #{new_resource.distribution} #{p_name}"
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if do
+ %x{reprepro -b #{node[:reprepro][:repo_dir]} list #{new_resource.distribution} #{p_name}}.empty?
+ end
+ end
+ new_resource.updated_by_last_action(e.updated_by_last_action?)
+end
View
103 recipes/default.rb
@@ -21,14 +21,17 @@
include_recipe "build-essential"
include_recipe "apache2"
-apt_repo = data_bag_item("reprepro", "main")
-
-node.set_unless.reprepro.fqdn = apt_repo['fqdn']
-node.set_unless.reprepro.description = apt_repo['description']
-node.set_unless.reprepro.pgp_email = apt_repo['pgp']['email']
-node.set_unless.reprepro.pgp_fingerprint = apt_repo['pgp']['fingerprint']
-
-apt_repo_allow = apt_repo["allow"] || []
+begin
+ apt_repo = data_bag_item("reprepro", "main")
+ node[:reprepro].keys.each do |key|
+ next if key.to_sym == :pgp
+ # NOTE: Use #has_key? so data bags can nil out existing values
+ node.default[:reprepro][key] = apt_repo[key] if apt_repo.has_key?(key)
+ end
+rescue Net::HTTPServerException
+ Chef::Log.warn 'Data bag not found. Using default attribute settings!'
+ include_recipe 'gpg'
+end
ruby_block "save node data" do
block do
@@ -41,7 +44,7 @@
package pkg
end
-[ apt_repo["repo_dir"], apt_repo["incoming"] ].each do |dir|
+[ node[:reprepro][:repo_dir], node[:reprepro][:incoming] ].each do |dir|
directory dir do
owner "nobody"
group "nogroup"
@@ -50,53 +53,87 @@
end
%w{ conf db dists pool tarballs }.each do |dir|
- directory "#{apt_repo["repo_dir"]}/#{dir}" do
+ directory "#{node[:reprepro][:repo_dir]}/#{dir}" do
owner "nobody"
group "nogroup"
mode "0755"
end
end
%w{ distributions incoming pulls }.each do |conf|
- template "#{apt_repo["repo_dir"]}/conf/#{conf}" do
+ template "#{node[:reprepro][:repo_dir]}/conf/#{conf}" do
source "#{conf}.erb"
mode "0644"
owner "nobody"
group "nogroup"
variables(
- :allow => apt_repo_allow,
- :codenames => apt_repo["codenames"],
- :architectures => apt_repo["architectures"],
- :incoming => apt_repo["incoming"],
- :pulls => apt_repo["pulls"]
+ :allow => node[:reprepro][:allow],
+ :codenames => node[:reprepro][:codenames],
+ :architectures => node[:reprepro][:architectures],
+ :incoming => node[:reprepro][:incoming],
+ :pulls => node[:reprepro][:pulls]
)
end
end
-execute "import packaging key" do
- command "/bin/echo -e '#{apt_repo["pgp"]["private"]}' | gpg --import -"
- user "root"
- cwd "/root"
- not_if "gpg --list-secret-keys --fingerprint #{node[:reprepro][:pgp_email]} | egrep -qx '.*Key fingerprint = #{node[:reprepro][:pgp_fingerprint]}'"
-end
+if(apt_repo)
+ pgp_key = "#{apt_repo["repo_dir"]}/#{node[:reprepro][:pgp_email]}.gpg.key"
-template "#{apt_repo["repo_dir"]}/#{node[:reprepro][:pgp_email]}.gpg.key" do
- source "pgp_key.erb"
- mode "0644"
- owner "nobody"
- group "nogroup"
- variables(
- :pgp_public => apt_repo["pgp"]["public"]
- )
+ execute "import packaging key" do
+ command "/bin/echo -e '#{apt_repo["pgp"]["private"]}' | gpg --import -"
+ user "root"
+ cwd "/root"
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if "gpg --list-secret-keys --fingerprint #{node[:reprepro][:pgp_email]} | egrep -qx '.*Key fingerprint = #{node[:reprepro][:pgp_fingerprint]}'"
+ end
+
+ template pgp_key do
+ source "pgp_key.erb"
+ mode "0644"
+ owner "nobody"
+ group "nogroup"
+ variables(
+ :pgp_public => apt_repo["pgp"]["public"]
+ )
+ end
+else
+ pgp_key = "#{node[:reprepro][:repo_dir]}/#{node[:gpg][:name][:email]}.gpg.key"
+
+ execute "sudo -u #{node[:gpg][:user]} -i gpg --armor --export #{node[:gpg][:name][:real]} > #{pgp_key}" do
+ creates pgp_key
+ end
+
+ file pgp_key do
+ mode 0644
+ owner "nobody"
+ group "nogroup"
+ end
+
+ execute "reprepro -Vb #{node[:reprepro][:repo_dir]} export" do
+ action :nothing
+ subscribes :run, resources(:file => pgp_key), :immediately
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ end
+
+ if(node[:reprepro][:enable_repository_on_host])
+ execute "apt-key add #{pgp_key}" do
+ action :nothing
+ subscribes :run, resources(:file => pgp_key), :immediately
+ end
+
+ apt_repository "reprepro" do
+ uri "file://#{node[:reprepro][:repo_dir]}"
+ distribution node.lsb.codename
+ components ["main"]
+ end
+ end
end
template "#{node[:apache][:dir]}/sites-available/apt_repo.conf" do
source "apt_repo.conf.erb"
mode 0644
- owner "root"
- group "root"
variables(
- :repo_dir => apt_repo["repo_dir"]
+ :repo_dir => node[:reprepro][:repo_dir]
)
end
View
5 resources/deb.rb
@@ -0,0 +1,5 @@
+actions :add, :remove
+default_action :add
+
+attribute :package, :kind_of => String
+attribute :distribution, :kind_of => [String,Array]
View
2 templates/default/apt_repo.conf.erb
@@ -1,4 +1,4 @@
-<VirtualHost *:80>
+<VirtualHost *:<%= node[:reprepro][:listen_port] %>>
ServerAdmin <%= node[:reprepro][:pgp_email] %>
ServerName <%= node[:reprepro][:fqdn] %>
ServerAlias <%= node[:hostname] %> <%= node[:fqdn] %>

0 comments on commit 6fd1c6b

Please sign in to comment.