middleman-cloudfront 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/Rakefile +0 -23
- data/lib/middleman-cloudfront/commands.rb +12 -13
- data/lib/middleman-cloudfront/extension.rb +4 -0
- data/lib/middleman-cloudfront/version.rb +5 -0
- data/middleman-cloudfront.gemspec +6 -3
- data/spec/lib/middleman-cloudfront/commands_spec.rb +38 -12
- data/spec/spec_helper.rb +0 -1
- metadata +24 -24
- data/lib/middleman-cloudfront/pkg-info.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12348384796b7067046a25f423794d619a66e943
|
4
|
+
data.tar.gz: 8aa2e82b808ca93d29e33104a40fbe5715937150
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0837f2f566cf23f9ac6c33f0fdc76c72ed414da0740d8fa3e7ea8bc3d5a91e2fc4638c2d9fec7445773f8864d8ac2a68ae9aee836931f104402ff3d98836038d
|
7
|
+
data.tar.gz: 0ba79f208ec3c2ce644d5c040338c57dd94b4329bd5139d237d3d989a3fad55589dcd8a61f769728e618d299a33faa215b77d016a0aa356175bcdd571eaebd74
|
data/README.md
CHANGED
@@ -32,6 +32,26 @@ activate :cloudfront do |cf|
|
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
On Amazon use following parameters inside your IAM policy:
|
36
|
+
```
|
37
|
+
{
|
38
|
+
"Version": "2012-10-17",
|
39
|
+
"Statement": [
|
40
|
+
{
|
41
|
+
"Sid": "Stmt1409254980000",
|
42
|
+
"Effect": "Allow",
|
43
|
+
"Action": [
|
44
|
+
"cloudfront:CreateInvalidation",
|
45
|
+
"cloudfront:GetDistribution"
|
46
|
+
],
|
47
|
+
"Resource": [
|
48
|
+
"*"
|
49
|
+
]
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
35
55
|
## Running
|
36
56
|
|
37
57
|
If you set `after_build` to `true` cache would be automatically invalidated after build:
|
@@ -44,6 +64,16 @@ Otherwise you should run it through commandline interface like so:
|
|
44
64
|
bundle exec middleman invalidate
|
45
65
|
```
|
46
66
|
|
67
|
+
or from within Middleman, optionally specifying a list of files to invalidate:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Invalidate automatic selection of files from build directory
|
71
|
+
invalidate
|
72
|
+
|
73
|
+
# Invalidate explicit list of files
|
74
|
+
invalidate %w(/index.html /images/example.png)
|
75
|
+
```
|
76
|
+
|
47
77
|
## S3 + Cloudfront deploying
|
48
78
|
|
49
79
|
In real world this gem shouldn't be used alone, but as a part of your
|
@@ -78,3 +108,10 @@ And when I want to deploy my site I do:
|
|
78
108
|
AWS_ACCESS_KEY= AWS_SECRET= bundle exec middleman sync
|
79
109
|
AWS_ACCESS_KEY= AWS_SECRET= bundle exec middleman invalidate
|
80
110
|
```
|
111
|
+
|
112
|
+
If you use [middleman-s3_sync](https://github.com/fredjean/middleman-s3_sync) for deployment, you can use its `after_s3_sync` hook to automatically invalidate updated files after syncing:
|
113
|
+
```ruby
|
114
|
+
after_s3_sync do |files_by_status|
|
115
|
+
invalidate files_by_status[:updated]
|
116
|
+
end
|
117
|
+
```
|
data/Rakefile
CHANGED
@@ -9,29 +9,6 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
|
9
9
|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
10
10
|
end
|
11
11
|
|
12
|
-
require 'rake/clean'
|
13
|
-
|
14
|
-
require "middleman-cloudfront/pkg-info"
|
15
|
-
|
16
|
-
PACKAGE = "#{Middleman::CloudFront::PACKAGE}"
|
17
|
-
VERSION = "#{Middleman::CloudFront::VERSION}"
|
18
|
-
|
19
|
-
task :package do
|
20
|
-
system "gem build #{PACKAGE}.gemspec"
|
21
|
-
end
|
22
|
-
|
23
|
-
task :install => :package do
|
24
|
-
Dir.chdir("pkg") do
|
25
|
-
system "gem install #{PACKAGE}-#{VERSION}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
task :release => :package do
|
30
|
-
Dir.chdir("pkg") do
|
31
|
-
system "gem push #{PACKAGE}-#{VERSION}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
12
|
RSpec::Core::RakeTask.new(:spec)
|
36
13
|
|
37
14
|
task :default => :spec
|
@@ -18,8 +18,8 @@ module Middleman
|
|
18
18
|
true
|
19
19
|
end
|
20
20
|
|
21
|
-
desc "
|
22
|
-
def invalidate(options = nil)
|
21
|
+
desc "invalidate", "A way to deal with your CloudFront distributions"
|
22
|
+
def invalidate(options = nil, files = nil)
|
23
23
|
if options.nil?
|
24
24
|
app_instance = ::Middleman::Application.server.inst
|
25
25
|
unless app_instance.respond_to?(:cloudfront_options)
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
# CloudFront limits the amount of files which can be invalidated by one request to 1000.
|
56
56
|
# If there are more than 1000 files to invalidate, do so sequentially and wait until each validation is ready.
|
57
57
|
# If there are max 1000 files, create the invalidation and return immediately.
|
58
|
-
files = list_files(options.filter)
|
58
|
+
files = normalize_files(files || list_files(options.filter))
|
59
59
|
return if files.empty?
|
60
60
|
|
61
61
|
if files.count <= INVALIDATION_LIMIT
|
@@ -84,20 +84,19 @@ end
|
|
84
84
|
|
85
85
|
# Remove files that do not match filter
|
86
86
|
files.reject! { |f| f !~ filter }
|
87
|
-
|
88
|
-
# Add directories of index.html files since they have to be
|
89
|
-
# invalidated as well if :directory_indexes is active
|
90
|
-
files.each do |file|
|
91
|
-
file_dir = file.sub(/\bindex\.html\z/, '')
|
92
|
-
files << file_dir if file_dir != file
|
93
|
-
end
|
94
|
-
|
95
|
-
# Add leading slash
|
96
|
-
files.map! { |f| f.start_with?('/') ? f : "/#{f}" }
|
97
87
|
end
|
98
88
|
end
|
99
89
|
end
|
100
90
|
|
91
|
+
def normalize_files(files)
|
92
|
+
# Add directories since they have to be invalidated
|
93
|
+
# as well if :directory_indexes is active
|
94
|
+
files += files.grep(/\/index.html\z/).map { |file| File.dirname(file) << '/' }.uniq
|
95
|
+
|
96
|
+
# URI encode and add leading slash
|
97
|
+
files.map { |f| URI::encode(f.start_with?('/') ? f : "/#{f}") }
|
98
|
+
end
|
99
|
+
|
101
100
|
end
|
102
101
|
|
103
102
|
Base.map({"inv" => "invalidate"})
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'middleman-cloudfront/version'
|
4
7
|
|
5
8
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
9
|
+
s.name = 'middleman-cloudfront'
|
7
10
|
s.version = Middleman::CloudFront::VERSION
|
8
11
|
s.platform = Gem::Platform::RUBY
|
9
12
|
s.authors = ["Andrey Korzhuev", "Manuel Meurer"]
|
@@ -17,24 +17,30 @@ describe Middleman::Cli::CloudFront do
|
|
17
17
|
|
18
18
|
describe '#invalidate' do
|
19
19
|
before do
|
20
|
-
Fog::CDN::AWS::Distributions.
|
21
|
-
distribution.invalidations.
|
22
|
-
double('invalidation', status: 'InProgress', wait_for: ->{}
|
20
|
+
allow_any_instance_of(Fog::CDN::AWS::Distributions).to receive(:get).and_return(distribution)
|
21
|
+
allow(distribution.invalidations).to receive(:create) do
|
22
|
+
double('invalidation', status: 'InProgress', wait_for: -> {})
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'gets the correct distribution' do
|
27
|
-
cloudfront.
|
27
|
+
allow(cloudfront).to receive(:list_files).and_return([])
|
28
28
|
expect_any_instance_of(Fog::CDN::AWS::Distributions).to receive(:get).with('distribution_id_123')
|
29
29
|
cloudfront.invalidate(options)
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'normalizes paths' do
|
33
|
+
files = %w(file directory/index.html)
|
34
|
+
normalized_files = %w(/file /directory/index.html /directory/)
|
35
|
+
allow(cloudfront).to receive(:list_files).and_return(files)
|
36
|
+
expect(distribution.invalidations).to receive(:create).once.with(paths: normalized_files)
|
37
|
+
cloudfront.invalidate(options)
|
38
|
+
end
|
39
|
+
|
32
40
|
context 'when the amount of files to invalidate is under the limit' do
|
33
41
|
it 'divides them up in packages and creates one invalidation per package' do
|
34
|
-
files = (1..Middleman::Cli::CloudFront::INVALIDATION_LIMIT).map
|
35
|
-
|
36
|
-
end
|
37
|
-
cloudfront.stub(:list_files).and_return files
|
42
|
+
files = (1..Middleman::Cli::CloudFront::INVALIDATION_LIMIT).map { |i| "/file_#{i}" }
|
43
|
+
allow(cloudfront).to receive(:list_files).and_return(files)
|
38
44
|
expect(distribution.invalidations).to receive(:create).once.with(paths: files)
|
39
45
|
cloudfront.invalidate(options)
|
40
46
|
end
|
@@ -42,15 +48,35 @@ describe Middleman::Cli::CloudFront do
|
|
42
48
|
|
43
49
|
context 'when the amount of files to invalidate is over the limit' do
|
44
50
|
it 'creates only one invalidation with all of them' do
|
45
|
-
files = (1..(Middleman::Cli::CloudFront::INVALIDATION_LIMIT * 3)).map
|
46
|
-
|
47
|
-
end
|
48
|
-
cloudfront.stub(:list_files).and_return files
|
51
|
+
files = (1..(Middleman::Cli::CloudFront::INVALIDATION_LIMIT * 3)).map { |i| "/file_#{i}" }
|
52
|
+
allow(cloudfront).to receive(:list_files).and_return(files)
|
49
53
|
expect(distribution.invalidations).to receive(:create).once.with(paths: files[0, Middleman::Cli::CloudFront::INVALIDATION_LIMIT])
|
50
54
|
expect(distribution.invalidations).to receive(:create).once.with(paths: files[Middleman::Cli::CloudFront::INVALIDATION_LIMIT, Middleman::Cli::CloudFront::INVALIDATION_LIMIT])
|
51
55
|
expect(distribution.invalidations).to receive(:create).once.with(paths: files[Middleman::Cli::CloudFront::INVALIDATION_LIMIT * 2, Middleman::Cli::CloudFront::INVALIDATION_LIMIT])
|
52
56
|
cloudfront.invalidate(options)
|
53
57
|
end
|
54
58
|
end
|
59
|
+
|
60
|
+
context 'when files to invalidate are explicitly specified' do
|
61
|
+
it 'uses them instead of the files in the build directory' do
|
62
|
+
files = (1..3).map { |i| "/file_#{i}" }
|
63
|
+
expect(distribution.invalidations).to receive(:create).once.with(paths: files)
|
64
|
+
cloudfront.invalidate(options, files)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't filter them" do
|
68
|
+
files = (1..3).map { |i| "/file_#{i}" }
|
69
|
+
options.filter = /filter that matches no files/
|
70
|
+
expect(distribution.invalidations).to receive(:create).once.with(paths: files)
|
71
|
+
cloudfront.invalidate(options, files)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'normalizes them' do
|
75
|
+
files = %w(file directory/index.html)
|
76
|
+
normalized_files = %w(/file /directory/index.html /directory/)
|
77
|
+
expect(distribution.invalidations).to receive(:create).once.with(paths: normalized_files)
|
78
|
+
cloudfront.invalidate(options, files)
|
79
|
+
end
|
80
|
+
end
|
55
81
|
end
|
56
82
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Korzhuev
|
@@ -9,118 +9,118 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.9'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.9'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: cucumber
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.3'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.3'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: aruba
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - ~>
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0.5'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - ~>
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0.5'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: fivemat
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - ~>
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '1.3'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - ~>
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.3'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: simplecov
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ~>
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0.8'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - ~>
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.8'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rake
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 0.9.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 0.9.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: rspec
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - ~>
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '3.0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - ~>
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '3.0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: middleman-core
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - ~>
|
116
|
+
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '3.0'
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - ~>
|
123
|
+
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '3.0'
|
126
126
|
description: Adds ability to invalidate a specific set of files in your CloudFront
|
@@ -131,8 +131,8 @@ executables: []
|
|
131
131
|
extensions: []
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
|
-
- .gitignore
|
135
|
-
- .travis.yml
|
134
|
+
- ".gitignore"
|
135
|
+
- ".travis.yml"
|
136
136
|
- Gemfile
|
137
137
|
- Guardfile
|
138
138
|
- LICENSE
|
@@ -142,7 +142,7 @@ files:
|
|
142
142
|
- lib/middleman-cloudfront.rb
|
143
143
|
- lib/middleman-cloudfront/commands.rb
|
144
144
|
- lib/middleman-cloudfront/extension.rb
|
145
|
-
- lib/middleman-cloudfront/
|
145
|
+
- lib/middleman-cloudfront/version.rb
|
146
146
|
- lib/middleman_extension.rb
|
147
147
|
- middleman-cloudfront.gemspec
|
148
148
|
- spec/lib/middleman-cloudfront/commands_spec.rb
|
@@ -156,17 +156,17 @@ require_paths:
|
|
156
156
|
- lib
|
157
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- -
|
159
|
+
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project: middleman-cloudfront
|
169
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.4.1
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Invalidate CloudFront cache after deployment to S3
|