middleman-cloudfront 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ coverage
3
+ .ruby-version
4
+ *.sublime-*
5
+ *.gem
6
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Andrey Korzhuev <andrew@korzhuev.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Middleman CloudFront
2
+ A deploying tool for middleman which allows you to interact with Amazon CloudFront.
3
+ Some of its features are:
4
+
5
+ * CloudFront cache invalidation;
6
+ * Ability to call it from command line and after middleman build;
7
+
8
+ # Usage
9
+
10
+ ## Installation
11
+ Add this to `Gemfile`:
12
+ ```ruby
13
+ gem "middleman-cloudfront"
14
+ ```
15
+
16
+ Then run:
17
+ ```
18
+ bundle install
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ Edit `config.rb` and add:
24
+ ```ruby
25
+ activate :cloudfront do |cf|
26
+ cf.access_key_id = 'I'
27
+ cf.secret_access_key = 'love'
28
+ cf.distribution_id = 'cats'
29
+ # cf.after_build = false
30
+ end
31
+ ```
32
+
33
+ ## Running
34
+
35
+ If you set `after_build` to `true` cache would be automatically invalidated after build:
36
+ ```bash
37
+ bundle exec middleman build
38
+ ```
39
+
40
+ Otherwise you should run it through commandline interface like so:
41
+ ```bash
42
+ bundle exec middleman invalidate
43
+ ```
44
+
45
+ # Notes
46
+ Inspired by [middleman-deploy](https://github.com/tvaughan/middleman-deploy) and [middleman-aws-deploy](https://github.com/coderoshi/middleman-aws-deploy).
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task :test => ["cucumber"]
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
+ task :default => :test
@@ -0,0 +1,6 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
4
+ require "middleman-core"
5
+ require "middleman-core/step_definitions"
6
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-cloudfront')
@@ -0,0 +1,69 @@
1
+ require "middleman-core/cli"
2
+ require "middleman-cloudfront/extension"
3
+ require "fog"
4
+
5
+ module Middleman
6
+ module Cli
7
+
8
+ class CloudFront < Thor
9
+ include Thor::Actions
10
+
11
+ check_unknown_options!
12
+
13
+ namespace :invalidate
14
+
15
+ def self.exit_on_failure?
16
+ true
17
+ end
18
+
19
+ desc "cloudfront:invalidate", "A way to deal with your ClodFront distributions"
20
+ def invalidate
21
+ puts "## Invalidating files on CloudFront"
22
+ cdn = Fog::CDN.new({
23
+ :provider => 'AWS',
24
+ :aws_access_key_id => options.access_key_id,
25
+ :aws_secret_access_key => options.secret_access_key
26
+ })
27
+
28
+ distribution = cdn.distributions.get options.distribution_id
29
+
30
+ # CloudFront limits amount of files which can be invalidated by one request
31
+ list_files.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? }
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def options
41
+ ::Middleman::Application.server.inst.options
42
+ rescue
43
+ raise Error, <<-EOF.lines.map(&:strip).join("\n")
44
+ ERROR: You need to activate the cloudfront extension in config.rb.
45
+
46
+ The example configuration is:
47
+ activate :cloudfront do |cf|
48
+ cf.access_key_id = 'I'
49
+ cf.secret_access_key = 'love'
50
+ cf.distribution_id = 'cats'
51
+ cf.after_build = true # default is false
52
+ end
53
+ EOF
54
+ end
55
+
56
+ def list_files
57
+ Dir.chdir('build/') do
58
+ files = Dir.glob('**/*', File::FNM_DOTMATCH).reject { |f| File.directory? f }
59
+ # if :directory_indexes is active, we must invalidate both files and dirs
60
+ files += files.map{|f| f.gsub(/\/index\.html$/, '/') }
61
+ files.uniq!.map! { |f| f.start_with?('/') ? f : "/#{f}" }
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ Base.map({"inv" => "cloudfront:invalidate"})
68
+ end
69
+ end
@@ -0,0 +1,35 @@
1
+ require 'middleman-core'
2
+
3
+ module Middleman
4
+ module CloudFront
5
+ class Options < Struct.new(:access_key_id, :secret_access_key, :distribution_id, :after_build); end
6
+
7
+ class << self
8
+ def options
9
+ @@options
10
+ end
11
+
12
+ def registered(app, options_hash = {}, &block)
13
+ options = Options.new options_hash
14
+ yield options if block_given?
15
+
16
+ options.after_build ||= false
17
+
18
+ app.after_build do
19
+ ::Middleman::Cli::CloudFront.new.invalidate if options.after_build
20
+ end
21
+
22
+ @@options = options
23
+ app.send :include, Helpers
24
+ end
25
+ alias :included :registered
26
+ end
27
+
28
+ module Helpers
29
+ def options
30
+ ::Middleman::CloudFront.options
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ module Middleman
2
+ module CloudFront
3
+ PACKAGE = 'middleman-cloudfront'
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'middleman-core'
2
+ require 'middleman-cloudfront/commands'
3
+
4
+ ::Middleman::Extensions.register(:cloudfront, ">= 3.0.0") do
5
+ require "middleman-cloudfront/extension"
6
+ ::Middleman::CloudFront
7
+ end
@@ -0,0 +1 @@
1
+ require 'middleman-cloudfront'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "middleman-cloudfront/pkg-info"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = Middleman::CloudFront::PACKAGE
7
+ s.version = Middleman::CloudFront::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Andrey Korzhuev"]
10
+ s.email = ["andrew@korzhuev.com"]
11
+ s.homepage = "https://github.com/andrusha/middleman-cloudfront"
12
+ s.summary = %q{Invalidate CloudFront cache after deployment to S3}
13
+ s.description = %q{Adds ability to invalidate a specific set of files in your CloudFront cache}
14
+
15
+ s.rubyforge_project = "middleman-cloudfront"
16
+
17
+ s.files = `git ls-files -z`.split("\0")
18
+ s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency("middleman-core", ["~> 3.0.0"])
22
+ s.add_dependency("fog", ["~> 1.9.0"])
23
+
24
+ s.add_development_dependency("cucumber")
25
+ s.add_development_dependency("aruba")
26
+ s.add_development_dependency("fivemat")
27
+ s.add_development_dependency("simplecov")
28
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-cloudfront
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Korzhuev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: middleman-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.9.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: cucumber
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: aruba
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: fivemat
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Adds ability to invalidate a specific set of files in your CloudFront
111
+ cache
112
+ email:
113
+ - andrew@korzhuev.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - features/support/env.rb
124
+ - lib/middleman-cloudfront.rb
125
+ - lib/middleman-cloudfront/commands.rb
126
+ - lib/middleman-cloudfront/extension.rb
127
+ - lib/middleman-cloudfront/pkg-info.rb
128
+ - lib/middleman_extension.rb
129
+ - middleman-cloudfront.gemspec
130
+ homepage: https://github.com/andrusha/middleman-cloudfront
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project: middleman-cloudfront
150
+ rubygems_version: 1.8.23
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Invalidate CloudFront cache after deployment to S3
154
+ test_files:
155
+ - features/support/env.rb