Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmanning committed Jun 17, 2012
2 parents d7a1ef2 + 10ff0b0 commit 74bb4d2
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 21 deletions.
55 changes: 55 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,58 @@
## v27 (6/14/2012)

Bugfixes:

* Remove `vendor/bundle` message only appears when dir actually exists

## v26 (6/14/2012)

Features:

* print message when assets:precompile finishes successfully
* Remove `vendor/bundle` if user commits it to their git repo.

## v25 (6/12/2012)

Features:

* support "ruby-xxx-jruby-yyy" for jruby detection packages

## v24 (6/7/2012)

Features:

* removes bundler cache in the slug, to minimize slug size (@stevenh512, #16)
* optimize push time with caching

## v23 (5/8/2012)

Bugfixes:

* fix ruby version bug with "fatal:-Not-a-git-repository"

## v22 (5/7/2012)

Features:

* bundler 1.2.0.pre
* ruby version support for ruby 1.9.2/1.9.3 via bundler's ruby DSL

Deprecation:

* ENV['RUBY_VERSION'] in favor of bundler's ruby DSL

## v21 (3/21/2012)

Features:

* bundler 1.1.2

## v20 (3/12/2012)

Features:

* bundler 1.1.0 \o/

## v19 (1/25/2012)

Bugfixes:
Expand Down
9 changes: 9 additions & 0 deletions LICENSE
@@ -0,0 +1,9 @@
MIT License:

Copyright (C) 2012 Heroku, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 3 additions & 2 deletions Rakefile
Expand Up @@ -12,13 +12,14 @@ def s3_upload(tmpdir, name)
sh("#{s3_tools_dir}/s3 put #{S3_BUCKET_NAME} #{name}.tgz #{tmpdir}/#{name}.tgz")
end

def vendor_plugin(git_url)
def vendor_plugin(git_url, branch = nil)
name = File.basename(git_url, File.extname(git_url))
Dir.mktmpdir("#{name}-") do |tmpdir|
FileUtils.rm_rf("#{tmpdir}/*")

Dir.chdir(tmpdir) do
sh "git clone #{git_url} ."
sh "git checkout origin/#{branch}" if branch
FileUtils.rm_rf("#{name}/.git")
sh("tar czvf #{tmpdir}/#{name}.tgz *")
s3_upload(tmpdir, name)
Expand Down Expand Up @@ -84,7 +85,7 @@ end

desc "update plugins"
task "plugins:update" do
vendor_plugin "http://github.com/ddollar/rails_log_stdout.git"
vendor_plugin "http://github.com/heroku/rails_log_stdout.git", "legacy"
vendor_plugin "http://github.com/pedro/rails3_serve_static_assets.git"
vendor_plugin "http://github.com/hone/rails31_enable_runtime_asset_compilation.git"
end
Expand Down
7 changes: 7 additions & 0 deletions lib/language_pack/base.rb
Expand Up @@ -131,6 +131,13 @@ def run(command)
%x{ #{command} 2>&1 }
end

# run a shell command and pipe stderr to /dev/null
# @param [String] command to be run
# @return [String] output of stdout
def run_stdout(command)
%x{ #{command} 2>/dev/null }
end

# run a shell command and stream the ouput
# @param [String] command to be run
def pipe(command)
Expand Down
6 changes: 3 additions & 3 deletions lib/language_pack/rails3.rb
Expand Up @@ -47,12 +47,12 @@ def run_assets_precompile_rake_task
ENV["RAILS_ENV"] ||= "production"

puts "Running: rake assets:precompile"
rake_output = ""
rake_output << run("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1")
puts rake_output
require 'benchmark'
time = Benchmark.realtime { pipe("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1") }

if $?.success?
log "assets_precompile", :status => "success"
puts "Asset precompilation completed (#{"%.2f" % time}s)"
else
log "assets_precompile", :status => "failure"
puts "Precompiling assets failed, enabling runtime asset compilation"
Expand Down
102 changes: 86 additions & 16 deletions lib/language_pack/ruby.rb
Expand Up @@ -7,7 +7,7 @@
class LanguagePack::Ruby < LanguagePack::Base
LIBYAML_VERSION = "0.1.4"
LIBYAML_PATH = "libyaml-#{LIBYAML_VERSION}"
BUNDLER_VERSION = "1.1.rc.7"
BUNDLER_VERSION = "1.2.0.pre"
BUNDLER_GEM_PATH = "bundler-#{BUNDLER_VERSION}"
NODE_VERSION = "0.4.7"
NODE_JS_BINARY_PATH = "node-#{NODE_VERSION}"
Expand Down Expand Up @@ -45,6 +45,7 @@ def default_process_types

def compile
Dir.chdir(build_path)
remove_vendor_bundle
install_ruby
setup_language_pack_environment
allow_git do
Expand Down Expand Up @@ -83,10 +84,42 @@ def build_ruby_path
"/tmp/#{ruby_version}"
end

# fetch the ruby version from the enviroment
# fetch the ruby version from bundler
# @return [String, nil] returns the ruby version if detected or nil if none is detected
def ruby_version
ENV["RUBY_VERSION"]
return @ruby_version if @ruby_version_run

@ruby_version_run = true

bootstrap_bundler do |bundler_path|
old_system_path = "/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
@ruby_version = run_stdout("env PATH=#{old_system_path}:#{bundler_path}/bin GEM_PATH=#{bundler_path} bundle platform --ruby").chomp
end

if @ruby_version == "No ruby version specified" && ENV['RUBY_VERSION']
# for backwards compatibility.
# this will go away in the future
@ruby_version = ENV['RUBY_VERSION']
@ruby_version_env_var = true
elsif @ruby_version == "No ruby version specified"
@ruby_version = nil
else
@ruby_version = @ruby_version.sub('(', '').sub(')', '').split.join('-')
@ruby_version_env_var = false
end

@ruby_version
end

# bootstraps bundler so we can pull the ruby version
def bootstrap_bundler(&block)
Dir.mktmpdir("bundler-") do |tmpdir|
Dir.chdir(tmpdir) do
run("curl #{VENDOR_URL}/#{BUNDLER_GEM_PATH}.tgz -s -o - | tar xzf -")
end

yield tmpdir
end
end

# determine if we're using rbx
Expand All @@ -98,7 +131,7 @@ def ruby_version_rbx?
# determine if we're using jruby
# @return [Boolean] true if we are and false if we aren't
def ruby_version_jruby?
ruby_version ? ruby_version.match(/^jruby-/) : false
@ruby_version_jruby ||= ruby_version ? ruby_version.match(/jruby-/) : false
end

# default JAVA_OPTS
Expand Down Expand Up @@ -127,11 +160,17 @@ def ruby_versions
def setup_language_pack_environment
setup_ruby_install_env

default_config_vars.each do |key, value|
config_vars = default_config_vars.each do |key, value|
ENV[key] ||= value
end
ENV["GEM_HOME"] = slug_vendor_base
ENV["PATH"] = "#{ruby_install_binstub_path}:#{default_config_vars["PATH"]}"
ENV["PATH"] = "#{ruby_install_binstub_path}:#{config_vars["PATH"]}"
end

# determines if a build ruby is required
# @return [Boolean] true if a build ruby is required
def build_ruby?
@build_ruby ||= !ruby_version_jruby? && ruby_version != "ruby-1.9.3"
end

# install the vendored ruby
Expand All @@ -145,7 +184,7 @@ def install_ruby
Valid versions: #{ruby_versions.join(", ")}
ERROR

if !ruby_version_jruby?
if build_ruby?
FileUtils.mkdir_p(build_ruby_path)
Dir.chdir(build_ruby_path) do
ruby_vm = ruby_version_rbx? ? "rbx" : "ruby"
Expand All @@ -166,19 +205,28 @@ def install_ruby
run("ln -s ../#{bin} #{bin_dir}")
end

topic "Using RUBY_VERSION: #{ruby_version}"
if !@ruby_version_env_var
topic "Using Ruby version: #{ruby_version}"
else
topic "Using RUBY_VERSION: #{ruby_version}"
puts "WARNING: RUBY_VERSION support has been deprecated and will be removed entirely on August 1, 2012."
puts "See https://devcenter.heroku.com/articles/ruby-versions#selecting_a_version_of_ruby for more information."
end

true
end

# find the ruby install path for its binstubs during build
# @return [String] resulting path or empty string if ruby is not vendored
def ruby_install_binstub_path
if ruby_version
"#{build_ruby_path}/bin"
else
""
end
@ruby_install_binstub_path ||=
if build_ruby?
"#{build_ruby_path}/bin"
elsif ruby_version
"#{slug_vendor_ruby}/bin"
else
""
end
end

# setup the environment so we can use the vendored ruby
Expand Down Expand Up @@ -245,6 +293,20 @@ def install_libyaml(dir)
end
end

# remove `vendor/bundle` that comes from the git repo
# in case there are native ext.
# users should be using `bundle pack` instead.
# https://github.com/heroku/heroku-buildpack-ruby/issues/21
def remove_vendor_bundle
if File.exists?("vendor/bundle")
topic "WARNING: Removing `vendor/bundle`."
puts "Checking in `vendor/bundle` is not supported. Please remove this directory"
puts "and add it to your .gitignore. To vendor your gems with Bundler, use"
puts "`bundle pack` instead."
FileUtils.rm_rf("vendor/bundle")
end
end

# runs bundler to install the dependencies
def build_bundler
log("bundle") do
Expand All @@ -264,11 +326,11 @@ def build_bundler
cache_load ".bundle"
end

cache_load "vendor/bundle"

version = run("env RUBYOPT=\"#{syck_hack}\" bundle version").strip
topic("Installing dependencies using #{version}")

cache_load "vendor/bundle"

bundler_output = ""
Dir.mktmpdir("libyaml-") do |tmpdir|
libyaml_dir = "#{tmpdir}/#{LIBYAML_PATH}"
Expand All @@ -292,6 +354,9 @@ def build_bundler
run "bundle clean"
cache_store ".bundle"
cache_store "vendor/bundle"

# Keep gem cache out of the slug
FileUtils.rm_rf("#{slug_vendor_base}/cache")
else
log "bundle", :status => "failure"
error_message = "Failed to install gems via Bundler."
Expand Down Expand Up @@ -449,8 +514,13 @@ def add_node_js_binary

def run_assets_precompile_rake_task
if rake_task_defined?("assets:precompile")
require 'benchmark'

topic "Running: rake assets:precompile"
pipe("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1")
time = Benchmark.realtime { pipe("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1") }
if $?.success?
puts "Asset precompilation completed (#{"%.2f" % time}s)"
end
end
end

Expand Down

0 comments on commit 74bb4d2

Please sign in to comment.