Skip to content

Instantly share code, notes, and snippets.

@markllama
Last active December 15, 2015 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markllama/5339961 to your computer and use it in GitHub Desktop.
Save markllama/5339961 to your computer and use it in GitHub Desktop.
A Thor script to assist in building OpenShift Origin (and other) packages.
#!/usr/bin/env ruby
#
# A set of tasks to prepare and build the OpenShift Origin source tree
# into packages
#
require 'rubygems'
require 'thor'
# Used to search for spec files and other marker files within the source tree
require 'find'
SOURCE_ROOT = ENV["OPENSHIFT_SOURCE_ROOT"] || "."
REPO_ROOT = ENV["OPENSHIFT_REPO_ROOT"] || "/tmp/tito"
YARDOC_ROOT = ENV["OPENSHIFT_YARDOC_ROOT"] || "./doc"
PREREQUISITES = ['git', 'tito', 'rpm-build', 'rubygem-redcarpet']
class Build < Thor
desc "prepare", "prepare the build environment"
def prepare
cmd = "yum install #{PREREQUISITES.join(' ')}"
cmd = "sudo " + cmd if not Process.uid == 0
system cmd
end
desc "requirements", "install packages required to build software"
method_option(:source, :aliases => "-s",
:type => :string, :default => '.',
:desc => "location of the source tree"
)
method_option(:assumeyes, :aliases => "-y",
:type => :boolean, :default => false,
:desc => "say 'yes' when prompted."
)
def requirements
cmd = "yum-builddep " + ((" --assumeyes " if options[:assumeyes]) || "")
specfiles = spec_file_list(options[:source]).join(' ')
cmd += specfiles
cmd = "sudo " + cmd if not Process.uid == 0
system cmd
end
desc "rpm", "build RPM packages from source code"
method_option(:source, :aliases => "-s",
:type => :string, :default => '.',
:desc => "location of the source tree"
)
method_option :repodir, :aliases => "-r", :default => REPO_ROOT,
:desc => "location for the YUM repo"
method_option :test, :aliases => "-t",:type => :boolean, :default => false,
:desc => "build test packages instead of release packages"
def rpm
pkg_root_list(options[:source]).each {|pkgdir|
cmd = "tito build --rpm --output #{options[:repodir]}"
cmd << " --test" if options[:test]
system "cd #{pkgdir} ; #{cmd}"
}
end
desc "repo", "generate YUM repository metadata"
method_option :repodir, :aliases => "-r", :default => REPO_ROOT,
:desc => "location for the YUM repo"
def repo
repodir = options[:repodir]
raise ArgumentError.new "directory #{repodir} does not exist" if not Dir.exists? repodir
system "createrepo #{repodir}"
puts "generating repo in #{repodir}"
end
begin
require 'yard'
desc "yardoc", "build comprehensive yard documentation"
method_option(:source, :aliases => "-s",
:type => :string, :default => '.',
:desc => "location of the source tree"
)
method_option :output, :aliases => "-o", :default => YARDOC_ROOT,
:desc => "location for yardoc output"
def yardoc
system "cd #{options[:source]} ; yardoc #{pkg_root_list.join(' ')} --output-dir #{options[:output]}"
end
rescue LoadError => e
end
private
# Find the RPM spec files beneath a directory tree
# @param rootdir [String] The root of the search
def spec_file_list(rootdir=SOURCE_ROOT)
Find.find(rootdir).select { | filename | filename.end_with? ".spec" }
end
# Find the list of package directories from the location of spec files
def pkg_root_list(rootdir=SOURCE_ROOT)
spec_file_list(rootdir).map {|specfile| File.dirname specfile }
end
end
#
Build.start
@markllama
Copy link
Author

To run this initially you need:

  • Fedora 18+
  • rubygem-thor

It's also helpful to enable sudo NOPASSWD for the build user at least for the yum install and yum-builddep commands.

To run this command:

  1. create a minimal Fedora 18 host
  2. install rubygem-thor
  3. download this script
  4. make it executable and put it in your path

At this point you can use the script to get help:

oo-build help
Tasks:
   oo-build help [TASK]   # Describe available tasks or one specific task
   oo-build prepare       # prepare the build environment
   oo-build repo          # generate YUM repository metadata
   oo-build requirements  # install packages required to build software
   oo-build rpm           # build RPM packages from source code
   oo-build yardoc        # build comprehensive yard documentation

To install the build tools:

  1. oo-build prepare

To build the software and create a YUM repository:

  1. clone the origin-server repository or fork of your choice
  2. oo-build requirements -s origin-server
  3. oo-build rpm -s origin-server [-r repository location] - defaults to /tmp/tito
  4. oo-build repo [-r repository location] - defaults to /tmp/tito

To build the Yard markdown documentation:

  1. oo-build yardoc -s origin-server [-o document location] - defaults to current working directory

You're responsible for installing and configuring a web server to make the resulting repository available on a network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment