middleman-cloudfront 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 1.8.7
data/README.md CHANGED
@@ -7,7 +7,6 @@ Some of its features are:
7
7
  * Ability to filter files which are going to be invalidated by regex;
8
8
 
9
9
  # Usage
10
- andrusha/middleman-cloudfront
11
10
 
12
11
  ## Installation
13
12
  Add this to `Gemfile`:
@@ -48,7 +47,7 @@ bundle exec middleman invalidate
48
47
  ## S3 + Cloudfront deploying
49
48
 
50
49
  In real world this gem shouldn't be used alone, but as a part of your
51
- deployment solution. As for me I use it with [cloudfront-sync](https://github.com/karlfreeman/middleman-sync) and my configuration file looks like this:
50
+ deployment solution. As for me I use it with [middleman-sync](https://github.com/karlfreeman/middleman-sync) and my configuration file looks like this:
52
51
 
53
52
  ```ruby
54
53
  configure :build do
@@ -8,6 +8,8 @@ module Middleman
8
8
  class CloudFront < Thor
9
9
  include Thor::Actions
10
10
 
11
+ INVALIDATION_LIMIT = 1000
12
+
11
13
  check_unknown_options!
12
14
 
13
15
  namespace :invalidate
@@ -25,13 +27,25 @@ module Middleman
25
27
  :aws_secret_access_key => options.secret_access_key
26
28
  })
27
29
 
28
- distribution = cdn.distributions.get options.distribution_id
30
+ distribution = cdn.distributions.get(options.distribution_id)
29
31
 
30
- # CloudFront limits amount of files which can be invalidated by one request
31
- list_files(options.filter).each_slice(1000) do |slice|
32
- puts "Please wait while Cloudfront is reloading #{slice.length} paths, it might take up to 10 minutes"
33
- invalidation = distribution.invalidations.create :paths => slice
34
- invalidation.wait_for { ready? }
32
+ # CloudFront limits the amount of files which can be invalidated by one request to 1000.
33
+ # If there are more than 1000 files to invalidate, do so sequentially and wait until each validation is ready.
34
+ # If there are max 1000 files, create the invalidation and return immediately.
35
+ files = list_files(options.filter)
36
+ if files.count <= INVALIDATION_LIMIT
37
+ puts "Invalidating #{files.count} files. It might take 10 to 15 minutes until all files are invalidated."
38
+ puts 'Please check the AWS Management Console to see the status of the invalidation.'
39
+ invalidation = distribution.invalidations.create(:paths => files)
40
+ raise StandardError, %(Invalidation status is #{invalidation.status}. Expected "InProgress") unless invalidation.status == 'InProgress'
41
+ else
42
+ slices = files.each_slice(INVALIDATION_LIMIT)
43
+ puts "Invalidating #{files.count} files in #{slices.count} batch(es). It might take 10 to 15 minutes per batch until all files are invalidated."
44
+ slices.each_with_index do |slice, i|
45
+ puts "Invalidating batch #{i + 1}..."
46
+ invalidation = distribution.invalidations.create(:paths => slice)
47
+ invalidation.wait_for { ready? } unless i == slices.count - 1
48
+ end
35
49
  end
36
50
  end
37
51
 
@@ -56,14 +70,22 @@ module Middleman
56
70
 
57
71
  def list_files(filter)
58
72
  Dir.chdir('build/') do
59
- files = Dir.glob('**/*', File::FNM_DOTMATCH).reject { |f| File.directory? f }
60
- # if :directory_indexes is active, we must invalidate both files and dirs
61
- files += files.map{|f| f.gsub(/\/index\.html$/, '/') }
62
- files.uniq!
63
- files.map! { |f| f.start_with?('/') ? f : "/#{f}" }
64
- files.reject! { |f| not filter =~ f }
65
-
66
- files
73
+ Dir.glob('**/*', File::FNM_DOTMATCH).tap do |files|
74
+ # Remove directories
75
+ files.reject! { |f| File.directory?(f) }
76
+
77
+ # Remove files that do not match filter
78
+ files.reject! { |f| f !~ filter }
79
+
80
+ # Add directories of index.html files since they have to be
81
+ # invalidated as well if :directory_indexes is active
82
+ index_files = files.select { |f| f =~ %r(/index\.html\z) }
83
+ index_file_dirs = index_files.map { |f| f[%r((.+)index\.html\z), 1] }
84
+ files.concat index_file_dirs
85
+
86
+ # Add leading slash
87
+ files.map! { |f| f.start_with?('/') ? f : "/#{f}" }
88
+ end
67
89
  end
68
90
  end
69
91
 
@@ -1,6 +1,6 @@
1
1
  module Middleman
2
2
  module CloudFront
3
3
  PACKAGE = 'middleman-cloudfront'
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
6
6
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = Middleman::CloudFront::PACKAGE
7
7
  s.version = Middleman::CloudFront::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Andrey Korzhuev"]
9
+ s.authors = ["Andrey Korzhuev", "Manuel Meurer"]
10
10
  s.email = ["andrew@korzhuev.com"]
11
11
  s.homepage = "https://github.com/andrusha/middleman-cloudfront"
12
12
  s.summary = %q{Invalidate CloudFront cache after deployment to S3}
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cloudfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrey Korzhuev
9
+ - Manuel Meurer
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
13
+ date: 2013-08-11 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: middleman-core