bundle_cache 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef06ddf7e865d936c9117b57a00e50e384444f80
4
+ data.tar.gz: b14ec0cc46f7d692afec351663152f97a698579e
5
+ SHA512:
6
+ metadata.gz: c4dcd3d54d556527b3c8dcbedb334d28ecf0c67c611328f2bcb8293e1537687099b1c2b4663a4ed491b8787ecb23295f4446fd1c9b5a2fb79bcfa03f08141c26
7
+ data.tar.gz: 0d48ad804bf05e63656a1754d499738d72e555ba1d7eb8b4c445c41e91c239f296fbc03395881c087dd36b1b2ccb53fd3829c02702cf9009961e9b6a39dc8bd0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bundle_cache.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # BundleCache
2
+
3
+ Utility for caching bundled gems on S3. Useful for speeding up Travis builds -
4
+ it doesn't need to wait for `bundle install` to download/install all gems.
5
+
6
+ ## Installation
7
+
8
+ Adding this to your Gemfile defeats the purpose. Instead, run
9
+
10
+ $ gem install bundle_cache
11
+
12
+ ## Usage
13
+
14
+ You'll need to set some environment variables to make this work.
15
+
16
+ AWS_S3_KEY=<your aws access key>
17
+ AWS_S3_SECRET=<your aws secret>
18
+ AWS_S3_BUCKET=<your bucket name>
19
+ BUNDLE_ARCHIVE=<the filename to use for your cache>
20
+
21
+ ## License
22
+
23
+ This code was originally written by Matias Korhonen and is available at
24
+ http://randomerrata.com/post/45827813818/travis-s3. It is MIT licensed.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/bundle_cache ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/bundle_cache'
4
+
5
+ required_env = %w(AWS_S3_KEY AWS_S3_SECRET AWS_S3_BUCKET BUNDLE_ARCHIVE)
6
+
7
+ required_env.each do |var|
8
+ unless ENV[var]
9
+ puts "Missing ENV[#{var}]"
10
+ exit 1
11
+ end
12
+ end
13
+
14
+ BundleCache.cache
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ architecture = `uname -m`.strip
4
+ file_name = "#{ENV['BUNDLE_ARCHIVE']}-#{architecture}.tgz"
5
+
6
+ Dir.chdir(ENV['HOME'])
7
+ `wget -O "remote_#{file_name}" "https://s3.amazonaws.com/#{ENV['AWS_S3_BUCKET']}/#{file_name}" && tar -xf "remote_#{file_name}"`
8
+ `wget -O "remote_#{file_name}.sha2" "https://s3.amazonaws.com/#{ENV['AWS_S3_BUCKET']}/#{file_name}.sha2"`
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bundle_cache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bundle_cache"
8
+ spec.version = BundleCache::VERSION
9
+ spec.authors = ["Eric Barendt"]
10
+ spec.email = ["eric.barendt@infogroup.com"]
11
+ spec.description = %q{Caches bundled gems on S3}
12
+ spec.summary = %q{Caches bundled gems on S3}
13
+ spec.homepage = "https://github.com/data-axle/bundle_cache"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "fog"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,77 @@
1
+ require "digest"
2
+ require "fog"
3
+
4
+ module BundleCache
5
+ def self.cache
6
+ bucket_name = ENV["AWS_S3_BUCKET"]
7
+ architecture = `uname -m`.strip
8
+
9
+ file_name = "#{ENV['BUNDLE_ARCHIVE']}-#{architecture}.tgz"
10
+ file_path = File.expand_path("~/#{file_name}")
11
+ lock_file = File.join(File.expand_path(ENV["TRAVIS_BUILD_DIR"].to_s), "Gemfile.lock")
12
+ digest_filename = "#{file_name}.sha2"
13
+ old_digest = File.expand_path("~/remote_#{digest_filename}")
14
+
15
+ puts "Checking for changes"
16
+ bundle_digest = Digest::SHA2.file(lock_file).hexdigest
17
+ old_digest = File.exists?(old_digest) ? File.read(old_digest) : ""
18
+
19
+ if bundle_digest == old_digest
20
+ puts "=> There were no changes, doing nothing"
21
+ else
22
+ if old_digest == ""
23
+ puts "=> There was no existing digest, uploading a new version of the archive"
24
+ else
25
+ puts "=> There were changes, uploading a new version of the archive"
26
+ puts " => Old checksum: #{old_digest}"
27
+ puts " => New checksum: #{bundle_digest}"
28
+ end
29
+
30
+ puts "=> Preparing bundle archive"
31
+ `cd ~ && tar -cjf #{file_name} .bundle && split -b 5m -a 3 #{file_name} #{file_name}.`
32
+
33
+ parts_pattern = File.expand_path(File.join("~", "#{file_name}.*"))
34
+ parts = Dir.glob(parts_pattern).sort
35
+
36
+ storage = Fog::Storage.new({
37
+ :provider => "AWS",
38
+ :aws_access_key_id => ENV["AWS_S3_KEY"],
39
+ :aws_secret_access_key => ENV["AWS_S3_SECRET"],
40
+ :region => ENV["AWS_S3_REGION"] || "us-east-1"
41
+ })
42
+
43
+ puts "=> Uploading the bundle"
44
+ puts " => Beginning multipart upload"
45
+ response = storage.initiate_multipart_upload bucket_name, file_name, { "x-amz-acl" => "public-read" }
46
+ upload_id = response.body['UploadId']
47
+ puts " => Upload ID: #{upload_id}"
48
+
49
+ part_ids = []
50
+
51
+ puts " => Uploading #{parts.length} parts"
52
+ parts.each_with_index do |part, index|
53
+ part_number = (index + 1).to_s
54
+ puts " => Uploading #{part}"
55
+ File.open part do |part_file|
56
+ response = storage.upload_part bucket_name, file_name, upload_id, part_number, part_file
57
+ part_ids << response.headers['ETag']
58
+ puts " => Uploaded"
59
+ end
60
+ end
61
+
62
+ puts " => Completing multipart upload"
63
+ storage.complete_multipart_upload bucket_name, file_name, upload_id, part_ids
64
+
65
+ puts "=> Uploading the digest file"
66
+ bucket = storage.directories.new(key: bucket_name)
67
+ bucket.files.create({
68
+ :body => bundle_digest,
69
+ :key => digest_filename,
70
+ :public => true,
71
+ :content_type => "text/plain"
72
+ })
73
+ end
74
+
75
+ puts "All done now."
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module BundleCache
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "bundle_cache/version"
2
+ require "bundle_cache/cache"
3
+
4
+ module BundleCache
5
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundle_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Eric Barendt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Caches bundled gems on S3
56
+ email:
57
+ - eric.barendt@infogroup.com
58
+ executables:
59
+ - bundle_cache
60
+ - bundle_cache_install
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/bundle_cache
69
+ - bin/bundle_cache_install
70
+ - bundle_cache.gemspec
71
+ - lib/bundle_cache.rb
72
+ - lib/bundle_cache/cache.rb
73
+ - lib/bundle_cache/version.rb
74
+ homepage: https://github.com/data-axle/bundle_cache
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Caches bundled gems on S3
98
+ test_files: []