<NME> s3-put
<BEF> ADDFILE
<MSG> Merge pull request #3907 from rjackson/use_cache

[BUGFIX beta] Use a bundler cache to speed builds.
<DFF> @@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
+#
+# Uploads a file to the Amazon S3 service.
+# Outputs the URL for the newly uploaded file.
+#
+# Requirements:
+# - S3_ACCESS_KEY_ID
+# - S3_SECRET_ACCESS_KEY
+# - openssl
+# - curl
+#
+# Author: Mislav Marohnić
+# Source: https://github.com/github/hub/blob/aadc8418d9e5dd27172d5d67c3da0bd2fdcf759a/script/s3-put
+
+set -e
+
+authorization() {
+  local signature="$(string_to_sign | hmac_sha1 | base64)"
+  echo "AWS ${S3_ACCESS_KEY_ID?}:${signature}"
+}
+
+hmac_sha1() {
+  openssl dgst -binary -sha1 -hmac "${S3_SECRET_ACCESS_KEY?}"
+}
+
+base64() {
+  openssl enc -base64
+}
+
+bin_md5() {
+  openssl dgst -binary -md5
+}
+
+string_to_sign() {
+  echo "$http_method"
+  echo "$content_md5"
+  echo "$content_type"
+  echo "$date"
+  echo "x-amz-acl:$acl"
+  printf "/$bucket/$remote_path"
+}
+
+date_string() {
+  LC_TIME=C date "+%a, %d %h %Y %T %z"
+}
+
+file="$1"
+bucket="${2%%:*}"
+remote_path="${2#*:}"
+content_type="$3"
+
+if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then
+  remote_path="${file##*/}"
+fi
+
+http_method=PUT
+acl="public-read"
+content_md5="$(bin_md5 < "$file" | base64)"
+date="$(date_string)"
+
+url="https://$bucket.s3.amazonaws.com/$remote_path"
+
+curl -qsSf -T "$file" \
+  -H "Authorization: $(authorization)" \
+  -H "x-amz-acl: $acl" \
+  -H "Date: $date" \
+  -H "Content-MD5: $content_md5" \
+  -H "Content-Type: $content_type" \
+  "$url"
+
+echo "$url"
+
+# vim: filetype=sh

{'commit': 'diff --git a/.gitignore b/.gitignore\nindex 52570c2fb..52800149c 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -13,7 +13,6 @@ _yardoc\n assets\n assets/bpm_libs.js\n assets/bpm_styles.css\n-bin/\n coverage\n dist\n docs/build\ndiff --git a/.travis.yml b/.travis.yml\nindex bbe2e2c23..eb9e10eb4 100644\n--- a/.travis.yml\n+++ b/.travis.yml\n@@ -6,7 +6,7 @@ node_js:\n install:\n - "npm install"\n - "gem install bundler --pre"\n-- "bundle install --deployment --retry 3 --jobs 4"\n+- "bin/cached-bundle install --deployment --retry 3 --jobs 4"\n - sudo apt-get update && sudo apt-get install git\n after_success: bundle exec rake publish_build\n script: rake test\\[$TEST_SUITE]\n@@ -22,6 +22,7 @@ notifications:\n     on_failure: always\n env:\n   global:\n+  - S3_BUILD_CACHE_BUCKET=emberjs-build-cache\n   - S3_BUCKET_NAME=builds.emberjs.com\n   - secure: ! \'KXJmcGLpnxnPmmei/qPNVcdQxLX1xyYIaVocinQ0YAjtBvCtAwg63EWMFnGp\n \ndiff --git a/bin/cached-bundle b/bin/cached-bundle\nnew file mode 100755\nindex 000000000..177ce0252\n--- /dev/null\n+++ b/bin/cached-bundle\n@@ -0,0 +1,61 @@\n+#!/usr/bin/env bash\n+# Usage: cached-bundle install --deployment\n+#\n+# After running `bundle`, caches the `vendor/bundle` directory to S3.\n+# On the next run, restores the cached directory before running `bundle`.\n+# When `Gemfile.lock` changes, the cache gets rebuilt.\n+#\n+# Requirements:\n+# - Gemfile.lock\n+# - TRAVIS_REPO_SLUG\n+# - TRAVIS_RUBY_VERSION\n+# - S3_BUILD_CACHE_BUCKET\n+# - script/s3-put\n+# - bundle\n+# - curl\n+#\n+# Author: Mislav Marohnić\n+# Source: https://github.com/github/hub/blob/aadc8418d9e5dd27172d5d67c3da0bd2fdcf759a/script/cached-bundle\n+\n+set -e\n+\n+compute_md5() {\n+  local output="$(openssl md5)"\n+  echo "${output##* }"\n+}\n+\n+download() {\n+  curl --tcp-nodelay -qsfL "$1" -o "$2"\n+}\n+\n+script_dir=$(dirname "${BASH_SOURCE[0]}")\n+bundle_path="vendor/bundle"\n+cache_buster="${BUNDLE_GEMFILE:-Gemfile}.lock"\n+if [ ! -f $cache_buster ]; then\n+  cache_buster="$GEMSPEC"\n+fi\n+cache_busting_hash="$(compute_md5 <"$cache_buster")"\n+\n+cache_name="bundler-${TRAVIS_RUBY_VERSION}-${cache_busting_hash}.tgz"\n+fetch_url="http://${S3_BUILD_CACHE_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}"\n+\n+if download "$fetch_url" "$cache_name"; then\n+  echo "Reusing cached bundle ${cache_name}"\n+  tar xzf "$cache_name"\n+fi\n+\n+bundle "$@"\n+\n+if [ ! -f "$cache_name" ]; then\n+  if [ -z "$S3_SECRET_ACCESS_KEY" ] || [ -z "$S3_ACCESS_KEY_ID" ]\n+  then\n+    echo "Enviroment variables not set. Exiting..."\n+    exit 0\n+  fi\n+\n+  echo "Caching \\`${bundle_path}\' to S3"\n+  tar czf "$cache_name" "$bundle_path"\n+  $script_dir/s3-put "$cache_name" "${S3_BUILD_CACHE_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}"\n+fi\n+\n+# vim: filetype=sh\ndiff --git a/bin/s3-put b/bin/s3-put\nnew file mode 100755\nindex 000000000..50b3eca04\n--- /dev/null\n+++ b/bin/s3-put\n@@ -0,0 +1,74 @@\n+#!/usr/bin/env bash\n+# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]\n+#\n+# Uploads a file to the Amazon S3 service.\n+# Outputs the URL for the newly uploaded file.\n+#\n+# Requirements:\n+# - S3_ACCESS_KEY_ID\n+# - S3_SECRET_ACCESS_KEY\n+# - openssl\n+# - curl\n+#\n+# Author: Mislav Marohnić\n+# Source: https://github.com/github/hub/blob/aadc8418d9e5dd27172d5d67c3da0bd2fdcf759a/script/s3-put\n+\n+set -e\n+\n+authorization() {\n+  local signature="$(string_to_sign | hmac_sha1 | base64)"\n+  echo "AWS ${S3_ACCESS_KEY_ID?}:${signature}"\n+}\n+\n+hmac_sha1() {\n+  openssl dgst -binary -sha1 -hmac "${S3_SECRET_ACCESS_KEY?}"\n+}\n+\n+base64() {\n+  openssl enc -base64\n+}\n+\n+bin_md5() {\n+  openssl dgst -binary -md5\n+}\n+\n+string_to_sign() {\n+  echo "$http_method"\n+  echo "$content_md5"\n+  echo "$content_type"\n+  echo "$date"\n+  echo "x-amz-acl:$acl"\n+  printf "/$bucket/$remote_path"\n+}\n+\n+date_string() {\n+  LC_TIME=C date "+%a, %d %h %Y %T %z"\n+}\n+\n+file="$1"\n+bucket="${2%%:*}"\n+remote_path="${2#*:}"\n+content_type="$3"\n+\n+if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then\n+  remote_path="${file##*/}"\n+fi\n+\n+http_method=PUT\n+acl="public-read"\n+content_md5="$(bin_md5 < "$file" | base64)"\n+date="$(date_string)"\n+\n+url="https://$bucket.s3.amazonaws.com/$remote_path"\n+\n+curl -qsSf -T "$file" \\\n+  -H "Authorization: $(authorization)" \\\n+  -H "x-amz-acl: $acl" \\\n+  -H "Date: $date" \\\n+  -H "Content-MD5: $content_md5" \\\n+  -H "Content-Type: $content_type" \\\n+  "$url"\n+\n+echo "$url"\n+\n+# vim: filetype=sh\n', 'commit_subject': 'Merge pull request #3907 from rjackson/use_cache', 'repo_name': 'emberjs/ember.js', 'committer': {'name': 'Stefan Penner', 'email': '0b40b374491a9d33ce3192c35cb80116802ee83a@gmail.com', 'time_sec': '1386735474', 'tz_offset': '-480', 'date': {'seconds': '1386735474'}}, 'commit_tree': 'c167037bdde81780f566ae5f8c374bbcb5767830', 'commit_message': 'Merge pull request #3907 from rjackson/use_cache\n\n[BUGFIX beta] Use a bundler cache to speed builds.', 'language_name': 'TypeScript', 'license': 'mit', 'hunks': '@@ -0,0 +1,74 @@\n+#!/usr/bin/env bash\n+# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]\n+#\n+# Uploads a file to the Amazon S3 service.\n+# Outputs the URL for the newly uploaded file.\n+#\n+# Requirements:\n+# - S3_ACCESS_KEY_ID\n+# - S3_SECRET_ACCESS_KEY\n+# - openssl\n+# - curl\n+#\n+# Author: Mislav Marohnić\n+# Source: https://github.com/github/hub/blob/aadc8418d9e5dd27172d5d67c3da0bd2fdcf759a/script/s3-put\n+\n+set -e\n+\n+authorization() {\n+  local signature="$(string_to_sign | hmac_sha1 | base64)"\n+  echo "AWS ${S3_ACCESS_KEY_ID?}:${signature}"\n+}\n+\n+hmac_sha1() {\n+  openssl dgst -binary -sha1 -hmac "${S3_SECRET_ACCESS_KEY?}"\n+}\n+\n+base64() {\n+  openssl enc -base64\n+}\n+\n+bin_md5() {\n+  openssl dgst -binary -md5\n+}\n+\n+string_to_sign() {\n+  echo "$http_method"\n+  echo "$content_md5"\n+  echo "$content_type"\n+  echo "$date"\n+  echo "x-amz-acl:$acl"\n+  printf "/$bucket/$remote_path"\n+}\n+\n+date_string() {\n+  LC_TIME=C date "+%a, %d %h %Y %T %z"\n+}\n+\n+file="$1"\n+bucket="${2%%:*}"\n+remote_path="${2#*:}"\n+content_type="$3"\n+\n+if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then\n+  remote_path="${file##*/}"\n+fi\n+\n+http_method=PUT\n+acl="public-read"\n+content_md5="$(bin_md5 < "$file" | base64)"\n+date="$(date_string)"\n+\n+url="https://$bucket.s3.amazonaws.com/$remote_path"\n+\n+curl -qsSf -T "$file" \\\n+  -H "Authorization: $(authorization)" \\\n+  -H "x-amz-acl: $acl" \\\n+  -H "Date: $date" \\\n+  -H "Content-MD5: $content_md5" \\\n+  -H "Content-Type: $content_type" \\\n+  "$url"\n+\n+echo "$url"\n+\n+# vim: filetype=sh\n', 'addition_count': 74, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/bin/s3-put', 'file_extension': '', 'before_file': 'ADDFILE', 'message': 'Merge pull request #3907 from rjackson/use_cache\n\n[BUGFIX beta] Use a bundler cache to speed builds.', 'author_name': 'Stefan Penner', 'lang': 's3-put'}