Skip to content

Commit

Permalink
Merge pull request #39 from AweSim-OSC/add-setup-script
Browse files Browse the repository at this point in the history
Added setup script
  • Loading branch information
nickjer authored Apr 21, 2017
2 parents e483be4 + ae9af9d commit 739bd48
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 33 deletions.
5 changes: 2 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash

export APP_VERSION=$(git describe --always --tags)
APP_VERSION=$(git describe --always --tags)
OOD_DATAROOT=$PWD/data
1 change: 1 addition & 0 deletions .env.local.osc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OOD_SITE="osc"
2 changes: 2 additions & 0 deletions .env.local.osc.awesim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OOD_PORTAL="awesim"
OOD_DASHBOARD_TITLE="AweSim Apps"
1 change: 1 addition & 0 deletions .env.local.osc.awesim.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OOD_DATAROOT=$HOME/$OOD_PORTAL/data/sys/systemstatus
2 changes: 2 additions & 0 deletions .env.local.osc.ondemand
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OOD_PORTAL="ondemand"
OOD_DASHBOARD_TITLE="OSC OnDemand"
7 changes: 2 additions & 5 deletions .env.production.awesim → .env.production
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 0 additions & 8 deletions .env.production.osc

This file was deleted.

8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
122 changes: 122 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 739bd48

Please sign in to comment.