Cache bundle results on Travis to S3

Hopefully speeds up builds
This commit is contained in:
Mislav Marohnić 2013-12-07 14:58:56 +01:00
Родитель 7845f0a548
Коммит e4641544de
3 изменённых файлов: 113 добавлений и 0 удалений

Просмотреть файл

@ -1,6 +1,7 @@
before_install: before_install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq tmux zsh git - sudo apt-get install -qq tmux zsh git
install: script/cached-bundle install --deployment
script: script/test script: script/test
language: ruby language: ruby
rvm: rvm:
@ -13,3 +14,8 @@ notifications:
recipients: recipients:
- mislav.marohnic@gmail.com - mislav.marohnic@gmail.com
on_success: never on_success: never
env:
global:
- AMAZON_S3_BUCKET=ci-cache
- AMAZON_ACCESS_KEY_ID=AKIAJQCVTDEWQHRPBPGQ
- secure: "XAZv5xyNjWt7F9hG0MZhDANVJ5h/ajEZvfJOEIZRQlE3X5x6oVgI8blLh/MmlRSF0kIyLckcn6t2ccjSOvwN2hca5bwZSjIqoKbJyNe2cmkxfi2432vEOu3Ve6PT5hZWX4R5RgT+xWyMjIJcdF3gUMP7ErXl64aEncBzeW6OoXM="

40
script/cached-bundle Executable file
Просмотреть файл

@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Usage: cached-bundle install --deployment
#
# After running `bundle`, caches the `vendor/bundle` directory to S3.
# On the next run, restores the cached directory before running `bundle`.
#
# Requirements:
# - TRAVIS_REPO_SLUG
# - TRAVIS_RUBY_VERSION
# - AMAZON_S3_BUCKET
# - script/s3-put
set -e
compute_md5() {
local output="$(openssl md5)"
echo "${output##* }"
}
download() {
curl --tcp-nodelay -qsfL "$1" -o "$2"
}
bundle_path="vendor/bundle"
gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}.lock")"
cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz"
fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}"
if download "$fetch_url" "$cache_name"; then
echo "Reusing cached bundle ${cache_name}"
tar xzf "$cache_name"
fi
bundle "$@"
if [ ! -f "$cache_name" ]; then
echo "Caching \`${bundle_path}' to S3"
tar czf "$cache_name" "$bundle_path"
script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}"
fi

67
script/s3-put Executable file
Просмотреть файл

@ -0,0 +1,67 @@
#!/usr/bin/env bash
# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
#
# Uploads a file to the Amazon S3 service.
#
# Depends on AWS credentials being set via env:
# - AMAZON_ACCESS_KEY_ID
# - AMAZON_SECRET_ACCESS_KEY
#
# Outputs the URL of the newly uploaded file.
set -e
authorization() {
local signature="$(string_to_sign | hmac_sha1 | base64)"
echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}"
}
hmac_sha1() {
openssl dgst -binary -sha1 -hmac "${AMAZON_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"