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 +0 -1
- data/README.md +1 -2
- data/lib/middleman-cloudfront/commands.rb +36 -14
- data/lib/middleman-cloudfront/pkg-info.rb +1 -1
- data/middleman-cloudfront.gemspec +1 -1
- metadata +3 -2
data/.travis.yml
CHANGED
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 [
|
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
|
30
|
+
distribution = cdn.distributions.get(options.distribution_id)
|
29
31
|
|
30
|
-
# CloudFront limits amount of files which can be invalidated by one request
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
|
@@ -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.
|
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-
|
13
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: middleman-core
|