github.com/jingweno/gh@v2.1.1-0.20221007190738-04a7985fa9a1+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 TRAVIS_RUBY_VERSION=`ruby -e "print RUBY_VERSION"` 32 gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}.lock")" 33 cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz" 34 fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}" 35 36 if download "$fetch_url" "$cache_name"; then 37 echo "Reusing cached bundle ${cache_name}" 38 tar xzf "$cache_name" 39 fi 40 41 bundle "$@" 42 43 if [ ! -f "$cache_name" ]; then 44 echo "Caching \`${bundle_path}' to S3" 45 tar czf "$cache_name" "$bundle_path" 46 script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}" 47 fi