s3deployer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +1 -1
- data/bin/s3deploy +37 -7
- data/lib/s3deployer/version.rb +1 -1
- data/lib/s3deployer.rb +27 -4
- data/spec/s3deployer_spec.rb +23 -2
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
data/bin/s3deploy
CHANGED
@@ -1,14 +1,44 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 's3deployer'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
optparse = OptionParser.new do|opts|
|
9
|
+
|
10
|
+
opts.on( '-h', '--help', 'Display this dialog' ) do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
options[:force_upload] = false
|
16
|
+
opts.on("-f", "--force", "Force Reuploading of files regardless of checksums" ) do
|
17
|
+
options[:force_upload] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
options[:bucket_name] = ""
|
21
|
+
opts.on( '-b', '--bucket BUCKET', 'S3 Bucket to upload to' ) do|b|
|
22
|
+
options[:bucket_name] = b
|
23
|
+
end
|
24
|
+
|
25
|
+
options[:directory] = "."
|
26
|
+
opts.on( '-d', '--directory DIRECTORY', 'Directory to deploy' ) do|d|
|
27
|
+
if File.directory? d
|
28
|
+
options[:directory] = d
|
29
|
+
else
|
30
|
+
puts "Directory #{d} does not exist"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
4
34
|
|
5
|
-
if ARGV[0].nil?
|
6
|
-
raise "Please supply a bucket name"
|
7
|
-
exit 1
|
8
35
|
end
|
9
36
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
37
|
+
optparse.parse!
|
38
|
+
|
39
|
+
options[:access_key] ||= ENV['AMAZON_ACCESS_KEY_ID']
|
40
|
+
options[:secret_key] ||= ENV['AMAZON_SECRET_ACCESS_KEY']
|
41
|
+
|
42
|
+
deployer = S3Deployer.new(options[:access_key], options[:secret_key], options)
|
43
|
+
deployer.deploy options[:directory], options[:bucket_name]
|
14
44
|
|
data/lib/s3deployer/version.rb
CHANGED
data/lib/s3deployer.rb
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
require 'aws/s3'
|
2
2
|
require 'pathname'
|
3
|
+
require 'digest/md5'
|
3
4
|
|
4
5
|
class S3Deployer
|
6
|
+
|
7
|
+
DEFAULT_OPTIONS={
|
8
|
+
force_upload: false
|
9
|
+
}
|
5
10
|
attr_accessor :directory_to_deploy, :bucket_name
|
6
|
-
|
11
|
+
|
12
|
+
def initialize(access_key, secret_key, options=DEFAULT_OPTIONS)
|
7
13
|
AWS::S3::Base.establish_connection!({
|
8
14
|
:access_key_id => access_key,
|
9
|
-
:secret_access_key => secret_key
|
15
|
+
:secret_access_key => secret_key
|
16
|
+
})
|
17
|
+
@force_upload = options[:force_upload]
|
10
18
|
end
|
19
|
+
|
11
20
|
def deploy(directory_to_deploy, bucket_name)
|
12
21
|
@bucket_name = bucket_name
|
13
22
|
@directory_to_deploy = File.expand_path(directory_to_deploy)
|
@@ -29,7 +38,21 @@ class S3Deployer
|
|
29
38
|
def upload_item(item)
|
30
39
|
item_as_path = Pathname.new(item)
|
31
40
|
s3_name = item_as_path.sub("#{@directory_to_deploy}/", '').cleanpath.to_s
|
32
|
-
|
33
|
-
|
41
|
+
if (@force_upload or not item_exists?(item))
|
42
|
+
puts "uploading #{item} as #{s3_name}"
|
43
|
+
AWS::S3::S3Object.store(s3_name, open(item), bucket_name)
|
44
|
+
else
|
45
|
+
puts "not uploading #{item}, it exists on S3 as #{s3_name}"
|
46
|
+
end
|
34
47
|
end
|
48
|
+
|
49
|
+
def item_exists?(item)
|
50
|
+
item_as_path = Pathname.new(item)
|
51
|
+
s3_name = item_as_path.sub("#{directory_to_deploy}/", '').cleanpath.to_s
|
52
|
+
return false unless AWS::S3::S3Object.exists?(s3_name, bucket_name)
|
53
|
+
existing = AWS::S3::S3Object.find(s3_name, bucket_name)
|
54
|
+
md5 = Digest::MD5.hexdigest(File.read(item))
|
55
|
+
existing.etag == md5
|
56
|
+
end
|
57
|
+
|
35
58
|
end
|
data/spec/s3deployer_spec.rb
CHANGED
@@ -5,18 +5,26 @@ describe S3Deployer do
|
|
5
5
|
AWS::S3::Base.stub(:establish_connection!)
|
6
6
|
Dir.mkdir('files') unless Dir.exists?('files')
|
7
7
|
AWS::S3::S3Object.stub(:store)
|
8
|
+
AWS::S3::S3Object.stub(:exists?).and_return(true)
|
9
|
+
AWS::S3::S3Object.stub(:find).and_return(stub(etag: '1234'))
|
8
10
|
subject.stub(:open).and_return('asdf')
|
9
11
|
end
|
10
|
-
|
12
|
+
|
13
|
+
|
14
|
+
subject { S3Deployer.new('abc', '123') }
|
11
15
|
describe "instantiation" do
|
12
16
|
it "Connects to Amazon S3 with access and secret keys" do
|
13
|
-
|
17
|
+
options = {}
|
18
|
+
options[:force_upload] = false
|
19
|
+
options[:directory] = '.'
|
20
|
+
S3Deployer.new('abc', '123', options)
|
14
21
|
AWS::S3::Base.should have_received(:establish_connection!).with({
|
15
22
|
:access_key_id=>'abc',
|
16
23
|
:secret_access_key=>'123'
|
17
24
|
})
|
18
25
|
end
|
19
26
|
end
|
27
|
+
|
20
28
|
describe "deploy" do
|
21
29
|
context "with multiple files" do
|
22
30
|
it "uploads them to S3" do
|
@@ -29,6 +37,19 @@ describe S3Deployer do
|
|
29
37
|
File.delete("#{Dir.pwd}/files/hiphopper")
|
30
38
|
end
|
31
39
|
end
|
40
|
+
|
41
|
+
context "when a file exists in the same state" do
|
42
|
+
it "Does not store the file" do
|
43
|
+
create_file("word", "asdf")
|
44
|
+
md5 = Digest::MD5.hexdigest(File.read("#{Dir.pwd}/files/word"))
|
45
|
+
AWS::S3::S3Object.stub(:find).and_return(stub(etag: md5))
|
46
|
+
subject.deploy "#{Dir.pwd}/files", 'bucket'
|
47
|
+
AWS::S3::S3Object.should_not have_received(:store).with('word', 'asdf', 'bucket')
|
48
|
+
File.delete("#{Dir.pwd}/files/word")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
32
53
|
context "with . as directory to deploy" do
|
33
54
|
it "doesn't strip out .'s in file names" do
|
34
55
|
create_file("blah.html", "asdf")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-s3
|
16
|
-
requirement: &
|
16
|
+
requirement: &70179732131360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70179732131360
|
25
25
|
description: A simple way to deploy a directory to Amazon s3
|
26
26
|
email:
|
27
27
|
- zee@zeespencer.com
|