mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Cache Bundler dependencies on Travis CI
- Even after the cache is restored, `bundle install` still needs to hit RubyGems.org because there is no Gemfile.lock. There doesn't seem to be a way to tell it that everything it needs is right there in the `./bundle` directory. - Can't use `--standalone` due to bundler/bundler#2851 - It's not necessary to manually update RubyGems and Bundler anymore.
This commit is contained in:
parent
0dcbe1023e
commit
03d92dd203
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,6 +13,7 @@ bin
|
||||
*.gem
|
||||
.bundle
|
||||
Gemfile.lock
|
||||
/bundle
|
||||
|
||||
## PROJECT::SPECIFIC
|
||||
.rbx
|
||||
|
22
.travis.yml
22
.travis.yml
@ -1,14 +1,5 @@
|
||||
before_install:
|
||||
- gem update bundler
|
||||
- bundle --version
|
||||
- gem update --system 2.1.11
|
||||
- gem --version
|
||||
bundler_args: --standalone --without development
|
||||
script: RUBYLIB=./bundle script/test
|
||||
|
||||
env:
|
||||
- SSL=no
|
||||
- SSL=yes
|
||||
install: script/cached-bundle install --path ./bundle --without development -j 3 -r 3
|
||||
script: bundle exec script/test
|
||||
|
||||
language: ruby
|
||||
|
||||
@ -33,3 +24,12 @@ rvm:
|
||||
- jruby-19mode
|
||||
- jruby-head
|
||||
- rbx
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- SSL=no
|
||||
- SSL=yes
|
||||
global:
|
||||
- AMAZON_S3_BUCKET=ci-cache
|
||||
- AMAZON_ACCESS_KEY_ID=AKIAJQCVTDEWQHRPBPGQ
|
||||
- secure: "fgk+vBuCp9GW2AlNAcWy5Axl+UEjXTTCwZa6boa5lvg6yBaBKHxqT4XH31U5My3SxJEaQpPDNE/ObHv8InV9DOP5ZI7c8s3cVrBx5a8LZSd25UZBozUHxMeZmFGlgc3syYkLjoeAE+4YmhmTnuKncb0xhke90wJw5T4Z5+GPmzI="
|
||||
|
46
script/cached-bundle
Executable file
46
script/cached-bundle
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: cached-bundle install --deployment
|
||||
#
|
||||
# After running `bundle`, caches the `./bundle` directory to S3.
|
||||
# On the next run, restores the cached directory before running `bundle`.
|
||||
# When `Gemfile` changes, the cache gets rebuilt.
|
||||
#
|
||||
# Requirements:
|
||||
# - Gemfile
|
||||
# - TRAVIS_REPO_SLUG
|
||||
# - TRAVIS_RUBY_VERSION
|
||||
# - AMAZON_S3_BUCKET
|
||||
# - script/s3-put
|
||||
# - bundle
|
||||
# - curl
|
||||
#
|
||||
# Author: Mislav Marohnić
|
||||
|
||||
set -e
|
||||
|
||||
compute_md5() {
|
||||
local output="$(openssl md5)"
|
||||
echo "${output##* }"
|
||||
}
|
||||
|
||||
download() {
|
||||
curl --tcp-nodelay -qsfL "$1" -o "$2"
|
||||
}
|
||||
|
||||
bundle_path="bundle"
|
||||
gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}")"
|
||||
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
|
71
script/s3-put
Executable file
71
script/s3-put
Executable file
@ -0,0 +1,71 @@
|
||||
#!/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:
|
||||
# - AMAZON_ACCESS_KEY_ID
|
||||
# - AMAZON_SECRET_ACCESS_KEY
|
||||
# - openssl
|
||||
# - curl
|
||||
#
|
||||
# Author: Mislav Marohnić
|
||||
|
||||
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"
|
Loading…
x
Reference in New Issue
Block a user