github.com/trevoraustin/hub@v2.2.0-preview1.0.20141105230840-96d8bfc654cc+incompatible/script/cached-bundle (about) 1 #!/usr/bin/env bash 2 # Usage: cached-bundle install --deployment 3 # 4 # After running `bundle`, caches the `vendor/bundle` directory to S3. 5 # On the next run, restores the cached directory before running `bundle`. 6 # When `Gemfile.lock` changes, the cache gets rebuilt. 7 # 8 # Requirements: 9 # - Gemfile.lock 10 # - TRAVIS_REPO_SLUG 11 # - TRAVIS_RUBY_VERSION 12 # - AMAZON_S3_BUCKET 13 # - script/s3-put 14 # - bundle 15 # - curl 16 # 17 # Author: Mislav Marohnić 18 19 set -e 20 21 compute_md5() { 22 local output="$(openssl md5)" 23 echo "${output##* }" 24 } 25 26 download() { 27 curl --tcp-nodelay -qsfL "$1" -o "$2" 28 } 29 30 bundle_path="vendor/bundle" 31 gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}.lock")" 32 cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz" 33 fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}" 34 35 if download "$fetch_url" "$cache_name"; then 36 echo "Reusing cached bundle ${cache_name}" 37 tar xzf "$cache_name" 38 fi 39 40 bundle "$@" 41 42 if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; then 43 echo "Caching \`${bundle_path}' to S3" 44 tar czf "$cache_name" "$bundle_path" 45 script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}" 46 fi