jekyll-s3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/bin/jekyll-s3 +5 -0
- data/features/jekyll-s3.feature +87 -0
- data/features/support/env.rb +22 -0
- data/jekyll-s3.gemspec +25 -0
- data/lib/jekyll-s3.rb +12 -0
- data/lib/jekyll-s3/cli.rb +12 -0
- data/lib/jekyll-s3/errors.rb +25 -0
- data/lib/jekyll-s3/uploader.rb +102 -0
- data/lib/jekyll-s3/version.rb +5 -0
- metadata +135 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/jekyll-s3
ADDED
@@ -0,0 +1,87 @@
|
|
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
|
+
Uploading _site/* to your.blog.bucket.com
|
85
|
+
"""
|
86
|
+
|
87
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
require 'aruba/cucumber'
|
7
|
+
|
8
|
+
# Following from 'aruba/cucumber'
|
9
|
+
Before do
|
10
|
+
@__aruba_original_paths = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
|
11
|
+
ENV['PATH'] = ([File.expand_path('bin')] + @__aruba_original_paths).join(File::PATH_SEPARATOR)
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
ENV['PATH'] = @__aruba_original_paths.join(File::PATH_SEPARATOR)
|
16
|
+
end
|
17
|
+
# End of following from 'aruba/cucumber'
|
18
|
+
|
19
|
+
Then /^the file "([^"]*)" should contain:$/ do |file, exact_content|
|
20
|
+
check_file_content(file, exact_content, true)
|
21
|
+
end
|
22
|
+
|
data/jekyll-s3.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
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"
|
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 = ""
|
12
|
+
s.summary = %q{Push your jekyll blog to S3"}
|
13
|
+
s.description = %q{Push your jekyll blog to AWS S3}
|
14
|
+
|
15
|
+
s.add_dependency 'aws-s3'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'cucumber'
|
19
|
+
s.add_development_dependency 'aruba'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/lib/jekyll-s3.rb
ADDED
@@ -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,102 @@
|
|
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
|
+
EOF
|
12
|
+
|
13
|
+
|
14
|
+
def self.run!
|
15
|
+
new.run!
|
16
|
+
end
|
17
|
+
|
18
|
+
def run!
|
19
|
+
check_jekyll_project!
|
20
|
+
check_s3_configuration!
|
21
|
+
upload_to_s3!
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
include AWS::S3
|
27
|
+
|
28
|
+
def upload_to_s3!
|
29
|
+
puts "Uploading _site/* to #{@s3_bucket}"
|
30
|
+
|
31
|
+
AWS::S3::Base.establish_connection!(
|
32
|
+
:access_key_id => @s3_id,
|
33
|
+
:secret_access_key => @s3_secret,
|
34
|
+
:use_ssl => true
|
35
|
+
)
|
36
|
+
unless Service.buckets.map(&:name).include?(@s3_bucket)
|
37
|
+
puts("Creating bucket #{@s3_bucket}")
|
38
|
+
Bucket.create(@s3_bucket)
|
39
|
+
end
|
40
|
+
|
41
|
+
bucket = Bucket.find(@s3_bucket)
|
42
|
+
|
43
|
+
local_files = Dir[SITE_DIR + '/**/*'].
|
44
|
+
delete_if { |f| File.directory?(f) }.
|
45
|
+
map { |f| f.gsub(SITE_DIR + '/', '') }
|
46
|
+
|
47
|
+
remote_files = bucket.objects.map { |f| f.key }
|
48
|
+
|
49
|
+
to_upload = local_files
|
50
|
+
to_upload.each do |f|
|
51
|
+
if S3Object.store(f, open("#{SITE_DIR}/#{f}"), @s3_bucket, :access => 'public-read')
|
52
|
+
puts("Upload #{f}: Success!")
|
53
|
+
else
|
54
|
+
puts("Upload #{f}: FAILURE!")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
to_delete = remote_files - local_files
|
59
|
+
to_delete.each do |f|
|
60
|
+
if S3Object.delete(f, @s3_bucket)
|
61
|
+
puts("Delete #{f}: Success!")
|
62
|
+
else
|
63
|
+
puts("Delete #{f}: FAILURE!")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_jekyll_project!
|
69
|
+
raise NotAJekyllProjectError unless File.directory?(SITE_DIR)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Raise NoConfigurationFileError if the configuration file does not exists
|
73
|
+
# Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect
|
74
|
+
# Loads the configuration if everything looks cool
|
75
|
+
def check_s3_configuration!
|
76
|
+
unless File.exists?(CONFIGURATION_FILE)
|
77
|
+
create_template_configuration_file
|
78
|
+
raise NoConfigurationFileError
|
79
|
+
end
|
80
|
+
raise MalformedConfigurationFileError unless load_configuration
|
81
|
+
end
|
82
|
+
|
83
|
+
# Load configuration from _jekyll_s3.yml
|
84
|
+
# Return true if all values are set and not emtpy
|
85
|
+
def load_configuration
|
86
|
+
config = YAML.load_file(CONFIGURATION_FILE) rescue nil
|
87
|
+
return false unless config
|
88
|
+
|
89
|
+
@s3_id = config['s3_id']
|
90
|
+
@s3_secret = config['s3_secret']
|
91
|
+
@s3_bucket = config['s3_bucket']
|
92
|
+
|
93
|
+
[@s3_id, @s3_secret, @s3_bucket].select { |k| k.nil? || k == '' }.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_template_configuration_file
|
97
|
+
File.open(CONFIGURATION_FILE, 'w') { |f| f.write(CONFIGURATION_FILE_TEMPLATE) }
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Philippe Creux
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-01 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: aws-s3
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: cucumber
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: aruba
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: Push your jekyll blog to AWS S3
|
78
|
+
email:
|
79
|
+
- pcreux@gmail.com
|
80
|
+
executables:
|
81
|
+
- jekyll-s3
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files: []
|
85
|
+
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- Rakefile
|
90
|
+
- bin/jekyll-s3
|
91
|
+
- features/jekyll-s3.feature
|
92
|
+
- features/support/env.rb
|
93
|
+
- jekyll-s3.gemspec
|
94
|
+
- lib/jekyll-s3.rb
|
95
|
+
- lib/jekyll-s3/cli.rb
|
96
|
+
- lib/jekyll-s3/errors.rb
|
97
|
+
- lib/jekyll-s3/uploader.rb
|
98
|
+
- lib/jekyll-s3/version.rb
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: ""
|
101
|
+
licenses: []
|
102
|
+
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.3.7
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Push your jekyll blog to S3"
|
133
|
+
test_files:
|
134
|
+
- features/jekyll-s3.feature
|
135
|
+
- features/support/env.rb
|