File: cached-bundle

package info (click to toggle)
ruby-vcr 6.0.0%2Breally5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: ruby: 8,456; sh: 177; makefile: 7
file content (48 lines) | stat: -rwxr-xr-x 1,372 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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`.
# When `Gemfile.lock` changes, the cache gets rebuilt.
#
# Requirements:
# - Gemfile.lock
# - 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="vendor/bundle"
gemfile_hash="$(cat "${BUNDLE_GEMFILE:-Gemfile}.lock" gemfiles/*.lock | compute_md5)"
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 "$@"
BUNDLE_GEMFILE=gemfiles/faraday_old.gemfile bundle "$@" --path "$PWD"/vendor/bundle
BUNDLE_GEMFILE=gemfiles/typhoeus_old.gemfile bundle "$@" --path "$PWD"/vendor/bundle

if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; 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