From 514b812a74f742753b46d0d0e8c1f0488ea63ff7 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Fri, 25 Oct 2019 09:41:43 -0400 Subject: [PATCH] Update rake building steps for monorepo layout --- .gitignore | 5 ++- Rakefile | 87 +++++++++++++++++++++++++---------------- packaging/ondemand.spec | 9 ++--- tests.sh | 2 +- 4 files changed, 62 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 796b96d1c4..91f6b423e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/build +/apps/*/vendor/bundle +/apps/*/node_modules +/apps/*/.built +/packaging/*.tar.gz diff --git a/Rakefile b/Rakefile index 08e62adf5a..c743780311 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/packaging/ondemand.spec b/packaging/ondemand.spec index f9589233f7..5bb70ab522 100644 --- a/packaging/ondemand.spec +++ b/packaging/ondemand.spec @@ -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 @@ -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 @@ -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 diff --git a/tests.sh b/tests.sh index 54446a8bf1..af45e96a0a 100755 --- a/tests.sh +++ b/tests.sh @@ -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