travis_bundle_cache 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51e3d47f4cb66ef1f3a31a1758e8c47fd59d492f
4
+ data.tar.gz: 89ddc01522b4650b092576f37914e4d63f3cce02
5
+ SHA512:
6
+ metadata.gz: 15a4cf836fc301f427ea47a7dbc8dc727d276fc56f44e2ded5ae0f03da0e7686aa025e2367d86cd9c5101f6a5aa325ea9fa0a270f347bf86cb8a76073b6bc665
7
+ data.tar.gz: 9795b30ebb39eaaf25ed66f6d269938edfdefd60a8d79bcc52b0a0f0deb15d55fb56224097ad6eff5f48b064cb1a96ca4415c55383892d89abe1d62e102d4704
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,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in travis_bundle_cache.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Genord II
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # TravisBundleCache
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/travis_bundle_cache.png)](http://badge.fury.io/rb/travis_bundle_cache)
4
+
5
+ Cache the gem bundle for speedy travis builds
6
+
7
+ ## Usage
8
+
9
+ 1. Set up a bucket on S3 in the US Standard region (us-east-1) (and possibly a new user via IAM)
10
+ 2. Install the travis gem
11
+
12
+ ```bash
13
+ gem install travis
14
+ ```
15
+
16
+ 3. Log into Travis (from inside your project respository directory)
17
+
18
+ ```bash
19
+ travis login --auto
20
+ ```
21
+
22
+ 4. Encrypt your S3 credentials (be sure to add your actual credentials inside the double quotes)
23
+
24
+ ```bash
25
+ travis encrypt AWS_S3_KEY="" AWS_S3_SECRET="" --add
26
+ ```
27
+
28
+ 5. Setup your .travis.yml to include the following
29
+
30
+ ```yaml
31
+ env:
32
+ global:
33
+ - BUNDLE_ARCHIVE="your-bundle-name"
34
+ - AWS_S3_REGION="us-east-1"
35
+ - AWS_S3_BUCKET="your-bucket-name"
36
+
37
+ before_install:
38
+ - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
39
+ - "gem install travis_bundle_cache"
40
+
41
+ install: travis_bundle_install
42
+
43
+ after_script:
44
+ - "travis_bundle_cache"
45
+ ```
46
+
47
+ Enjoy faster builds
48
+
49
+ ## Contributions
50
+
51
+ TravisBundleCache is open source and contributions from the community are encouraged! No contribution is too small. Please consider:
52
+
53
+ * adding an awesome feature
54
+ * fixing a terrible bug
55
+ * updating documentation
56
+ * fixing a not-so-bad bug
57
+ * fixing typos
58
+
59
+ For the best chance of having your changes merged, please:
60
+
61
+ 1. Ask us! We'd love to hear what you're up to.
62
+ 2. Fork the project.
63
+ 3. Commit your changes and tests (if applicable (they're applicable)).
64
+ 4. Submit a pull request with a thorough explanation and at least one animated GIF.
65
+
66
+ ## Thanks
67
+
68
+ Most of the credit for this gem goes to Random Errata and [this](http://randomerrata.com/post/45827813818/travis-s3) blog post
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'travis_bundle_cache/cache'
5
+
6
+ TravisBundleCache::Cache.new.cache
7
+
8
+ exit 0
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'travis_bundle_cache/cache'
5
+
6
+ TravisBundleCache::Cache.new.install
7
+
8
+ exit 0
@@ -0,0 +1,94 @@
1
+ require "digest"
2
+ require "fog"
3
+
4
+ module TravisBundleCache
5
+ class Cache
6
+ def initialize
7
+ @bucket_name = ENV["AWS_S3_BUCKET"]
8
+ @architecture = `uname -m`.strip
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"]), "Gemfile.lock")
12
+ @digest_filename = "#{@file_name}.sha2"
13
+ @old_digest_filename = File.expand_path("~/remote_#{@digest_filename}")
14
+ end
15
+
16
+ def install
17
+ `cd ~ && wget -O "remote_#{@file_name}" "https://#{@bucket_name}.s3.amazonaws.com/#{@file_name}" && tar -xf "remote_#{@file_name}"`
18
+ `cd ~ && wget -O "remote_#{@file_name}.sha2" "https://#{@bucket_name}.s3.amazonaws.com/#{@file_name}.sha2"`
19
+ `bundle install --without #{ENV['BUNDLE_WITHOUT'] || "development production"} --path=~/.bundle`
20
+ end
21
+
22
+ def cache_bundle
23
+ puts "Checking for changes"
24
+ @bundle_digest = Digest::SHA2.file(@lock_file).hexdigest
25
+ @old_digest = File.exists?(@old_digest_filename) ? File.read(@old_digest_filename) : ""
26
+
27
+ if @bundle_digest == @old_digest
28
+ puts "=> There were no changes, doing nothing"
29
+ else
30
+ archive_and_upload_bundle
31
+ end
32
+ end
33
+
34
+ def archive_and_upload_bundle
35
+ if @old_digest == ""
36
+ puts "=> There was no existing digest, uploading a new version of the archive"
37
+ else
38
+ puts "=> There were changes, uploading a new version of the archive"
39
+ puts " => Old checksum: #{@old_digest}"
40
+ puts " => New checksum: #{@bundle_digest}"
41
+ end
42
+
43
+ puts "=> Preparing bundle archive"
44
+ `cd ~ && tar -cjf "#{@file_name}" .bundle && split -b 5m -a 3 "#{@file_name}" "#{@file_name}."`
45
+
46
+ parts_pattern = File.expand_path(File.join("~", "#{@file_name}.*"))
47
+ parts = Dir.glob(parts_pattern).sort
48
+
49
+ puts "=> Uploading the bundle"
50
+ puts " => Beginning multipart upload"
51
+ response = storage.initiate_multipart_upload @bucket_name, @file_name, { "x-amz-acl" => "public-read" }
52
+ upload_id = response.body['UploadId']
53
+ puts " => Upload ID: #{upload_id}"
54
+
55
+ part_ids = []
56
+
57
+ puts " => Uploading #{parts.length} parts"
58
+ parts.each_with_index do |part, index|
59
+ part_number = (index + 1).to_s
60
+ puts " => Uploading #{part}"
61
+ File.open part do |part_file|
62
+ response = storage.upload_part @bucket_name, @file_name, upload_id, part_number, part_file
63
+ part_ids << response.headers['ETag']
64
+ puts " => Uploaded"
65
+ end
66
+ end
67
+
68
+ puts " => Completing multipart upload"
69
+ storage.complete_multipart_upload @bucket_name, @file_name, upload_id, part_ids
70
+
71
+ puts "=> Uploading the digest file"
72
+ bucket = storage.directories.new(key: @bucket_name)
73
+ bucket.files.create({
74
+ :body => @bundle_digest,
75
+ :key => @digest_filename,
76
+ :public => true,
77
+ :content_type => "text/plain"
78
+ })
79
+
80
+ puts "All done now."
81
+ end
82
+
83
+ protected
84
+
85
+ def storage
86
+ @storage ||= Fog::Storage.new({
87
+ :provider => "AWS",
88
+ :aws_access_key_id => ENV["AWS_S3_KEY"],
89
+ :aws_secret_access_key => ENV["AWS_S3_SECRET"],
90
+ :region => ENV["AWS_S3_REGION"] || "us-east-1"
91
+ })
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module TravisBundleCache
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "travis_bundle_cache/version"
2
+
3
+ module TravisBundleCache
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'travis_bundle_cache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "travis_bundle_cache"
8
+ spec.version = TravisBundleCache::VERSION
9
+ spec.authors = ["David Genord II"]
10
+ spec.email = ["david@collectiveidea.com"]
11
+ spec.description = %q{Cache the gem bundle for speedy travis builds}
12
+ spec.summary = %q{Cache the gem bundle for speedy travis builds}
13
+ spec.homepage = "https://github.com/collectiveidea/travis_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
+ spec.executables = ["travis_bundle_cache", "travis_bundle_install"]
21
+
22
+ spec.add_dependency "bundler", "~> 1.3"
23
+ spec.add_dependency "fog"
24
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis_bundle_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Genord II
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Cache the gem bundle for speedy travis builds
42
+ email:
43
+ - david@collectiveidea.com
44
+ executables:
45
+ - travis_bundle_cache
46
+ - travis_bundle_install
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/travis_bundle_cache
56
+ - bin/travis_bundle_install
57
+ - lib/travis_bundle_cache.rb
58
+ - lib/travis_bundle_cache/cache.rb
59
+ - lib/travis_bundle_cache/version.rb
60
+ - travis_bundle_cache.gemspec
61
+ homepage: https://github.com/collectiveidea/travis_bundle_cache
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Cache the gem bundle for speedy travis builds
85
+ test_files: []