diff --git a/.env b/.env index 3655e0f9..7431c8c4 100644 --- a/.env +++ b/.env @@ -1,3 +1,2 @@ -#!/bin/bash - -export APP_VERSION=$(git describe --always --tags) +APP_VERSION=$(git describe --always --tags) +OOD_DATAROOT=$PWD/data diff --git a/.env.local.osc b/.env.local.osc new file mode 100644 index 00000000..0bb481fd --- /dev/null +++ b/.env.local.osc @@ -0,0 +1 @@ +OOD_SITE="osc" diff --git a/.env.local.osc.awesim b/.env.local.osc.awesim new file mode 100644 index 00000000..a5dff3aa --- /dev/null +++ b/.env.local.osc.awesim @@ -0,0 +1,2 @@ +OOD_PORTAL="awesim" +OOD_DASHBOARD_TITLE="AweSim Apps" diff --git a/.env.local.osc.awesim.production b/.env.local.osc.awesim.production new file mode 100644 index 00000000..305dc22b --- /dev/null +++ b/.env.local.osc.awesim.production @@ -0,0 +1 @@ +OOD_DATAROOT=$HOME/$OOD_PORTAL/data/sys/systemstatus diff --git a/.env.local.osc.ondemand b/.env.local.osc.ondemand new file mode 100644 index 00000000..b78ed75f --- /dev/null +++ b/.env.local.osc.ondemand @@ -0,0 +1,2 @@ +OOD_PORTAL="ondemand" +OOD_DASHBOARD_TITLE="OSC OnDemand" diff --git a/.env.production.awesim b/.env.production similarity index 60% rename from .env.production.awesim rename to .env.production index 6786c50b..b8c13008 100644 --- a/.env.production.awesim +++ b/.env.production @@ -1,8 +1,5 @@ -OOD_PORTAL="awesim" -OOD_DASHBOARD_TITLE="AweSim Apps" - -APP_TOKEN=sys/systemstatus -OOD_DATAROOT=$HOME/$OOD_PORTAL/data/$APP_TOKEN RAILS_RELATIVE_URL_ROOT=/pun/sys/systemstatus +OOD_DATAROOT=$HOME/ondemand/data/sys/systemstatus + SECRET_KEY_BASE="8bc86ade88fcbf44272f1d20b7bea4f8df1d655129e38ac3d433a22d262f68fb693c20125b7ec14b66dd40fac2325e5ec728003cf76797bcc52d8f6e38c2389b" diff --git a/.env.production.osc b/.env.production.osc deleted file mode 100644 index 9468711d..00000000 --- a/.env.production.osc +++ /dev/null @@ -1,8 +0,0 @@ -OOD_PORTAL="ondemand" -OOD_DASHBOARD_TITLE="OSC OnDemand" - -APP_TOKEN=sys/systemstatus -OOD_DATAROOT=$HOME/$OOD_PORTAL/data/$APP_TOKEN -RAILS_RELATIVE_URL_ROOT=/pun/sys/systemstatus - -SECRET_KEY_BASE="8bc86ade88fcbf44272f1d20b7bea4f8df1d655129e38ac3d433a22d262f68fb693c20125b7ec14b66dd40fac2325e5ec728003cf76797bcc52d8f6e38c2389b" diff --git a/.gitignore b/.gitignore index ddce65ed..36c812c3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,13 +20,7 @@ /data # files used for deployment should not be versioned -/public/assets/ +/public/assets /public/.htaccess -/.env.production /.env.local /vendor/bundle - -RAILS_DATAROOT=$PWD/data -RAILS_DATABASE=db/development.sqlite3 - -/.htaccess diff --git a/README.md b/README.md index 4ea354ca..910a1fd4 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,31 @@ This app displays the current system status of available system clusters. -### Deployment on OOD +### Deployment on OSC 1. Git clone this repository -2. Modify `.env.production` as appropriate, or rename one of the versioned copies -3. Install gems and restart app. - -``` -$ scl enable git19 rh-ruby22 nodejs010 -- bin/bundle install --path=vendor/bundle -$ scl enable git19 rh-ruby22 nodejs010 -- bin/rake assets:clobber RAILS_ENV=production -$ scl enable git19 rh-ruby22 nodejs010 -- bin/rake assets:precompile RAILS_ENV=production -$ scl enable git19 rh-ruby22 nodejs010 -- bin/rake ood_appkit:restart -``` +2. Install the app for a production environment. + + **For OSC OnDemand:** + + ```sh + OOD_SITE=osc OOD_PORTAL=ondemand RAILS_ENV=production scl enable git19 rh-ruby22 nodejs010 -- bin/setup + ``` + + **For AweSim:** + + ```sh + OOD_SITE=osc OOD_PORTAL=awesim RAILS_ENV=production scl enable git19 rh-ruby22 nodejs010 -- bin/setup + ``` + + **Updating:** + + For updating you do not need to specify `OOD_SITE` or `OOD_PORTAL` if they + are defined in `.env.local` + + ```sh + RAILS_ENV=production scl enable git19 rh-ruby22 nodejs010 -- bin/setup + ``` ### Options diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..59dcf2a4 --- /dev/null +++ b/bin/setup @@ -0,0 +1,122 @@ +#!/usr/bin/env ruby +require "pathname" +require "rake" + +include FileUtils + +ENV["RAILS_ENV"] ||= ENV["PASSENGER_APP_ENV"] || "development" +ENV["RAILS_RELATIVE_URL_ROOT"] ||= ENV["PASSENGER_BASE_URI"] + +def cat(source, target) + source = Array(source).select {|f| File.file?(f)} + if source.empty? + puts "No site/portal specific files found for #{target}" + else + source_files = source.join(" ") + unless system("cat #{source_files} | cmp -s - #{target}") + sh "cat #{source_files} > #{target}" + else + puts "No changes detected for #{source.join(", ")} => #{target}" + end + end +end + +# define application object +class App + attr_accessor :env, :url, :site, :portal + + def initialize(env:, url:, site:, portal:) + @env = env + @url = url + @site = site + @portal = portal + end + + def production? + env == "production" + end +end + +# set application settings +APP = App.new( + env: ENV["RAILS_ENV"], + url: ENV["RAILS_RELATIVE_URL_ROOT"], + site: ENV["OOD_SITE"], + portal: ENV["OOD_PORTAL"] +) + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + # Read in OOD_SITE and OOD_PORTAL if defined in .env.local + if File.exist?(".env.local") + unless APP.site + tmp = `bash -c 'source .env.local && echo $OOD_SITE'`.strip + APP.site = tmp unless tmp.empty? + end + + unless APP.portal + tmp = `bash -c 'source .env.local && echo $OOD_PORTAL'`.strip + APP.portal = tmp unless tmp.empty? + end + end + + # Read in RAILS_RELATIVE_URL_ROOT if defined in .env.production + if APP.production? && File.exist?(".env.production") + unless APP.url + tmp = `bash -c 'source .env.production && echo $RAILS_RELATIVE_URL_ROOT'`.strip + APP.url = tmp unless tmp.empty? + end + end + + puts "\n== Building System Status App ==" + puts "RAILS_ENV = #{APP.env}" + puts "RAILS_RELATIVE_URL_ROOT = #{APP.url || "not set"}" + puts "OOD_SITE = #{APP.site || "not set (default: none)"}" + puts "OOD_PORTAL = #{APP.portal || "not set (default: none)"}" + + unless system("bin/bundle check &> /dev/null") + puts "\n== Installing dependencies ==" + sh "bin/bundle install --path=vendor/bundle" + sh "bin/bundle clean" + end + + if APP.site + puts "\n== Enabling site and portal specific settings ==" + + # .env.local + target_file = ".env.local" + if APP.site == "" # user wants to unset site settings + rm_f target_file + elsif APP.portal == "" # user wants to unset portal settings + source_file = ".env.local.#{APP.site}" + cat source_file, target_file + else + source_files = [ + ".env.local.#{APP.site}", + ".env.local.#{APP.site}.#{APP.portal}", + ".env.local.#{APP.site}.#{APP.portal}.#{APP.env}" + ] + cat source_files, target_file + end + elsif APP.portal + abort "ERROR: You have a portal specified with no site specified" + end + + if APP.production? + puts "\n== Compiling assets ==" + sh "bin/rake assets:clobber" + sh "bin/rake assets:precompile" + end + + puts "\n== Removing old logs and tempfiles ==" + sh "bin/rake log:clear tmp:clear" + + puts "\n== Restarting application server ==" + touch "tmp/restart.txt" + puts "" +end