Browse Source

Update RVM installation, fix rails

Hamilton Turner 11 years ago
parent
commit
87f2e6d999

+ 24 - 0
frameworks/Ruby/README.md

@@ -0,0 +1,24 @@
+# Using RVM to setup your environment
+
+TFB uses rvm wherever possible to help ruby-based or
+jruby-based frameworks setup their environment. 
+In your framework's `bash_profile.sh`, put this: 
+
+    #!/bin/bash
+    
+    # Assume single-user installation
+    source $HOME/.rvm/scripts/rvm
+
+Because TFB uses Python's `subprocess` module, which runs 
+all shell processes in a non-login mode, you must source the 
+`rvm` script before using `rvm` anywhere. Placing the `source`
+call in your `bash_profile.sh` ensures that it will be called 
+before running `install.sh` and before running `setup.py`
+
+For compatibility with how the framework rounds are executed, 
+you must use a single-user installation if you wish to run 
+ruby-based TFB tests.
+
+
+
+

+ 7 - 0
frameworks/Ruby/rails/bash_profile.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# We assume single-user installation as 
+# done in our rvm.sh script and 
+# in Travis-CI
+source $HOME/.rvm/scripts/rvm
+

+ 1 - 1
frameworks/Ruby/rails/config/nginx.conf

@@ -24,7 +24,7 @@ worker_processes 8;
 #user nobody nobody; # for systems with "nobody" as a group instead
 #user nobody nobody; # for systems with "nobody" as a group instead
 
 
 # Feel free to change all paths to suite your needs here, of course
 # Feel free to change all paths to suite your needs here, of course
-# pid /tmp/nginx.pid;
+pid /tmp/nginx.pid;
 #error_log /tmp/nginx.error.log;
 #error_log /tmp/nginx.error.log;
 error_log stderr error;
 error_log stderr error;
 
 

+ 7 - 1
frameworks/Ruby/rails/install.sh

@@ -1,3 +1,9 @@
 #!/bin/bash
 #!/bin/bash
 
 
-fw_depends rails ruby
+fw_depends rvm nginx java
+
+rvm install ruby-2.0.0-p0
+rvm ruby-2.0.0-p0 do bundle install --gemfile=$TROOT/Gemfile-ruby
+
+rvm install jruby-1.7.8
+rvm jruby-1.7.8 do bundle install --gemfile=$TROOT/Gemfile-jruby

+ 2 - 3
frameworks/Ruby/rails/setup_jruby.py

@@ -8,7 +8,6 @@ def start(args, logfile, errfile):
   setup_util.replace_text("rails/config/database.yml", "host: .*", "host: " + args.database_host)
   setup_util.replace_text("rails/config/database.yml", "host: .*", "host: " + args.database_host)
 
 
   try:
   try:
-    subprocess.check_call("rvm jruby-1.7.8 do bundle install --gemfile=Gemfile-jruby", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-jruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-jruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-jruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-jruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.Popen("rvm jruby-1.7.8 do bundle exec torqbox -b 0.0.0.0 -E production", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.Popen("rvm jruby-1.7.8 do bundle exec torqbox -b 0.0.0.0 -E production", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
@@ -23,8 +22,8 @@ def stop(logfile, errfile):
       if 'torqbox' in line:
       if 'torqbox' in line:
         pid = int(line.split(None, 2)[1])
         pid = int(line.split(None, 2)[1])
         os.kill(pid, 15)
         os.kill(pid, 15)
-    subprocess.check_call("rm Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
-    subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
+    subprocess.check_call("rm -f Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
+    subprocess.check_call("rm -f Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     return 0
     return 0
   except subprocess.CalledProcessError:
   except subprocess.CalledProcessError:
     return 1
     return 1

+ 9 - 10
frameworks/Ruby/rails/setup_ruby.py

@@ -4,23 +4,22 @@ import sys
 import re
 import re
 import os
 import os
 import setup_util
 import setup_util
-from os.path import expanduser
-
-home = expanduser("~")
+import time
 
 
 def start(args, logfile, errfile):
 def start(args, logfile, errfile):
+  
   setup_util.replace_text("rails/config/database.yml", "host: .*", "host: " + args.database_host)
   setup_util.replace_text("rails/config/database.yml", "host: .*", "host: " + args.database_host)
+
   try:
   try:
-    subprocess.check_call("rvm ruby-2.0.0-p0 do bundle install --gemfile=Gemfile-ruby", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
-    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/rails/config/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
-    subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn_rails -E production -c config/unicorn.rb", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/config/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn_rails -E production -c $TROOT/config/unicorn.rb", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
     return 0
     return 0
   except subprocess.CalledProcessError:
   except subprocess.CalledProcessError:
     return 1
     return 1
 def stop(logfile, errfile):
 def stop(logfile, errfile):
-  subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
+  subprocess.call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/config/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
   try:
   try:
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     out, err = p.communicate()
     out, err = p.communicate()
@@ -28,9 +27,9 @@ def stop(logfile, errfile):
       if 'unicorn' in line and 'master' in line:
       if 'unicorn' in line and 'master' in line:
         pid = int(line.split(None, 2)[1])
         pid = int(line.split(None, 2)[1])
         os.kill(pid, 15)
         os.kill(pid, 15)
-    # subprocess.check_call("rvm ruby-2.0.0-p0 do bundle exec passenger stop --pid-file=$HOME/FrameworkBenchmarks/rack/rack.pid", shell=True, cwd='rack')
-    subprocess.check_call("rm Gemfile", shell=True, cwd="rails")
-    subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rails")
+    subprocess.check_call("rm -f Gemfile", shell=True, cwd="rails")
+    subprocess.check_call("rm -f Gemfile.lock", shell=True, cwd="rails")
+
     return 0
     return 0
   except subprocess.CalledProcessError:
   except subprocess.CalledProcessError:
     return 1
     return 1

+ 22 - 0
toolset/setup/linux/languages/rvm.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+
+RETCODE=$(fw_exists rvm.installed)
+[ ! "$RETCODE" == 0 ] || { \
+  # Assume single-user installation
+  source $HOME/.rvm/scripts/rvm
+  return 0;
+}
+
+# Never run installation inside of TRAVIS, 
+# just rely on their default RVM installaton
+if [ "$TRAVIS" = "true" ] || { \
+  source $HOME/.rvm/scripts/rvm
+  touch rvm.installed
+  return 0;
+}
+
+# Run single-user installation and source rvm
+\curl -sSL https://get.rvm.io | bash -s stable
+source $HOME/.rvm/scripts/rvm
+
+touch rvm.installed