Skip to content

Commit

Permalink
Update rake building steps for monorepo layout
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Oct 25, 2019
1 parent a16f288 commit 514b812
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 41 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/build
/apps/*/vendor/bundle
/apps/*/node_modules
/apps/*/.built
/packaging/*.tar.gz
87 changes: 54 additions & 33 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,87 @@
require "json"
require "pathname"
require "time"

PROJ_DIR = Pathname.new(__dir__)
CONFIG_FILE = PROJ_DIR.join(ENV["CNFFILE"] || "config.json")
BUILD_ROOT = Pathname.new(ENV["OBJDIR"] || "build")
APPS_DIR = PROJ_DIR.join('apps')
INSTALL_ROOT = Pathname.new(ENV["PREFIX"] || "/opt/ood")

def all_components
JSON.parse(CONFIG_FILE.read).map { |c| Component.new(c) }
def apps
Dir["#{APPS_DIR}/*"].map { |d| Component.new(d) }
end

class Component
attr_reader :name
attr_reader :url
attr_reader :tag
attr_reader :path
#attr_reader :built

def initialize(opts = {})
@name = opts.fetch("name") { raise ArgumentError, "No name specified. Missing argument: name" }.to_s
@url = opts.fetch("url") { raise ArgumentError, "No url specified. Missing argument: url" }.to_s
@tag = opts.fetch("tag") { raise ArgumentError, "No tag specified. Missing argument: tag" }.to_s
@app = opts.fetch("app", nil)
def initialize(app)
@name = File.basename(app)
@path = Pathname.new(app)
#@built = @path.join('.built')
end
end

def app?
!!@app
desc "Package OnDemand"
task :package do
`which gtar 1>/dev/null 2>&1`
if $?.success?
tar = 'gtar'
else
tar = 'tar'
end

def build_root
app? ? BUILD_ROOT.join("apps", name) : BUILD_ROOT.join(name)
version = ENV['VERSION']
if ! version
latest_commit = `git rev-list --tags --max-count=1`.strip[0..6]
latest_tag = `git describe --tags #{latest_commit}`.strip[1..-1]
datetime = Time.now.strftime("%Y%m%d-%H%M")
version = "#{latest_tag}-#{datetime}-#{latest_commit}"
end
sh "git ls-files | #{tar} -c --transform 's,^,ondemand-#{version}/,' -T - | gzip > packaging/v#{version}.tar.gz"
end

def download_url
"#{url}/archive/#{tag}.tar.gz"
namespace :build do
apps.each do |a|
desc "Build #{a.name} app"
task a.name.to_sym do
setup_path = a.path.join("bin", "setup")
if setup_path.exist? && setup_path.executable?
sh "PASSENGER_APP_ENV=production PASSENGER_BASE_URI=/pun/sys/#{a.name} #{setup_path}"
end
end
end
end

task :default => :build
desc "Build all apps"
task :all => apps.map { |a| a.name }
end

all_components.each do |c|
file c.build_root => CONFIG_FILE do
rm_rf c.build_root if c.build_root.directory?
mkdir_p c.build_root unless c.build_root.directory?
sh "curl -skL #{c.download_url} | tar xzf - -C #{c.build_root} --strip-components=1"
setup_path = c.build_root.join("bin", "setup")
=begin
apps.each do |a|
file a.built do
setup_path = a.path.join("bin", "setup")
if setup_path.exist? && setup_path.executable?
sh "PASSENGER_APP_ENV=production PASSENGER_BASE_URI=/pun/sys/#{c.name} #{setup_path}"
sh "PASSENGER_APP_ENV=production PASSENGER_BASE_URI=/pun/sys/#{a.name} #{setup_path}"
sh "touch #{a.built}"
end
c.build_root.join("VERSION").write(c.tag) if c.app?
end
end
=end

desc "Build OnDemand"
task :build => all_components.map(&:build_root)
task :build => 'build:all'
#task :build => all_apps.map(&:built)

directory INSTALL_ROOT.to_s

desc "Install OnDemand"
task :install => [:build, INSTALL_ROOT] do
sh "rsync -rptl --delete --copy-unsafe-links #{BUILD_ROOT}/ #{INSTALL_ROOT}"
task :install => [INSTALL_ROOT] do
sh "cp -r mod_ood_proxy #{INSTALL_ROOT}/"
sh "cp -r nginx_stage #{INSTALL_ROOT}/"
sh "cp -r ood_auth_map #{INSTALL_ROOT}/"
sh "cp -r ood-portal-generator #{INSTALL_ROOT}/"
sh "cp -r #{APPS_DIR} #{INSTALL_ROOT}/"
end

desc "Clean up build"
task :clean do
rm_rf BUILD_ROOT
sh "git clean -Xdf"
end
9 changes: 3 additions & 6 deletions packaging/ondemand.spec
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ popd
scl enable ondemand - << \EOS
set -x
set -e
rake --trace -mj%{ncpus} OBJDIR=$(pwd)/build
rake --trace -mj%{ncpus} build
EOS


Expand All @@ -113,11 +113,7 @@ EOS
scl enable ondemand - << \EOS
set -x
set -e
rake --trace install PREFIX=%{buildroot}/opt/ood OBJDIR=$(pwd)/build
%__cp -r mod_ood_proxy %{buildroot}/opt/ood/mod_ood_proxy
%__cp -r nginx_stage %{buildroot}/opt/ood/nginx_stage
%__cp -r ood-portal-generator %{buildroot}/opt/ood/ood-portal-generator
%__cp -r ood_auth_map %{buildroot}/opt/ood/ood_auth_map
rake --trace install PREFIX=%{buildroot}/opt/ood

%__rm %{buildroot}/opt/ood/apps/*/log/production.log
echo "%{git_tag}" > %{buildroot}/opt/ood/VERSION
Expand All @@ -141,6 +137,7 @@ fi
%__mv %{buildroot}/opt/ood/apps/activejobs %{buildroot}%{_localstatedir}/www/ood/apps/sys/activejobs
%__mv %{buildroot}/opt/ood/apps/myjobs %{buildroot}%{_localstatedir}/www/ood/apps/sys/myjobs
%__mv %{buildroot}/opt/ood/apps/bc_desktop %{buildroot}%{_localstatedir}/www/ood/apps/sys/bc_desktop
%__rm -rf %{buildroot}/opt/ood/apps
%__mkdir_p %{buildroot}%{_sharedstatedir}/ondemand-nginx/config/puns
%__mkdir_p %{buildroot}%{_sharedstatedir}/ondemand-nginx/config/apps/sys
%__mkdir_p %{buildroot}%{_sharedstatedir}/ondemand-nginx/config/apps/usr
Expand Down
2 changes: 1 addition & 1 deletion tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ yum install -y \
source scl_source enable ondemand || :

# Build and install
rake -mj ${NUM_TASKS:-$(nproc)} && rake install
rake -mj ${NUM_TASKS:-$(nproc)} build && rake install

0 comments on commit 514b812

Please sign in to comment.