Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #292 from 37signals/rvm-deprecation
Browse files Browse the repository at this point in the history
Deprecate automatic RVM support
  • Loading branch information
sstephenson committed Jun 6, 2012
2 parents b7ea07d + e789bcd commit 3e62bab
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cakefile
Expand Up @@ -29,6 +29,7 @@ buildTemplates = (callback) ->
compile("http_server/layout.html")
compile("http_server/proxy_error.html")
compile("http_server/rackup_file_missing.html")
compile("http_server/rvm_deprecation_notice.html")
compile("http_server/welcome.html")
compile("installer/cx.pow.firewall.plist")
compile("installer/cx.pow.powd.plist")
Expand Down
66 changes: 55 additions & 11 deletions MANUAL.md
Expand Up @@ -186,20 +186,64 @@ loaded first.

### Working With Different Versions of Ruby ###

Pow offers full support for running multiple applications under
different versions of Ruby with
[rvm](http://rvm.beginrescueend.com/). Just add a [project
`.rvmrc`](http://rvm.beginrescueend.com/workflow/rvmrc/#project)
file to your application's root directory and you're good to go.
Pow invokes each application's Ruby processes in an isolated
environment. This design makes it possible to use different Ruby
runtimes on a per-application basis.

For example, to instruct Pow to run an application with Ruby 1.9.2,
use this `.rvmrc` file (assuming you've already installed 1.9.2 with
`rvm install 1.9.2`):
There are three ways to specify which version of Ruby to use for a
particular application.

rvm 1.9.2
#### Specifying Ruby Versions with rbenv ####

If an application has an `.rvmrc` file but rvm isn't installed, Pow
will ignore the `.rvmrc` file and fall back to your system Ruby.
You can use [rbenv](https://github.com/sstephenson/rbenv) to specify
per-application Ruby versions for use with Pow.

The `rbenv local` command lets you set a per-project Ruby version by
saving an `.rbenv-version` file in the current directory. For example,
to configure a particular application to run with Ruby 1.9.3-p194,
change to the application's directory and run:

$ rbenv local 1.9.3-p194

Assuming you have set up rbenv in your login environment, there is no
additional configuration necessary to use it with Pow.

For more information, see the [rbenv
documentation](https://github.com/sstephenson/rbenv#readme).

#### Specifying Ruby Versions with RVM ####

[RVM](http://rvm.io/) is another option for specifying per-application
Ruby versions for use with Pow.

You can create a [project `.rvmrc`
file](https://rvm.io/workflow/rvmrc#project) to specify an
application's Ruby version. For example, to configure your application
to run with Ruby 1.8.7, add the following to `.rvmrc` in the
application's root directory:

rvm 1.8.7

Because RVM works by injecting itself into your shell, you must first
load it in your application's `.powrc` or `.powenv` file using the
following code:

[ ! -f "$rvm_path/scripts/rvm" ] || source "$rvm_path/scripts/rvm"
[ ! -f ".rvmrc" ] || source ".rvmrc"

For more information, see the [RVM web site](http://rvm.io/).

#### Specifying Ruby Versions by Setting $PATH ####

You can adjust the `PATH` environment variable in `.powrc` or
`.powenv` to select Ruby versions on a per-application basis. For
example, if you have Ruby installed into `/opt/ruby-1.8.7`, you can
add the following to `.powenv`:

export PATH="/opt/ruby-1.8.7/bin:$PATH"

When Pow loads your application, it will find and use the first `ruby`
binary in your `PATH` — in this case `/opt/ruby-1.8.7/bin/ruby`.

### Serving Static Files ###

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -9,7 +9,7 @@ DIST="$(pwd)/dist"
cake build

mkdir -p "$ROOT/$VERSION/node_modules"
cp -R package.json bin lib "$ROOT/$VERSION"
cp -R package.json bin lib libexec "$ROOT/$VERSION"
cp Cakefile "$ROOT/$VERSION"
cd "$ROOT/$VERSION"
BUNDLE_ONLY=1 npm install --production &>/dev/null
Expand Down
11 changes: 10 additions & 1 deletion lib/configuration.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 36 additions & 2 deletions lib/http_server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions lib/rack_application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -55,7 +55,7 @@ module.exports = function(__obj) {
__out.push(__sanitize(_this.rest.join("\n")));
__out.push('</div>');
}
return __out.push('</pre>\n <p>(If your app uses Bundler, check to make sure you have the <a href="http://gembundler.com/">latest version</a>, then run <code>bundle install</code>. If you&rsquo;re using rvm, make sure you have the <a href="https://rvm.beginrescueend.com/rvm/upgrading/">latest version</a> installed and your app is using the right gemset.)</p>\n </section>\n');
return __out.push('</pre>\n </section>\n');
});
}));

Expand Down
48 changes: 48 additions & 0 deletions lib/templates/http_server/rvm_deprecation_notice.html.js
@@ -0,0 +1,48 @@
module.exports = function(__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {

__out.push('<!doctype html>\n<html>\n <head>\n <title>Pow: Automatic RVM support is deprecated</title>\n <style type="text/css">\n html {\n background: #fff;\n margin: 0;\n padding: 0;\n }\n\n body {\n margin: 30px auto;\n padding: 15px 35px;\n width: 520px;\n font-family: Lucida Grande;\n }\n\n h1 {\n font-family: Helvetica;\n font-size: 24px;\n }\n\n a {\n color: #03f;\n }\n\n p {\n width: 460px;\n font-size: 13px;\n }\n\n .important {\n background: #ff3;\n }\n\n code {\n font-family: Menlo;\n font-size: 12px;\n }\n </style>\n <script type="text/javascript">\n function addToPowrc(link) {\n perform(link, "add_to_powrc",\n "This code has been added to your application&rsquo;s <code>.powrc</code> file."\n )\n }\n\n function disable(link) {\n perform(link, "disable",\n "You will not see this deprecation notice for other applications. " +\n \'<a href="#" onclick="enable(this); return false">Undo</a>\'\n )\n }\n\n function enable(link) {\n perform(link, "enable")\n }\n\n function perform(link, action, successHTML) {\n if (link.className == "busy") return\n link.className = "busy"\n\n xhr = new XMLHttpRequest()\n xhr.open("POST", "/__pow__/rvm_deprecation/" + action, true)\n xhr.onreadystatechange = function() {\n if (xhr.readyState != 4) return\n link.className = ""\n\n if (xhr.status == 200) {\n var p = link.parentNode\n var previousInnerHTML = p.previousInnerHTML\n p.previousInnerHTML = p.innerHTML\n p.innerHTML = successHTML || previousInnerHTML\n }\n }\n\n xhr.send()\n }\n </script>\n </head>\n <body>\n <h1>Automatic RVM support is deprecated</h1>\n\n <p>We&rsquo;re showing you this notice because you just accessed\n an application with a per-project <code>.rvmrc</code> file.</p>\n\n <p><span class="important">Support for automatically loading\n per-project <code>.rvmrc</code> files in Pow is deprecated and\n will be removed in the next major release.</span></p>\n\n <p>Ensure your application continues to work with future releases\n of Pow by adding the following code to the\n application&rsquo;s <code>.powrc</code> file:</p>\n\n <pre><code>[ ! -f "$rvm_path/scripts/rvm" ] || source "$rvm_path/scripts/rvm"\n[ ! -f ".rvmrc" ] || source ".rvmrc"</code></pre>\n\n <p><a href="#" onclick="addToPowrc(this); return false">Add this\n code to <code>.powrc</code> for me</a></p>\n\n <p>We won&rsquo;t notify you again for this project.</p>\n\n <p><a href="#" onclick="disable(this); return false">Don&rsquo;t\n notify me about deprecations for any other applications,\n either</a></p>\n\n <p>Thanks for using Pow.</p>\n </body>\n</html>\n');

}).call(this);

}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
}
24 changes: 24 additions & 0 deletions libexec/pow_rvm_deprecation_notice
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

HOST="$1"
RVMRC_PATH="$PWD/.rvmrc"
SUPPORT_ROOT="$HOME/Library/Application Support/Pow"
DISABLED_FILE="$SUPPORT_ROOT/.disableRvmDeprecationNotices"
NOTIFIED_FILE="$SUPPORT_ROOT/.rvmDeprecationNotices"

if [ -z "$HOST" ] || [ -f "$DISABLED_FILE" ]; then
exit
fi

if [ -f "$NOTIFIED_FILE" ] && grep -xF "$RVMRC_PATH" "$NOTIFIED_FILE"; then
exit
fi

for file in .powrc .powenv; do
if [ -f "$file" ] && egrep 'source.+rvmrc' "$file"; then
exit
fi
done

echo "$RVMRC_PATH" >> "$NOTIFIED_FILE"
open "http://$HOST/__pow__/rvm_deprecation"
18 changes: 15 additions & 3 deletions src/configuration.coffee
Expand Up @@ -108,17 +108,20 @@ module.exports = class Configuration
# Support *.xip.io top-level domains.
@allDomains.push /\d+\.\d+\.\d+\.\d+\.xip\.io$/, /[0-9a-z]{1,7}\.xip\.io$/

# Runtime support files live in `~/Library/Application Support/Pow`.
@supportRoot = libraryPath "Application Support", "Pow"

# `POW_HOST_ROOT`: path to the directory containing symlinks to
# applications that will be served by Pow. Defaults to
# `~/Library/Application Support/Pow/Hosts`.
@hostRoot = env.POW_HOST_ROOT ? libraryPath "Application Support", "Pow", "Hosts"
@hostRoot = env.POW_HOST_ROOT ? path.join @supportRoot, "Hosts"

# `POW_LOG_ROOT`: path to the directory that Pow will use to store
# its log files. Defaults to `~/Library/Logs/Pow`.
@logRoot = env.POW_LOG_ROOT ? libraryPath "Logs", "Pow"

# `POW_RVM_PATH`: path to the rvm initialization script. Defaults
# to `~/.rvm/scripts/rvm`.
# `POW_RVM_PATH` (**deprecated**): path to the rvm initialization
# script. Defaults to `~/.rvm/scripts/rvm`.
@rvmPath = env.POW_RVM_PATH ? path.join process.env.HOME, ".rvm/scripts/rvm"

# ---
Expand All @@ -139,6 +142,15 @@ module.exports = class Configuration
getLogger: (name) ->
@loggers[name] ||= new Logger path.join @logRoot, name + ".log"

# Globally disable or enable RVM deprecation notices by touching or
# removing the `~/Library/Application
# Support/Pow/.disableRvmDeprecationNotices` file.
disableRvmDeprecationNotices: ->
fs.writeFile path.join(@supportRoot, ".disableRvmDeprecationNotices"), ""

enableRvmDeprecationNotices: ->
fs.unlink path.join @supportRoot, ".disableRvmDeprecationNotices"

# Search `hostRoot` for files, symlinks or directories matching the
# domain specified by `host`. If a match is found, the matching domain
# name and its configuration are passed as second and third arguments
Expand Down

0 comments on commit 3e62bab

Please sign in to comment.