jekyll-s3-yearofmoo 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/jekyll-s3-yearofmoo +5 -0
- data/features/jekyll-s3-cloudfront.feature +22 -0
- data/features/jekyll-s3.feature +85 -0
- data/features/support/env.rb +23 -0
- data/jekyll-s3-yearofmoo.gemspec +31 -0
- data/lib/cloudfront/invalidator.rb +14 -0
- data/lib/jekyll-s3/cli.rb +12 -0
- data/lib/jekyll-s3/errors.rb +25 -0
- data/lib/jekyll-s3/uploader.rb +172 -0
- data/lib/jekyll-s3/version.rb +5 -0
- data/lib/jekyll-s3.rb +17 -0
- data/spec/lib/invalidator_spec.rb +36 -0
- data/spec/lib/uploader_spec.rb +62 -0
- data/spec/spec_helper.rb +6 -0
- metadata +162 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# jekyll-s3
|
2
|
+
|
3
|
+
Deploy your jekyll site to S3.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install jekyll-s3
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
* Go to your jekyll site directory
|
12
|
+
* Run `jekyll-s3`. It generates a configuration file called `_jekyll_s3.yml` that looks like that:
|
13
|
+
<pre>
|
14
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
15
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
16
|
+
s3_bucket: your.blog.bucket.com
|
17
|
+
cloudfront_distribution_id: YOUR_CLOUDFRONT_DIST_ID (OPTIONAL)
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
* Edit it with your details.
|
21
|
+
|
22
|
+
## Deploy!
|
23
|
+
|
24
|
+
* Run `jekyll-s3`. Done.
|
25
|
+
|
26
|
+
## Want the root url to render index.html?
|
27
|
+
|
28
|
+
* Log into <https://console.aws.amazon.com/s3/home>
|
29
|
+
* Set the Index document to index.html in Bucket Properties >
|
30
|
+
Website.
|
31
|
+
* Visit the website endpoint:
|
32
|
+
(http://yourblog.s3-website...amazonaws.com)
|
33
|
+
|
34
|
+
## How to use Cloudfront to deliver your blog
|
35
|
+
|
36
|
+
It is easy to deliver your S3-based web site via Cloudfront, the CDN of Amazon.
|
37
|
+
|
38
|
+
* Go to <https://console.aws.amazon.com/cloudfront/home>
|
39
|
+
* Create a distribution and set the your Jekyll S3 bucket as the origin
|
40
|
+
* Add the `cloudfront_distribution_id: your-dist-id` setting into
|
41
|
+
`_jekyll_s3.yml`
|
42
|
+
* Run `jekyll-s3` to deploy your site to S3 and invalidate the Cloudfront
|
43
|
+
distribution
|
44
|
+
|
45
|
+
## Todo
|
46
|
+
|
47
|
+
* Upload new / updated files *only* (using s3-sync?)
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
* Install bundler and run `bundle install`
|
52
|
+
* Run the integration tests by running `bundle exec cucumber`
|
53
|
+
* Run the unit tests by running `bundle exec rspec spec/lib/*.rb`
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
MIT
|
58
|
+
|
59
|
+
## Copyright
|
60
|
+
|
61
|
+
Copyright (c) 2011 VersaPay, Philippe Creux.
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: Invalidate the Cloudfront distribution
|
2
|
+
|
3
|
+
In order to publish my posts
|
4
|
+
As a blogger who delivers his blog via an S3-based Cloudfront distribution
|
5
|
+
I want to run jekyll-s3
|
6
|
+
And see, that the items in the distribution were invalidated
|
7
|
+
So that my latest updates will be immediately available to readers
|
8
|
+
|
9
|
+
Scenario: Run jekyll-s3 for the first time
|
10
|
+
Given a directory named "_site"
|
11
|
+
When I run `jekyll-s3`
|
12
|
+
Then the output should contain:
|
13
|
+
"""
|
14
|
+
I've just generated a file called _jekyll_s3.yml. Go put your details in it!
|
15
|
+
"""
|
16
|
+
Then the file "_jekyll_s3.yml" should contain:
|
17
|
+
"""
|
18
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
19
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
20
|
+
s3_bucket: your.blog.bucket.com
|
21
|
+
cloudfront_distribution_id: YOUR_CLOUDFRONT_DIST_ID (OPTIONAL)
|
22
|
+
"""
|
@@ -0,0 +1,85 @@
|
|
1
|
+
Feature: jekyll-s3
|
2
|
+
|
3
|
+
In order to push my jekyll site to s3
|
4
|
+
As a blogger
|
5
|
+
I want to run jekyll-s3 and say OMG it just worked!
|
6
|
+
|
7
|
+
Scenario: Run jekyll-s3 in the wrong directory
|
8
|
+
When I run `jekyll-s3`
|
9
|
+
Then the output should contain:
|
10
|
+
"""
|
11
|
+
I can't find any directory called _site. Are you in the right directory?
|
12
|
+
"""
|
13
|
+
|
14
|
+
Scenario: Run jekyll-s3 for the first time
|
15
|
+
Given a directory named "_site"
|
16
|
+
When I run `jekyll-s3`
|
17
|
+
Then the output should contain:
|
18
|
+
"""
|
19
|
+
I've just generated a file called _jekyll_s3.yml. Go put your details in it!
|
20
|
+
"""
|
21
|
+
Then the file "_jekyll_s3.yml" should contain:
|
22
|
+
"""
|
23
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
24
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
25
|
+
s3_bucket: your.blog.bucket.com
|
26
|
+
"""
|
27
|
+
|
28
|
+
Scenario: Run jekyll-s3 with an empty configuration file
|
29
|
+
Given a directory named "_site"
|
30
|
+
And an empty file named "_jekyll_s3.yml"
|
31
|
+
When I run `jekyll-s3`
|
32
|
+
Then the output should contain:
|
33
|
+
"""
|
34
|
+
I can't parse the file _jekyll_s3.yml. It should look like this:
|
35
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
36
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
37
|
+
s3_bucket: your.blog.bucket.com
|
38
|
+
"""
|
39
|
+
|
40
|
+
Scenario: Run jekyll-s3 with a malformed configuration file
|
41
|
+
Given a directory named "_site"
|
42
|
+
And a file named "_jekyll_s3.yml" with:
|
43
|
+
"""
|
44
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
45
|
+
this is not yaml
|
46
|
+
"""
|
47
|
+
When I run `jekyll-s3`
|
48
|
+
Then the output should contain:
|
49
|
+
"""
|
50
|
+
I can't parse the file _jekyll_s3.yml. It should look like this:
|
51
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
52
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
53
|
+
s3_bucket: your.blog.bucket.com
|
54
|
+
"""
|
55
|
+
|
56
|
+
Scenario: Run jekyll-s3 with a configuration file that does not contain a bucket
|
57
|
+
Given a directory named "_site"
|
58
|
+
And a file named "_jekyll_s3.yml" with:
|
59
|
+
"""
|
60
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
61
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
62
|
+
s3_bucket:
|
63
|
+
"""
|
64
|
+
When I run `jekyll-s3`
|
65
|
+
Then the output should contain:
|
66
|
+
"""
|
67
|
+
I can't parse the file _jekyll_s3.yml. It should look like this:
|
68
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
69
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
70
|
+
s3_bucket: your.blog.bucket.com
|
71
|
+
"""
|
72
|
+
|
73
|
+
Scenario: Run jekyll-s3
|
74
|
+
Given a directory named "_site"
|
75
|
+
And a file named "_jekyll_s3.yml" with:
|
76
|
+
"""
|
77
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
78
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
79
|
+
s3_bucket: your.blog.bucket.com
|
80
|
+
"""
|
81
|
+
When I run `jekyll-s3`
|
82
|
+
Then the output should contain:
|
83
|
+
"""
|
84
|
+
Deploying _site/* to your.blog.bucket.com
|
85
|
+
"""
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
require 'aruba/cucumber'
|
7
|
+
require 'cucumber/rspec/doubles'
|
8
|
+
|
9
|
+
# Following from 'aruba/cucumber'
|
10
|
+
Before do
|
11
|
+
@__aruba_original_paths = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
|
12
|
+
ENV['PATH'] = ([File.expand_path('bin')] + @__aruba_original_paths).join(File::PATH_SEPARATOR)
|
13
|
+
end
|
14
|
+
|
15
|
+
After do
|
16
|
+
ENV['PATH'] = @__aruba_original_paths.join(File::PATH_SEPARATOR)
|
17
|
+
end
|
18
|
+
# End of following from 'aruba/cucumber'
|
19
|
+
|
20
|
+
Then /^the file "([^"]*)" should contain:$/ do |file, exact_content|
|
21
|
+
check_file_content(file, exact_content, true)
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jekyll-s3/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jekyll-s3-yearofmoo"
|
7
|
+
s.version = Jekyll::S3::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Philippe Creux"]
|
10
|
+
s.email = ["pcreux@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/versapay/jekyll-s3"
|
12
|
+
s.summary = %q{Push your Jekyll blog to S3}
|
13
|
+
s.description = %q{This Gem allows you to push your Jekyll blog to AWS S3.
|
14
|
+
In addition, you can use this Gem to invalidate the related Cloudfront
|
15
|
+
distribution, making it easy to deliver your blog via the CDN.}
|
16
|
+
|
17
|
+
s.default_executable = %q{jekyll-s3-yearofmoo}
|
18
|
+
|
19
|
+
s.add_dependency 'aws-s3'
|
20
|
+
s.add_dependency 'cf-s3-invalidator'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'mocha'
|
24
|
+
s.add_development_dependency 'cucumber'
|
25
|
+
s.add_development_dependency 'aruba', '>= 0.4.7'
|
26
|
+
|
27
|
+
s.files = `git ls-files`.split("\n")
|
28
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Cloudfront
|
3
|
+
class Invalidator
|
4
|
+
def self.invalidate(
|
5
|
+
aws_key, aws_secret, s3_bucket_name, cloudfront_distribution_id)
|
6
|
+
bucket = AWS::S3::Bucket.find(s3_bucket_name)
|
7
|
+
s3_object_keys = bucket.objects.map { |f| f.key }
|
8
|
+
CloudfrontS3Invalidator::CloudfrontClient.new(
|
9
|
+
aws_key, aws_secret, cloudfront_distribution_id).invalidate(
|
10
|
+
s3_object_keys)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module S3
|
3
|
+
class JekyllS3Error < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class NotAJekyllProjectError < JekyllS3Error
|
7
|
+
def initialize(message = "I can't find any directory called _site. Are you in the right directory?")
|
8
|
+
super(message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class NoConfigurationFileError < JekyllS3Error
|
13
|
+
def initialize(message = "I've just generated a file called _jekyll_s3.yml. Go put your details in it!")
|
14
|
+
super(message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class MalformedConfigurationFileError < JekyllS3Error
|
19
|
+
def initialize(message = "I can't parse the file _jekyll_s3.yml. It should look like this:\n#{Uploader::CONFIGURATION_FILE_TEMPLATE}")
|
20
|
+
super(message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module S3
|
3
|
+
class Uploader
|
4
|
+
|
5
|
+
SITE_DIR = "_site"
|
6
|
+
CONFIGURATION_FILE = '_jekyll_s3.yml'
|
7
|
+
CONFIGURATION_FILE_TEMPLATE = <<-EOF
|
8
|
+
s3_id: YOUR_AWS_S3_ACCESS_KEY_ID
|
9
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
10
|
+
s3_bucket: your.blog.bucket.com
|
11
|
+
cloudfront_distribution_id: YOUR_CLOUDFRONT_DIST_ID (OPTIONAL)
|
12
|
+
EOF
|
13
|
+
|
14
|
+
def self.run!
|
15
|
+
new.run!
|
16
|
+
end
|
17
|
+
|
18
|
+
def run!
|
19
|
+
check_jekyll_project!
|
20
|
+
check_s3_configuration!
|
21
|
+
load_configuration
|
22
|
+
upload_to_s3!
|
23
|
+
invalidate_cf_dist_if_configured!
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def invalidate_cf_dist_if_configured!
|
29
|
+
cloudfront_configured = @cloudfront_distribution_id != nil && @cloudfront_distribution_id != ''
|
30
|
+
Jekyll::Cloudfront::Invalidator.invalidate(
|
31
|
+
@s3_id, @s3_secret, @s3_bucket, @cloudfront_distribution_id
|
32
|
+
) if cloudfront_configured
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_with_retry
|
36
|
+
begin
|
37
|
+
yield
|
38
|
+
rescue AWS::S3::RequestTimeout => e
|
39
|
+
$stderr.puts "Exception Occurred: #{e.message} (#{e.class}) Retrying in 5 seconds..."
|
40
|
+
sleep 5
|
41
|
+
retry
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def local_files
|
46
|
+
dir = @production_directory || SITE_DIR
|
47
|
+
paths = []
|
48
|
+
|
49
|
+
files = Dir[dir + '/**/*']
|
50
|
+
files = files.delete_if { |f|
|
51
|
+
File.directory?(f)
|
52
|
+
}.map { |f|
|
53
|
+
f.gsub(dir + '/', '')
|
54
|
+
}
|
55
|
+
|
56
|
+
if @config['exclude_files']
|
57
|
+
patterns = @config['exclude_files']
|
58
|
+
files.each do |file|
|
59
|
+
found = true
|
60
|
+
patterns.each do |pattern|
|
61
|
+
found = false if file =~ pattern
|
62
|
+
end
|
63
|
+
paths.push(file) if found
|
64
|
+
end
|
65
|
+
else
|
66
|
+
paths = files
|
67
|
+
end
|
68
|
+
|
69
|
+
raise paths.to_yaml
|
70
|
+
|
71
|
+
paths
|
72
|
+
end
|
73
|
+
|
74
|
+
def customize_file_details(file)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
# Please spec me!
|
79
|
+
def upload_to_s3!
|
80
|
+
puts "Deploying _site/* to #{@s3_bucket}"
|
81
|
+
|
82
|
+
AWS::S3::Base.establish_connection!(
|
83
|
+
:access_key_id => @s3_id,
|
84
|
+
:secret_access_key => @s3_secret,
|
85
|
+
:use_ssl => true
|
86
|
+
)
|
87
|
+
unless AWS::S3::Service.buckets.map(&:name).include?(@s3_bucket)
|
88
|
+
puts("Creating bucket #{@s3_bucket}")
|
89
|
+
AWS::S3::Bucket.create(@s3_bucket)
|
90
|
+
end
|
91
|
+
|
92
|
+
bucket = AWS::S3::Bucket.find(@s3_bucket)
|
93
|
+
|
94
|
+
remote_files = bucket.objects.map { |f| f.key }
|
95
|
+
|
96
|
+
to_upload = local_files
|
97
|
+
to_upload.each do |f|
|
98
|
+
run_with_retry do
|
99
|
+
if AWS::S3::S3Object.store(f, open("#{SITE_DIR}/#{f}"), @s3_bucket, :access => 'public-read')
|
100
|
+
puts("Upload #{f}: Success!")
|
101
|
+
else
|
102
|
+
puts("Upload #{f}: FAILURE!")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
to_delete = remote_files - local_files
|
108
|
+
|
109
|
+
delete_all = false
|
110
|
+
keep_all = false
|
111
|
+
to_delete.each do |f|
|
112
|
+
delete = false
|
113
|
+
keep = false
|
114
|
+
until delete || delete_all || keep || keep_all
|
115
|
+
puts "#{f} is on S3 but not in your _site directory anymore. Do you want to [d]elete, [D]elete all, [k]eep, [K]eep all?"
|
116
|
+
case STDIN.gets.chomp
|
117
|
+
when 'd' then delete = true
|
118
|
+
when 'D' then delete_all = true
|
119
|
+
when 'k' then keep = true
|
120
|
+
when 'K' then keep_all = true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
if (delete_all || delete) && !(keep_all || keep)
|
124
|
+
run_with_retry do
|
125
|
+
if AWS::S3::S3Object.delete(f, @s3_bucket)
|
126
|
+
puts("Delete #{f}: Success!")
|
127
|
+
else
|
128
|
+
puts("Delete #{f}: FAILURE!")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
puts "Done! Go visit: http://#{@s3_bucket}.s3.amazonaws.com/index.html"
|
135
|
+
true
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_jekyll_project!
|
139
|
+
raise NotAJekyllProjectError unless File.directory?(SITE_DIR)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Raise NoConfigurationFileError if the configuration file does not exists
|
143
|
+
def check_s3_configuration!
|
144
|
+
unless File.exists?(CONFIGURATION_FILE)
|
145
|
+
create_template_configuration_file
|
146
|
+
raise NoConfigurationFileError
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Load configuration from _jekyll_s3.yml
|
151
|
+
# Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect
|
152
|
+
def load_configuration
|
153
|
+
@config = YAML.load_file(CONFIGURATION_FILE) rescue nil
|
154
|
+
raise MalformedConfigurationFileError unless @config
|
155
|
+
|
156
|
+
@s3_id = @config['s3_id']
|
157
|
+
@s3_secret = @config['s3_secret']
|
158
|
+
@s3_bucket = @config['s3_bucket']
|
159
|
+
@cloudfront_distribution_id = @config['cloudfront_distribution_id']
|
160
|
+
@production_directory = @config['production_directory']
|
161
|
+
|
162
|
+
raise MalformedConfigurationFileError unless
|
163
|
+
[@s3_id, @s3_secret, @s3_bucket].select { |k| k.nil? || k == '' }.empty?
|
164
|
+
end
|
165
|
+
|
166
|
+
def create_template_configuration_file
|
167
|
+
File.open(CONFIGURATION_FILE, 'w') { |f| f.write(CONFIGURATION_FILE_TEMPLATE) }
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
data/lib/jekyll-s3.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'aws/s3'
|
4
|
+
require 'cf-s3-invalidator'
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module S3
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
%w{errors uploader cli}.each do |file|
|
12
|
+
require File.dirname(__FILE__) + "/jekyll-s3/#{file}"
|
13
|
+
end
|
14
|
+
|
15
|
+
%w{invalidator}.each do |file|
|
16
|
+
require File.dirname(__FILE__) + "/cloudfront/#{file}"
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jekyll::Cloudfront::Invalidator do
|
4
|
+
describe "#invalidate cloudfront items" do
|
5
|
+
it "should retrieve all objects from the S3 bucket and call invalidation on them" do
|
6
|
+
s3_object_keys = ["key1", "key2"]
|
7
|
+
s3_objects = s3_object_keys.map { |key| S3Object.new(key) }
|
8
|
+
@s3_bucket_name = "my-s3-bucket"
|
9
|
+
AWS::S3::Bucket.expects(:find).with(@s3_bucket_name).returns(S3Bucket.new(s3_objects))
|
10
|
+
CloudfrontS3Invalidator::CloudfrontClient.any_instance.
|
11
|
+
expects(:invalidate).with(s3_object_keys)
|
12
|
+
|
13
|
+
Jekyll::Cloudfront::Invalidator.invalidate("", "", @s3_bucket_name, "")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class S3Bucket
|
19
|
+
def initialize(s3_objects)
|
20
|
+
@s3_objects = s3_objects
|
21
|
+
end
|
22
|
+
|
23
|
+
def objects
|
24
|
+
@s3_objects
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class S3Object
|
29
|
+
def initialize(key)
|
30
|
+
@key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
def key
|
34
|
+
@key
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jekyll::S3::Uploader do
|
4
|
+
describe "#upload_to_s3" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
AWS::S3::Base.expects(:establish_connection!).at_least(1).returns true
|
8
|
+
AWS::S3::Service.expects(:buckets).at_least(1).returns []
|
9
|
+
AWS::S3::Bucket.expects(:create).at_least(1).returns true
|
10
|
+
bucket = mock()
|
11
|
+
bucket.expects(:objects).returns []
|
12
|
+
AWS::S3::Bucket.expects(:find).at_least(1).returns bucket
|
13
|
+
|
14
|
+
@uploader = Jekyll::S3::Uploader.new
|
15
|
+
@uploader.expects(:local_files).at_least(1).returns ['index.html']
|
16
|
+
@uploader.expects(:open).at_least(1).returns true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should work right when there are no exceptions" do
|
20
|
+
AWS::S3::S3Object.expects(:store).at_least(1).returns(true)
|
21
|
+
@uploader.send(:upload_to_s3!).should
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should properly handle exceptions on uploading to S3" do
|
25
|
+
AWS::S3::S3Object.expects(:store).raises(AWS::S3::RequestTimeout.new('timeout', 'timeout')).then.at_least(1).returns(true)
|
26
|
+
@uploader.send(:upload_to_s3!).should
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#call_cloudfront_invalidation" do
|
31
|
+
it "should invalidate Cloudfront items if the configuration 'cloudfront_dist_id' exists" do
|
32
|
+
configure_uploader({
|
33
|
+
"s3_id" => "xx",
|
34
|
+
"s3_secret" => "zz",
|
35
|
+
"s3_bucket" => "bucket",
|
36
|
+
"cloudfront_distribution_id" => "dist id"
|
37
|
+
})
|
38
|
+
Jekyll::Cloudfront::Invalidator.expects(:invalidate).with("xx", "zz", "bucket", "dist id")
|
39
|
+
Jekyll::S3::Uploader.run!
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should skip calling Cloudfront if the configuration 'cloudfront_dist_id' is missing" do
|
43
|
+
configure_uploader({
|
44
|
+
"s3_id" => "xx",
|
45
|
+
"s3_secret" => "zz",
|
46
|
+
"s3_bucket" => "bucket"
|
47
|
+
})
|
48
|
+
Jekyll::Cloudfront::Invalidator.expects(:invalidate).never
|
49
|
+
Jekyll::S3::Uploader.run!
|
50
|
+
end
|
51
|
+
|
52
|
+
def configure_uploader(config)
|
53
|
+
def disable_methods_that_interact_with_world
|
54
|
+
Jekyll::S3::Uploader.any_instance.expects(:upload_to_s3!).returns nil
|
55
|
+
Jekyll::S3::Uploader.any_instance.expects(:check_jekyll_project!).returns nil
|
56
|
+
Jekyll::S3::Uploader.any_instance.expects(:check_s3_configuration!).returns nil
|
57
|
+
end
|
58
|
+
YAML.expects(:load_file).with('_jekyll_s3.yml').returns(config)
|
59
|
+
disable_methods_that_interact_with_world
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-s3-yearofmoo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Philippe Creux
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-08-26 00:00:00 -04:00
|
18
|
+
default_executable: jekyll-s3-yearofmoo
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: aws-s3
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: cf-s3-invalidator
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rspec
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: cucumber
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id005
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: aruba
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
- 4
|
90
|
+
- 7
|
91
|
+
version: 0.4.7
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id006
|
94
|
+
description: |-
|
95
|
+
This Gem allows you to push your Jekyll blog to AWS S3.
|
96
|
+
In addition, you can use this Gem to invalidate the related Cloudfront
|
97
|
+
distribution, making it easy to deliver your blog via the CDN.
|
98
|
+
email:
|
99
|
+
- pcreux@gmail.com
|
100
|
+
executables:
|
101
|
+
- jekyll-s3-yearofmoo
|
102
|
+
extensions: []
|
103
|
+
|
104
|
+
extra_rdoc_files: []
|
105
|
+
|
106
|
+
files:
|
107
|
+
- .DS_Store
|
108
|
+
- .gitignore
|
109
|
+
- Gemfile
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/jekyll-s3-yearofmoo
|
113
|
+
- features/jekyll-s3-cloudfront.feature
|
114
|
+
- features/jekyll-s3.feature
|
115
|
+
- features/support/env.rb
|
116
|
+
- jekyll-s3-yearofmoo.gemspec
|
117
|
+
- lib/cloudfront/invalidator.rb
|
118
|
+
- lib/jekyll-s3.rb
|
119
|
+
- lib/jekyll-s3/cli.rb
|
120
|
+
- lib/jekyll-s3/errors.rb
|
121
|
+
- lib/jekyll-s3/uploader.rb
|
122
|
+
- lib/jekyll-s3/version.rb
|
123
|
+
- spec/lib/invalidator_spec.rb
|
124
|
+
- spec/lib/uploader_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: https://github.com/versapay/jekyll-s3
|
128
|
+
licenses: []
|
129
|
+
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.3.6
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: Push your Jekyll blog to S3
|
156
|
+
test_files:
|
157
|
+
- features/jekyll-s3-cloudfront.feature
|
158
|
+
- features/jekyll-s3.feature
|
159
|
+
- features/support/env.rb
|
160
|
+
- spec/lib/invalidator_spec.rb
|
161
|
+
- spec/lib/uploader_spec.rb
|
162
|
+
- spec/spec_helper.rb
|