microstatic 0.2.0 → 0.3.0
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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/bin/microstatic +17 -0
- data/lib/microstatic.rb +13 -0
- data/lib/microstatic/s3_bucket_creator.rb +17 -0
- data/lib/microstatic/s3_deployer.rb +10 -13
- data/lib/microstatic/uses_fog.rb +21 -0
- data/lib/microstatic/version.rb +1 -1
- data/microstatic.gemspec +1 -1
- metadata +21 -10
- data/.rvmrc +0 -1
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
microstatic
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
default
|
data/bin/microstatic
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'microstatic'
|
|
4
|
+
|
|
5
|
+
if ARGV.empty?
|
|
6
|
+
puts 'please specify a bucket name'
|
|
7
|
+
exit 1
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
bucket_name = ARGV[0]
|
|
11
|
+
|
|
12
|
+
bucket_creator = Microstatic::S3BucketCreator.new( Microstatic.aws_creds_from_env )
|
|
13
|
+
|
|
14
|
+
puts "creating bucket #{bucket_name} ..."
|
|
15
|
+
bucket_creator.create( bucket_name )
|
|
16
|
+
|
|
17
|
+
puts "done"
|
data/lib/microstatic.rb
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
require "microstatic/version"
|
|
2
|
+
|
|
3
|
+
require 'microstatic/uses_fog'
|
|
4
|
+
|
|
2
5
|
require "microstatic/s3_deployer"
|
|
6
|
+
require "microstatic/s3_bucket_creator"
|
|
7
|
+
|
|
8
|
+
module Microstatic
|
|
9
|
+
def self.aws_creds_from_env
|
|
10
|
+
{
|
|
11
|
+
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
|
|
12
|
+
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Microstatic
|
|
2
|
+
|
|
3
|
+
class S3BucketCreator
|
|
4
|
+
include UsesFog
|
|
5
|
+
|
|
6
|
+
def initialize( aws_creds )
|
|
7
|
+
check_and_store_aws_creds(aws_creds)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create( bucket_name )
|
|
11
|
+
connection.put_bucket( bucket_name )
|
|
12
|
+
connection.put_bucket_acl( bucket_name, 'public-read' )
|
|
13
|
+
connection.put_bucket_website( bucket_name, 'index.html', :key => '404.html' )
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
require 'digest/md5'
|
|
2
2
|
require 'pathname'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
module Microstatic
|
|
5
5
|
|
|
6
6
|
# The following is based on code generously
|
|
7
7
|
# shared by Giles Alexander (@gga)
|
|
8
|
-
class
|
|
8
|
+
class S3Deployer
|
|
9
|
+
include UsesFog
|
|
9
10
|
def initialize( local_dir, bucket, aws_creds )
|
|
10
|
-
|
|
11
|
-
raise ArgumentError, "must supply :#{required_key}" unless aws_creds.key?(required_key)
|
|
12
|
-
end
|
|
11
|
+
check_and_store_aws_creds(aws_creds)
|
|
13
12
|
|
|
14
13
|
@local_dir = Pathname.new(local_dir)
|
|
15
14
|
@bucket = bucket
|
|
16
|
-
@aws_creds = aws_creds
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
def upload
|
|
20
|
-
AWS::S3::Base.establish_connection!(@aws_creds)
|
|
21
|
-
|
|
22
18
|
Pathname.glob(@local_dir+"**/*") do |child|
|
|
23
19
|
upload_file(child) unless child.directory?
|
|
24
20
|
end
|
|
@@ -28,23 +24,23 @@ class Microstatic::S3Deployer
|
|
|
28
24
|
s3_key = file.relative_path_from(@local_dir).to_s
|
|
29
25
|
|
|
30
26
|
begin
|
|
31
|
-
s3_object =
|
|
32
|
-
rescue
|
|
27
|
+
s3_object = connection.head_object(@bucket,s3_key)
|
|
28
|
+
rescue Excon::Errors::NotFound
|
|
33
29
|
s3_object = false
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
if !s3_object
|
|
37
33
|
log_action('CREATE', s3_key)
|
|
38
|
-
|
|
34
|
+
connection.put_object( @bucket, s3_key, file.open, 'x-amz-acl' => 'public-read' )
|
|
39
35
|
else
|
|
40
|
-
s3_md5 = s3_object.
|
|
36
|
+
s3_md5 = s3_object.headers['ETag'].sub(/"(.*)"/,'\1')
|
|
41
37
|
local_md5 = Digest::MD5.hexdigest( file.read )
|
|
42
38
|
|
|
43
39
|
if( s3_md5 == local_md5 )
|
|
44
40
|
log_action('NO CHANGE', s3_key)
|
|
45
41
|
else
|
|
46
42
|
log_action('UPDATE', s3_key)
|
|
47
|
-
|
|
43
|
+
connection.put_object( @bucket, s3_key, file.open )
|
|
48
44
|
end
|
|
49
45
|
end
|
|
50
46
|
end
|
|
@@ -55,3 +51,4 @@ class Microstatic::S3Deployer
|
|
|
55
51
|
end
|
|
56
52
|
end
|
|
57
53
|
|
|
54
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'fog'
|
|
2
|
+
|
|
3
|
+
module Microstatic
|
|
4
|
+
module UsesFog
|
|
5
|
+
def check_and_store_aws_creds( aws_creds )
|
|
6
|
+
[:access_key_id,:secret_access_key].each do |required_key|
|
|
7
|
+
raise ArgumentError, "must supply :#{required_key}" unless aws_creds.key?(required_key)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
@aws_creds = aws_creds
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def connection
|
|
14
|
+
@_connection ||= Fog::Storage.new({
|
|
15
|
+
:provider => 'AWS',
|
|
16
|
+
:aws_access_key_id => @aws_creds.fetch(:access_key_id),
|
|
17
|
+
:aws_secret_access_key => @aws_creds.fetch(:secret_access_key)
|
|
18
|
+
})
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/microstatic/version.rb
CHANGED
data/microstatic.gemspec
CHANGED
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
|
15
15
|
gem.require_paths = ["lib"]
|
|
16
16
|
gem.version = Microstatic::VERSION
|
|
17
17
|
|
|
18
|
-
gem.add_runtime_dependency "
|
|
18
|
+
gem.add_runtime_dependency "fog", ">=1"
|
|
19
19
|
|
|
20
20
|
gem.add_development_dependency "rake"
|
|
21
21
|
gem.add_development_dependency "bundler"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microstatic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,24 +9,24 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
15
|
+
name: fog
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - ! '>='
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
21
|
+
version: '1'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ! '>='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
29
|
+
version: '1'
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: rake
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,19 +95,24 @@ description: The microstatic gem turns generating your static site and deploying
|
|
|
95
95
|
to S3 into a one-liner.
|
|
96
96
|
email:
|
|
97
97
|
- phodgson@thoughtworks.com
|
|
98
|
-
executables:
|
|
98
|
+
executables:
|
|
99
|
+
- microstatic
|
|
99
100
|
extensions: []
|
|
100
101
|
extra_rdoc_files: []
|
|
101
102
|
files:
|
|
102
103
|
- .gitignore
|
|
103
|
-
- .
|
|
104
|
+
- .ruby-gemset
|
|
105
|
+
- .ruby-version
|
|
104
106
|
- Gemfile
|
|
105
107
|
- LICENSE
|
|
106
108
|
- README.md
|
|
107
109
|
- Rakefile
|
|
110
|
+
- bin/microstatic
|
|
108
111
|
- lib/microstatic.rb
|
|
109
112
|
- lib/microstatic/rake.rb
|
|
113
|
+
- lib/microstatic/s3_bucket_creator.rb
|
|
110
114
|
- lib/microstatic/s3_deployer.rb
|
|
115
|
+
- lib/microstatic/uses_fog.rb
|
|
111
116
|
- lib/microstatic/version.rb
|
|
112
117
|
- microstatic.gemspec
|
|
113
118
|
- spec/integration/fixtures/example_file.txt
|
|
@@ -128,15 +133,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
128
133
|
- - ! '>='
|
|
129
134
|
- !ruby/object:Gem::Version
|
|
130
135
|
version: '0'
|
|
136
|
+
segments:
|
|
137
|
+
- 0
|
|
138
|
+
hash: 2953068700068104113
|
|
131
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
140
|
none: false
|
|
133
141
|
requirements:
|
|
134
142
|
- - ! '>='
|
|
135
143
|
- !ruby/object:Gem::Version
|
|
136
144
|
version: '0'
|
|
145
|
+
segments:
|
|
146
|
+
- 0
|
|
147
|
+
hash: 2953068700068104113
|
|
137
148
|
requirements: []
|
|
138
149
|
rubyforge_project:
|
|
139
|
-
rubygems_version: 1.8.
|
|
150
|
+
rubygems_version: 1.8.25
|
|
140
151
|
signing_key:
|
|
141
152
|
specification_version: 3
|
|
142
153
|
summary: Generate static sites from git and deploy them to an S3 bucket.
|
data/.rvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
rvm use --create default@microstatic
|