middleman-cdn 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +20 -9
- data/lib/middleman-cdn/cdns/cloudflare.rb +6 -6
- data/lib/middleman-cdn/cdns/cloudfront.rb +4 -4
- data/lib/middleman-cdn/cdns/fastly.rb +4 -4
- data/lib/middleman-cdn/cdns/maxcdn.rb +3 -3
- data/lib/middleman-cdn/cdns/rackspace.rb +3 -3
- data/lib/middleman-cdn/commands.rb +4 -4
- data/lib/middleman-cdn/version.rb +1 -1
- data/middleman-cdn.gemspec +1 -1
- data/spec/lib/middleman-cdn/commands_spec.rb +6 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c8c316517f0c2673b971da4bfb0c637cb09b9a4
|
4
|
+
data.tar.gz: c68675ee11af145c82dd4e64a72135baa5522d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a490b5271e455b88f523cc937c58d7a55e29fdf0f0b321d5ad5ff24fd1913898268e7bc985e7b5904cc3bb2ca327c1adf501c6b5b630c7d2df8b5e94a59fac21
|
7
|
+
data.tar.gz: aea229478874d90b8f0c3526c557daada1066b581e9cd7b8c9f99b5c16170aed949f92fdba11eb9a956cf57b092cdfaa33936072fab5d8fa83da42382ae6f31f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -14,15 +14,13 @@ on common Content Delivery Networks (CDNs).
|
|
14
14
|
* [Rackspace CloudFiles](http://www.rackspace.com/cloud/files/)
|
15
15
|
* Select files for invalidation with regex.
|
16
16
|
* Automatically invalidate after build.
|
17
|
-
* Manually trigger invalidation with a single command.
|
18
|
-
|
19
|
-
What's next?
|
20
|
-
* Invalidating files only when they've changed.
|
21
|
-
* [Open an issue](../../issues/new) if you'd like your CDN provider added.
|
17
|
+
* Manually trigger invalidation with a single command on specific files.
|
18
|
+
* Invalidating files only when they've changed [if you're using middleman-s3_sync](#invalidating-with-middleman-s3_sync).
|
22
19
|
|
23
20
|
# Usage
|
24
21
|
|
25
22
|
## Installation
|
23
|
+
|
26
24
|
Add this to your `Gemfile`:
|
27
25
|
```ruby
|
28
26
|
gem "middleman-cdn"
|
@@ -99,6 +97,9 @@ invalidate them.
|
|
99
97
|
Note: Directories containing `index.html` files are automatically included
|
100
98
|
when their respective `index.html` is included in the filter.
|
101
99
|
|
100
|
+
Alternatively: If you're using `middleman-s3_sync` you can hook middleman-cdn into
|
101
|
+
it's build process. See the [instructions here](#invalidating-with-middleman-s3_sync).
|
102
|
+
|
102
103
|
### Configuration: CloudFlare
|
103
104
|
|
104
105
|
The `cloudflare` parameter contains the information specific to your CloudFlare
|
@@ -194,7 +195,6 @@ as environment variables or provided on the commandline like this example.
|
|
194
195
|
CLOUDFLARE_CLIENT_API_KEY= CLOUDFLARE_EMAIL= bundle exec middleman invalidate
|
195
196
|
```
|
196
197
|
|
197
|
-
|
198
198
|
## Invalidating
|
199
199
|
|
200
200
|
Set `after_build` to `true` and the cache will be invalidated after build:
|
@@ -204,14 +204,25 @@ bundle exec middleman build
|
|
204
204
|
|
205
205
|
Or, invalidate manually using:
|
206
206
|
```bash
|
207
|
-
bundle exec middleman
|
207
|
+
bundle exec middleman cdn
|
208
208
|
```
|
209
209
|
|
210
|
-
Or:
|
210
|
+
Or, invalidate specific files manually:
|
211
211
|
```bash
|
212
|
-
bundle exec middleman cdn
|
212
|
+
bundle exec middleman cdn [file] [file] ...
|
213
213
|
```
|
214
214
|
|
215
|
+
## Invalidating with middleman-s3_sync
|
216
|
+
|
217
|
+
If you're using `middleman-s3_sync` you can hook middleman-cdn into it's build process, to invalidate only the files that s3_sync uploads. Add the following to your `config.rb`:
|
218
|
+
```ruby
|
219
|
+
after_s3_sync do |files_by_status|
|
220
|
+
cdn_invalidate(files_by_status[:updated])
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
224
|
+
Also, make sure to remove `cdn.after_build = true` from your config, if it was there previously, so the invalidation is not run twice.
|
225
|
+
|
215
226
|
## Example Usage
|
216
227
|
|
217
228
|
I'm using middleman-cdn on my personal website [leighmcculloch.com](http://leighmcculloch.com) which is on [github](https://github.com/leighmcculloch/leighmcculloch.com) if you want to checkout how I deploy. It's configuration has all of the above CDNs in use for demonstration. I primarily use CloudFlare, and unlike the other CDNs, CloudFlare doesn't default to caching HTML. To make the most of CloudFlare, configure a PageRule that looks like this to tell CloudFlare to cache everything.
|
@@ -25,14 +25,14 @@ module Middleman
|
|
25
25
|
|
26
26
|
[:client_api_key, :email, :zone, :base_urls].each do |key|
|
27
27
|
if options[key].blank?
|
28
|
-
say_status("Error: Configuration key cloudflare[:#{key}] is missing."
|
28
|
+
say_status(ANSI.red{ "Error: Configuration key cloudflare[:#{key}] is missing." })
|
29
29
|
raise
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
options[:base_urls] = [options[:base_urls]] if options[:base_urls].is_a?(String)
|
34
34
|
if !options[:base_urls].is_a?(Array)
|
35
|
-
say_status("Error: Configuration key cloudflare[:base_urls] must be an array and contain at least one base url."
|
35
|
+
say_status(ANSI.red{ "Error: Configuration key cloudflare[:base_urls] must be an array and contain at least one base url." })
|
36
36
|
raise
|
37
37
|
end
|
38
38
|
|
@@ -42,9 +42,9 @@ module Middleman
|
|
42
42
|
say_status("Invalidating zone #{options[:zone]}... ", newline: false)
|
43
43
|
cloudflare.fpurge_ts(options[:zone])
|
44
44
|
rescue => e
|
45
|
-
say_status(", " + "error: #{e.message}"
|
45
|
+
say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
|
46
46
|
else
|
47
|
-
say_status("✔"
|
47
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
48
48
|
end
|
49
49
|
else
|
50
50
|
options[:base_urls].each do |base_url|
|
@@ -54,9 +54,9 @@ module Middleman
|
|
54
54
|
say_status("Invalidating #{url}... ", newline: false)
|
55
55
|
cloudflare.zone_file_purge(options[:zone], "#{base_url}#{file}")
|
56
56
|
rescue => e
|
57
|
-
say_status(", " + "error: #{e.message}"
|
57
|
+
say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
|
58
58
|
else
|
59
|
-
say_status("✔"
|
59
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -24,7 +24,7 @@ module Middleman
|
|
24
24
|
options[:secret_access_key] ||= ENV['AWS_SECRET_ACCESS_KEY']
|
25
25
|
[:access_key_id, :secret_access_key, :distribution_id].each do |key|
|
26
26
|
if options[key].blank?
|
27
|
-
say_status("Error: Configuration key cloudfront[:base_urls] is missing."
|
27
|
+
say_status(ANSI.red{ "Error: Configuration key cloudfront[:base_urls] is missing." })
|
28
28
|
raise
|
29
29
|
end
|
30
30
|
end
|
@@ -41,10 +41,10 @@ module Middleman
|
|
41
41
|
say_status("Invalidating #{files.count} files... ", newline: false)
|
42
42
|
invalidation = distribution.invalidations.create(:paths => files)
|
43
43
|
if invalidation.status != 'InProgress'
|
44
|
-
say_status("Invalidation status is #{invalidation.status}. Expected 'InProgress'."
|
44
|
+
say_status(ANSI.red{ ANSI.bold + "Invalidation status is #{invalidation.status}. Expected 'InProgress'." }, header: false)
|
45
45
|
raise
|
46
46
|
end
|
47
|
-
say_status("✔"
|
47
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
48
48
|
else
|
49
49
|
slices = files.each_slice(INVALIDATION_LIMIT)
|
50
50
|
say_status("Invalidating #{files.count} files in #{slices.count} batch(es) ")
|
@@ -52,7 +52,7 @@ module Middleman
|
|
52
52
|
say_status("Invalidating batch #{i + 1}... ", newline: false)
|
53
53
|
invalidation = distribution.invalidations.create(:paths => slice)
|
54
54
|
invalidation.wait_for { ready? } unless i == slices.count - 1
|
55
|
-
say_status("✔"
|
55
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
say_status("It might take 10 to 15 minutes until all files are invalidated.")
|
@@ -22,14 +22,14 @@ module Middleman
|
|
22
22
|
|
23
23
|
[:api_key, :base_urls].each do |key|
|
24
24
|
if options[key].blank?
|
25
|
-
say_status("Error: Configuration key fastly[:#{key}] is missing."
|
25
|
+
say_status(ANSI.red{ "Error: Configuration key fastly[:#{key}] is missing." })
|
26
26
|
raise
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
options[:base_urls] = [options[:base_urls]] if options[:base_urls].is_a?(String)
|
31
31
|
if !options[:base_urls].is_a?(Array)
|
32
|
-
say_status("Error: Configuration key fastly[:base_urls] must be an array and contain at least one base url."
|
32
|
+
say_status(ANSI.red{ "Error: Configuration key fastly[:base_urls] must be an array and contain at least one base url." })
|
33
33
|
raise
|
34
34
|
end
|
35
35
|
|
@@ -44,9 +44,9 @@ module Middleman
|
|
44
44
|
say_status("Invalidating #{url}... ", newline: false)
|
45
45
|
fastly.purge("#{base_url}#{file}")
|
46
46
|
rescue => e
|
47
|
-
say_status(", " + "error: #{e.message}"
|
47
|
+
say_status(ANSI.red{ ", " + "error: #{e.message}" }, header: false)
|
48
48
|
else
|
49
|
-
say_status("✔"
|
49
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -26,7 +26,7 @@ module Middleman
|
|
26
26
|
|
27
27
|
[:alias, :consumer_key, :consumer_secret, :zone_id].each do |key|
|
28
28
|
if options[key].blank?
|
29
|
-
say_status("Error: Configuration key maxcdn[:#{key}] is missing."
|
29
|
+
say_status(ANSI.red{ "Error: Configuration key maxcdn[:#{key}] is missing." })
|
30
30
|
raise
|
31
31
|
end
|
32
32
|
end
|
@@ -37,9 +37,9 @@ module Middleman
|
|
37
37
|
say_status("Invalidating #{files.count} files...", newline: false)
|
38
38
|
maxcdn.purge(options[:zone_id], files)
|
39
39
|
rescue => e
|
40
|
-
say_status(", " + "error: #{e.message}"
|
40
|
+
say_status(ANSI.red{ ", " + "error: #{e.message}" }, header: false)
|
41
41
|
else
|
42
|
-
say_status("✔"
|
42
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -28,7 +28,7 @@ module Middleman
|
|
28
28
|
|
29
29
|
[:username, :api_key, :region, :container].each do |key|
|
30
30
|
if options[key].blank?
|
31
|
-
say_status("Error: Configuration key rackspace[:#{key}] is missing."
|
31
|
+
say_status(ANSI.red{ "Error: Configuration key rackspace[:#{key}] is missing." })
|
32
32
|
raise
|
33
33
|
end
|
34
34
|
end
|
@@ -54,9 +54,9 @@ module Middleman
|
|
54
54
|
say_status("Invalidating #{file}...", newline: false)
|
55
55
|
rackspace_client.invalidate(region, container, file, notification_email: notification_email)
|
56
56
|
rescue => e
|
57
|
-
say_status(" error: #{e.message}"
|
57
|
+
say_status(ANSI.red{ " error: #{e.message}" }, header: false)
|
58
58
|
else
|
59
|
-
say_status("✔"
|
59
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -6,7 +6,7 @@ require "middleman-cdn/cdns/cloudfront.rb"
|
|
6
6
|
require "middleman-cdn/cdns/fastly.rb"
|
7
7
|
require "middleman-cdn/cdns/maxcdn.rb"
|
8
8
|
require "middleman-cdn/cdns/rackspace.rb"
|
9
|
-
require "
|
9
|
+
require "ansi/code"
|
10
10
|
|
11
11
|
module Middleman
|
12
12
|
module Cli
|
@@ -35,7 +35,7 @@ module Middleman
|
|
35
35
|
if options.nil?
|
36
36
|
app_instance = ::Middleman::Application.server.inst
|
37
37
|
unless app_instance.respond_to?(:cdn_options)
|
38
|
-
self.class.say_status(nil, "Error: You need to activate the cdn extension in config.rb.\n#{example_configuration}"
|
38
|
+
self.class.say_status(nil, ANSI.red{ "Error: You need to activate the cdn extension in config.rb.\n#{example_configuration}" })
|
39
39
|
raise
|
40
40
|
end
|
41
41
|
options = app_instance.cdn_options
|
@@ -43,7 +43,7 @@ module Middleman
|
|
43
43
|
options.filter ||= /.*/
|
44
44
|
|
45
45
|
if cdns.all? { |cdn| options.public_send(cdn.key.to_sym).nil? }
|
46
|
-
self.class.say_status(nil, "Error: You must specify a config for one of the supported CDNs.\n#{example_configuration}"
|
46
|
+
self.class.say_status(nil, ANSI.red{ "Error: You must specify a config for one of the supported CDNs.\n#{example_configuration}" })
|
47
47
|
raise
|
48
48
|
end
|
49
49
|
|
@@ -72,7 +72,7 @@ module Middleman
|
|
72
72
|
|
73
73
|
def self.say_status(cdn, status, newline: true, header: true, wait_enter: false)
|
74
74
|
message = ""
|
75
|
-
message << "#{:cdn.to_s.rjust(12)
|
75
|
+
message << "#{ANSI.green { :cdn.to_s.rjust(12)} } #{ANSI.yellow{ cdn } unless cdn.nil? }" if header
|
76
76
|
message << " " if header && cdn
|
77
77
|
message << status if status
|
78
78
|
print message
|
data/middleman-cdn.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'cloudflare', '~> 2.0'
|
22
22
|
s.add_dependency 'fastly', '~> 1.1'
|
23
23
|
s.add_dependency 'maxcdn', '~> 0.1'
|
24
|
-
s.add_dependency '
|
24
|
+
s.add_dependency 'ansi', '~> 1.5'
|
25
25
|
s.add_dependency 'activesupport', '~> 4.1'
|
26
26
|
s.add_dependency 'httparty', '~> 0.13'
|
27
27
|
|
@@ -15,6 +15,12 @@ describe Middleman::Cli::CDN do
|
|
15
15
|
described_class.say_status(nil, "a status")
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
context "with a cdn" do
|
20
|
+
it "should say" do
|
21
|
+
described_class.say_status("the cdn", "a status")
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
describe '#cdn_invalidate' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-cdn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leigh McCulloch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: ansi
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.5'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
221
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.
|
222
|
+
rubygems_version: 2.4.3
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: Invalidate CloudFlare or CloudFront cache after deployment
|