From bfc6484d93ad0574a443192709695f9658f73e0a Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Thu, 20 Apr 2017 16:35:42 -0400 Subject: [PATCH 1/3] added setup script --- .env | 5 +- .env.local.osc | 1 + .env.local.osc.awesim | 2 + .env.local.osc.awesim.production | 1 + .env.local.osc.ondemand | 2 + .env.production.awesim | 8 -- .env.production.osc | 8 -- README.md | 33 ++++++--- bin/setup | 122 +++++++++++++++++++++++++++++++ 9 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 .env.local.osc create mode 100644 .env.local.osc.awesim create mode 100644 .env.local.osc.awesim.production create mode 100644 .env.local.osc.ondemand delete mode 100644 .env.production.awesim delete mode 100644 .env.production.osc create mode 100755 bin/setup 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.awesim deleted file mode 100644 index 6786c50b..00000000 --- a/.env.production.awesim +++ /dev/null @@ -1,8 +0,0 @@ -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 - -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/README.md b/README.md index 4ea354ca..b713fe98 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=ondemand 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 From 895062be251f6dc2e53f62a8dbc6d02c95bc5576 Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Fri, 21 Apr 2017 09:31:09 -0400 Subject: [PATCH 2/3] don't ignore .env.production --- .env.production | 5 +++++ .gitignore | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 .env.production diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..b8c13008 --- /dev/null +++ b/.env.production @@ -0,0 +1,5 @@ +RAILS_RELATIVE_URL_ROOT=/pun/sys/systemstatus + +OOD_DATAROOT=$HOME/ondemand/data/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 From ae9af9d45e5a4ea22544af5a6e937350d50c7eae Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Fri, 21 Apr 2017 13:26:22 -0400 Subject: [PATCH 3/3] fix typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b713fe98..910a1fd4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This app displays the current system status of available system clusters. **For AweSim:** ```sh - OOD_SITE=osc OOD_PORTAL=ondemand RAILS_ENV=production scl enable git19 rh-ruby22 nodejs010 -- bin/setup + OOD_SITE=osc OOD_PORTAL=awesim RAILS_ENV=production scl enable git19 rh-ruby22 nodejs010 -- bin/setup ``` **Updating:**