capistrano-fastly 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/capistrano-fastly.gemspec +21 -0
- data/lib/capistrano/fastly/version.rb +5 -0
- data/lib/capistrano/fastly.rb +39 -0
- data/spec/capistrano_fastly_spec.rb +31 -0
- data/spec/fixtures/vcr_cassettes/fastly_purge_all.yml +56 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/vcr_setup.rb +6 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dave Konopka
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Capistrano::Fastly [![Build Status](https://travis-ci.org/articulate/capistrano-fastly.png?branch=master)](https://travis-ci.org/articulate/capistrano-fastly)
|
2
|
+
|
3
|
+
Capistrano tasks for interacting with [Fastly](http://www.fastly.com/), a CDN/caching service.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-fastly'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-fastly
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The only task at the moment is `purge_all` which flushes the entire cache for a single site.
|
22
|
+
|
23
|
+
Add this to your deploy.rb file with your real service id and api key:
|
24
|
+
|
25
|
+
require 'capistrano/fastly'
|
26
|
+
|
27
|
+
set :fastly_config, {
|
28
|
+
:service_id => '----',
|
29
|
+
:api_key => '----'
|
30
|
+
}
|
31
|
+
|
32
|
+
Then you'll be able to call this task directly:
|
33
|
+
|
34
|
+
cap fastly:purge_all
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/fastly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-fastly"
|
8
|
+
gem.version = Capistrano::Fastly::VERSION
|
9
|
+
gem.authors = ["Dave Konopka"]
|
10
|
+
gem.email = ["dkonopka@articulate.com"]
|
11
|
+
gem.description = %q{Capistrano extensions for Fastly CDN service.}
|
12
|
+
gem.summary = %q{Execute Fastly api calls as part of your Capistrano deploys.}
|
13
|
+
gem.homepage = "https://github.com/articulate/capistrano-fastly"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'capistrano', '>= 2.0'
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/fastly/version'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
module Fastly
|
7
|
+
def self.load_into(configuration)
|
8
|
+
configuration.load do
|
9
|
+
|
10
|
+
namespace :fastly do
|
11
|
+
desc 'Purge entire Fastly cache'
|
12
|
+
task :purge_all do
|
13
|
+
raise(Capistrano::Error, 'Fastly configuration is not set') unless fetch(:fastly_config).kind_of?(Hash)
|
14
|
+
|
15
|
+
uri = URI.parse("https://api.fastly.com")
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true
|
18
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
19
|
+
request = Net::HTTP::Post.new("/service/#{fastly_config[:service_id]}/purge_all")
|
20
|
+
request.add_field('Content-Type', 'application/json')
|
21
|
+
request.add_field('X-Fastly-Key', fastly_config[:api_key])
|
22
|
+
request.body = ""
|
23
|
+
response = http.request(request)
|
24
|
+
|
25
|
+
if response.kind_of? Net::HTTPSuccess
|
26
|
+
logger.info('Fastly cache purge all complete.')
|
27
|
+
else
|
28
|
+
logger.info("Fastly cache purge failed: #{response.body}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if Capistrano::Configuration.instance
|
38
|
+
Capistrano::Fastly.load_into(Capistrano::Configuration.instance)
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Capistrano::Fastly do
|
4
|
+
before do
|
5
|
+
@capistrano = Capistrano::Configuration.new
|
6
|
+
Capistrano::Fastly.load_into(@capistrano)
|
7
|
+
@fastly_config = {
|
8
|
+
:service_id => 'XXXXXXXXXXXXXXXXXXXXX',
|
9
|
+
:api_key => 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'purge_all' do
|
14
|
+
it 'is present' do
|
15
|
+
@capistrano.find_task('fastly:purge_all').should_not == nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'fails without Fastly configuration values' do
|
19
|
+
@capistrano.set(:fastly_config, nil)
|
20
|
+
expect { @capistrano.find_and_execute_task('fastly:purge_all') }.to raise_error(Capistrano::Error, 'Fastly configuration is not set')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'completes with Fastly configuration values' do
|
24
|
+
@capistrano.set(:fastly_config, @fastly_config)
|
25
|
+
VCR.use_cassette('fastly_purge_all') do
|
26
|
+
expect { @capistrano.find_and_execute_task('fastly:purge_all') }.to_not raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.fastly.com/service/XXXXXXXXXXXXXXXXXXXXX/purge_all
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
X-Fastly-Key:
|
17
|
+
- YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Wed, 24 Apr 2013 17:17:05 GMT
|
25
|
+
Status:
|
26
|
+
- 200 OK
|
27
|
+
X-Frame-Options:
|
28
|
+
- sameorigin
|
29
|
+
Content-Type:
|
30
|
+
- application/json;charset=utf-8
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
Content-Length:
|
34
|
+
- '15'
|
35
|
+
Accept-Ranges:
|
36
|
+
- bytes
|
37
|
+
Via:
|
38
|
+
- 1.1 varnish
|
39
|
+
Age:
|
40
|
+
- '0'
|
41
|
+
X-Served-By:
|
42
|
+
- cache-v37-ASH
|
43
|
+
X-Cache:
|
44
|
+
- MISS
|
45
|
+
X-Cache-Hits:
|
46
|
+
- '0'
|
47
|
+
Vary:
|
48
|
+
- Accept-Encoding
|
49
|
+
Cache-Control:
|
50
|
+
- max-age=0;s-maxage=0;private
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ! '{"status":"ok"}'
|
54
|
+
http_version:
|
55
|
+
recorded_at: Wed, 24 Apr 2013 17:17:05 GMT
|
56
|
+
recorded_with: VCR 2.4.0
|
data/spec/spec_helper.rb
ADDED
data/spec/vcr_setup.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-fastly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Konopka
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.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: '2.0'
|
30
|
+
description: Capistrano extensions for Fastly CDN service.
|
31
|
+
email:
|
32
|
+
- dkonopka@articulate.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- .travis.yml
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- capistrano-fastly.gemspec
|
45
|
+
- lib/capistrano/fastly.rb
|
46
|
+
- lib/capistrano/fastly/version.rb
|
47
|
+
- spec/capistrano_fastly_spec.rb
|
48
|
+
- spec/fixtures/vcr_cassettes/fastly_purge_all.yml
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
- spec/vcr_setup.rb
|
51
|
+
homepage: https://github.com/articulate/capistrano-fastly
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.23
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Execute Fastly api calls as part of your Capistrano deploys.
|
75
|
+
test_files:
|
76
|
+
- spec/capistrano_fastly_spec.rb
|
77
|
+
- spec/fixtures/vcr_cassettes/fastly_purge_all.yml
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/vcr_setup.rb
|