From 0d88ae0c600b5d4abeec5708cf43b53738817b41 Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Fri, 25 Jul 2014 11:18:51 +0100 Subject: [PATCH] MCOP-245 Add pl:packaging Add the necessary boilerplate to build packages with the current Puppet Labs build infrastructure. Based on the packaging of mcollective-sysctl-data --- .gitignore | 2 + Rakefile | 86 +++++++++++++++++-- ext/build_defaults.yaml | 21 +++++ ext/debian/changelog.erb | 5 ++ ext/debian/compat | 1 + ext/debian/control | 13 +++ ext/debian/copyright | 5 ++ ext/debian/install | 1 + ext/debian/rules | 4 + ext/packaging.rake | 36 ++++++++ ext/project_data.yaml | 14 +++ .../mcollective-actionpolicy-auth.spec.erb | 39 +++++++++ 12 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 ext/build_defaults.yaml create mode 100644 ext/debian/changelog.erb create mode 100644 ext/debian/compat create mode 100644 ext/debian/control create mode 100644 ext/debian/copyright create mode 100644 ext/debian/install create mode 100644 ext/debian/rules create mode 100644 ext/packaging.rake create mode 100644 ext/project_data.yaml create mode 100644 ext/redhat/mcollective-actionpolicy-auth.spec.erb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99a5221 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ext/packaging +/pkg/ diff --git a/Rakefile b/Rakefile index 85ec1b8..ba79dc8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1,92 @@ +RAKE_ROOT = File.expand_path(File.dirname(__FILE__)) specdir = File.join([File.dirname(__FILE__), "spec"]) require 'rake' begin require 'rspec/core/rake_task' + require 'mcollective' rescue LoadError end -if defined?(RSpec::Core::RakeTask) - desc "Run plugin tests" - RSpec::Core::RakeTask.new(:test) do |t| - require "#{specdir}/spec_helper.rb" - t.pattern = 'spec/**/*_spec.rb' +begin + load File.join(RAKE_ROOT, 'ext', 'packaging.rake') +rescue LoadError +end - tmp_load_path = $LOAD_PATH.map { |f| f.shellescape }.join(" -I ") - t.rspec_opts = tmp_load_path + " " + File.read("#{specdir}/spec.opts").chomp +def safe_system *args + raise RuntimeError, "Failed: #{args.join(' ')}" unless system *args +end + +def check_build_env + raise "Not all environment variables have been set. Missing #{{"'DESTDIR'" => ENV["DESTDIR"], "'MCLIBDIR'" => ENV["MCLIBDIR"], "'MCBINDIR'" => ENV["MCBINDIR"], "'TARGETDIR'" => ENV["TARGETDIR"]}.reject{|k,v| v != nil}.keys.join(", ")}" unless ENV["DESTDIR"] && ENV["MCLIBDIR"] && ENV["MCBINDIR"] && ENV["TARGETDIR"] + raise "DESTDIR - '#{ENV["DESTDIR"]}' is not a directory" unless File.directory?(ENV["DESTDIR"]) + raise "MCLIBDIR - '#{ENV["MCLIBDIR"]}' is not a directory" unless File.directory?(ENV["MCLIBDIR"]) + raise "MCBINDIR - '#{ENV["MCBINDIR"]}' is not a directory" unless File.directory?(ENV["MCBINDIR"]) + raise "TARGETDIR - '#{ENV["TARGETDIR"]}' is not a directory" unless File.directory?(ENV["TARGETDIR"]) +end + +def build_package(path) + require 'yaml' + options = [] + + if File.directory?(path) + buildops = File.join(path, "buildops.yaml") + buildops = YAML.load_file(buildops) if File.exists?(buildops) + + return unless buildops["build"] + + libdir = ENV["LIBDIR"] || buildops["mclibdir"] + mcname = ENV["MCNAME"] || buildops["mcname"] + sign = ENV["SIGN"] || buildops["sign"] + + options << "--pluginpath=#{libdir}" if libdir + options << "--mcname=#{mcname}" if mcname + options << "--sign" if sign + + options << "--dependency=\"#{buildops["dependencies"].join(" ")}\"" if buildops["dependencies"] + + safe_system("ruby -I #{File.join(ENV["MCLIBDIR"], "lib").shellescape} #{File.join(ENV["MCBINDIR"], "mco").shellescape} plugin package -v #{path.shellescape} #{options.join(" ")}") + move_artifacts end end +def move_artifacts + rpms = FileList["*.rpm"] + debs = FileList["*.deb","*.orig.tar.gz","*.debian.tar.gz","*.diff.gz","*.dsc","*.changes"] + [debs,rpms].each do |pkgs| + unless pkgs.empty? + safe_system("mv #{pkgs} #{ENV["DESTDIR"]}") unless File.expand_path(ENV["DESTDIR"]) == Dir.pwd + end + end +end + +desc "Build packages for specified plugin in target directory" +task :buildplugin do + check_build_env + build_package(ENV["TARGETDIR"]) +end + +desc "Build packages for all plugins in target directory" +task :build do + check_build_env + packages = Dir.glob(File.join(ENV["TARGETDIR"], "*")) + + packages.each do |package| + if File.directory?(File.expand_path(package)) + build_package(File.expand_path(package)) + end + end +end + +desc "Run agent and application tests" +task :test do + require "#{specdir}/spec_helper.rb" + if ENV["TARGETDIR"] + test_pattern = "#{File.expand_path(ENV["TARGETDIR"])}/spec/**/*_spec.rb" + else + test_pattern = 'spec/**/*_spec.rb' + end + sh "rspec #{Dir.glob(test_pattern).sort.join(' ')}" +end + task :default => :test diff --git a/ext/build_defaults.yaml b/ext/build_defaults.yaml new file mode 100644 index 0000000..9a5776c --- /dev/null +++ b/ext/build_defaults.yaml @@ -0,0 +1,21 @@ +--- +packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master' +packaging_repo: 'packaging' +pbuild_conf: '/etc/pbuilderrc' +default_cow: 'base-squeeze-i386.cow' +cows: 'base-lucid-i386.cow base-precise-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-trusty-i386.cow base-wheezy-i386.cow base-saucy-i386.cow' +packager: 'puppetlabs' +gpg_name: 'info@puppetlabs.com' +gpg_key: '4BD6EC30' +sign_tar: FALSE +# a space separated list of mock configs +final_mocks: 'pl-el-5-i386 pl-el-6-i386 pl-el-7-x86_64 pl-fedora-19-i386 pl-fedora-20-i386' +yum_host: 'yum.puppetlabs.com' +yum_repo_path: '/opt/repository/yum/' +build_gem: FALSE +build_dmg: FALSE +build_doc: FALSE +build_ips: FALSE +apt_host: 'apt.puppetlabs.com' +apt_repo_url: 'http://apt.puppetlabs.com' +apt_repo_path: '/opt/repository/incoming' diff --git a/ext/debian/changelog.erb b/ext/debian/changelog.erb new file mode 100644 index 0000000..adfa676 --- /dev/null +++ b/ext/debian/changelog.erb @@ -0,0 +1,5 @@ +mcollective-actionpolicy-auth (<%= @debversion %>) lucid unstable sid squeeze wheezy precise; urgency=low + + * Update to version <%= @debversion %> + + -- Puppet Labs Release <%= Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")%> diff --git a/ext/debian/compat b/ext/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/ext/debian/compat @@ -0,0 +1 @@ +7 diff --git a/ext/debian/control b/ext/debian/control new file mode 100644 index 0000000..8485a74 --- /dev/null +++ b/ext/debian/control @@ -0,0 +1,13 @@ +Source: mcollective-actionpolicy-auth +Homepage: https://github.com/puppetlabs/mcollective-actionpolicy-auth +Section: utils +Priority: extra +Maintainer: Puppet Labs +Build-Depends: cdbs, debhelper +Standards-Version: 3.8.0 + +Package: mcollective-actionpolicy-auth +Architecture: all +Description: Action Policy simplerpc authorization plugin +Depends: mcollective-common(>= 2.2.1) + diff --git a/ext/debian/copyright b/ext/debian/copyright new file mode 100644 index 0000000..fc245b5 --- /dev/null +++ b/ext/debian/copyright @@ -0,0 +1,5 @@ +Upstream Author: + Puppet Labs https://github.com/puppetlabs/mcollective-actionpolicy-auth + +License: + ASL 2.0 diff --git a/ext/debian/install b/ext/debian/install new file mode 100644 index 0000000..bd1cf6a --- /dev/null +++ b/ext/debian/install @@ -0,0 +1 @@ +util/* usr/share/mcollective/plugins/mcollective/util/ diff --git a/ext/debian/rules b/ext/debian/rules new file mode 100644 index 0000000..2d33f6a --- /dev/null +++ b/ext/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/ext/packaging.rake b/ext/packaging.rake new file mode 100644 index 0000000..3adb340 --- /dev/null +++ b/ext/packaging.rake @@ -0,0 +1,36 @@ +build_defs_file = File.join(RAKE_ROOT, 'ext', 'build_defaults.yaml') +if File.exist?(build_defs_file) + begin + require 'yaml' + @build_defaults ||= YAML.load_file(build_defs_file) + rescue Exception => e + STDERR.puts "Unable to load yaml from #{build_defs_file}:" + raise e + end + @packaging_url = @build_defaults['packaging_url'] + @packaging_repo = @build_defaults['packaging_repo'] + raise "Could not find packaging url in #{build_defs_file}" if @packaging_url.nil? + raise "Could not find packaging repo in #{build_defs_file}" if @packaging_repo.nil? + + namespace :package do + desc "Bootstrap packaging automation, e.g. clone into packaging repo" + task :bootstrap do + if File.exist?(File.join(RAKE_ROOT, "ext", @packaging_repo)) + puts "It looks like you already have ext/#{@packaging_repo}. If you don't like it, blow it away with package:implode." + else + cd File.join(RAKE_ROOT, 'ext') do + %x{git clone #{@packaging_url}} + end + end + end + desc "Remove all cloned packaging automation" + task :implode do + rm_rf File.join(RAKE_ROOT, "ext", @packaging_repo) + end + end +end + +begin + load File.join(RAKE_ROOT, 'ext', 'packaging', 'packaging.rake') +rescue LoadError +end diff --git a/ext/project_data.yaml b/ext/project_data.yaml new file mode 100644 index 0000000..f85bba5 --- /dev/null +++ b/ext/project_data.yaml @@ -0,0 +1,14 @@ +--- +project: 'mcollective-actionpolicy-auth' +author: 'Puppet Labs' +email: 'info@puppetlabs.com' +homepage: 'https://github.com/puppetlabs/mcollective-actionpolicy-auth' +summary: 'Action Policy simplerpc authorization plugin' +description: 'Action Policy simplerpc authorization plugin' +# files and gem_files are space separated lists +files: + - util +# List of packaging related templates to evaluate before the tarball is packed +templates: + - "ext/redhat/mcollective-actionpolicy-auth.spec.erb" + - "ext/debian/changelog.erb" diff --git a/ext/redhat/mcollective-actionpolicy-auth.spec.erb b/ext/redhat/mcollective-actionpolicy-auth.spec.erb new file mode 100644 index 0000000..3651803 --- /dev/null +++ b/ext/redhat/mcollective-actionpolicy-auth.spec.erb @@ -0,0 +1,39 @@ +# VERSION is subbed out during rake srpm process +%global realversion <%= @version %> +%global rpmversion <%= @rpmversion %> + +Summary: Action Policy simplerpc authorization plugin +Name: mcollective-actionpolicy-auth +Version: %{rpmversion} +Release: <%= @rpmrelease -%>%{?dist} +Vendor: %{?_host_vendor} +License: ASL 2.0 +URL: https://github.com/puppetlabs/mcollective-actionpolicy-auth +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildArch: noarch +Group: System Tools +Source0: mcollective-actionpolicy-auth-%{realversion}.tar.gz +Requires: mcollective-common >= 2.2.1 + +%description +Action Policy simplerpc authorization plugin + +%prep +%setup -q -n %{name}-%{realversion} + +%build + +%install +rm -rf %{buildroot} +%{__install} -d -m0755 %{buildroot}%{_libexecdir}/mcollective/mcollective +cp -a util %{buildroot}%{_libexecdir}/mcollective/mcollective + +%clean +rm -rf %{buildroot} + +%files +%{_libexecdir}/mcollective/mcollective/util/* + +%changelog +* <%= Time.now.strftime("%a %b %d %Y") %> Puppet Labs Release - <%= @rpmversion %>-<%= @rpmrelease %> +- Build for <%= @version %>