s3deploy 0.1.0 → 0.1.1
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/README.md +1 -1
- data/bin/s3deploy +12 -1
- data/lib/.s3deploy.yml +19 -17
- data/lib/s3deploy.rb +27 -9
- data/lib/s3deploy/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -45,7 +45,7 @@ If you want to test-drive your configuration you can simulate a deploy
|
|
45
45
|
|
46
46
|
## Whats next?
|
47
47
|
|
48
|
-
1. Create method for creating a bucket from the settings in the configuration and
|
48
|
+
1. Create method for creating a bucket from the settings in the configuration and setting it up as a website.
|
49
49
|
|
50
50
|
## Contributing
|
51
51
|
|
data/bin/s3deploy
CHANGED
@@ -13,7 +13,14 @@ begin
|
|
13
13
|
S3deploy.install_config(ARGV.include? "--default")
|
14
14
|
elsif ARGV.first == "simulate"
|
15
15
|
s3deploy = S3deploy.new
|
16
|
-
|
16
|
+
if ARGV[1] && ARGV[1] == "empty"
|
17
|
+
s3deploy.empty(true)
|
18
|
+
else
|
19
|
+
s3deploy.deploy(true)
|
20
|
+
end
|
21
|
+
elsif ARGV.first == "empty"
|
22
|
+
s3deploy = S3deploy.new
|
23
|
+
s3deploy.empty(false)
|
17
24
|
else
|
18
25
|
puts <<-eos
|
19
26
|
S3deploy usage.
|
@@ -26,6 +33,10 @@ begin
|
|
26
33
|
|
27
34
|
Folder configurations takes precedence over default configurations.
|
28
35
|
I put my aws key, secret and region in default and the rest in folder.
|
36
|
+
|
37
|
+
s3deploy empty (deletes all files in bucket)
|
38
|
+
s3deploy simulate empty (simulates deletion of files)
|
39
|
+
|
29
40
|
eos
|
30
41
|
end
|
31
42
|
rescue Exception => e
|
data/lib/.s3deploy.yml
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
---
|
2
|
-
aws_key:
|
3
|
-
aws_secret:
|
4
|
-
aws_bucket:
|
5
|
-
#aws_region:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#path:
|
14
|
-
#remote_path:
|
15
|
-
#cache_regex:
|
16
|
-
|
17
|
-
#skip_regex:
|
18
|
-
|
2
|
+
aws_key: # your amazon key *required*
|
3
|
+
aws_secret: # your amazon secret *required*
|
4
|
+
aws_bucket: # the bucket you want to deploy to *required*
|
5
|
+
#aws_region: # the region where your bucket is located
|
6
|
+
# region names are: (blank for US Standard)
|
7
|
+
# us-west-2 US West (Oregon)
|
8
|
+
# us-west-1 US West (Northern California)
|
9
|
+
# eu-west-1 EU (Ireland)
|
10
|
+
# ap-southeast-1 Singapore ( Asia Pacific )
|
11
|
+
# ap-northeast-1 Tokyo ( Asia Pacific )
|
12
|
+
# sa-east-1 South America (Sao Paulo)
|
13
|
+
#path: # the relative path to the files you want to deploy, leave it blank for current directory.
|
14
|
+
#remote_path: # the path within the bucket to where you want to deploy, leave it blank for bucket root.
|
15
|
+
#cache_regex: ^(images|javascripts|stylesheets)\/.+\.(png|jpg|js|css)(\.gz)?$
|
16
|
+
# Adds headers for browser cache for files matching regex.
|
17
|
+
#skip_regex: \.DS_Store$
|
18
|
+
# Skips files that match this regex.
|
19
|
+
#html_charset: utf-8
|
20
|
+
# Sets the charset header on html files
|
19
21
|
extras:
|
20
22
|
#- delete_old_files # deletes files that were in the bucket but not in the latest deploy
|
21
23
|
#- replace_with_gzip # replaces files with gz versions if they exist
|
data/lib/s3deploy.rb
CHANGED
@@ -27,12 +27,12 @@ class S3deploy
|
|
27
27
|
:access_key_id => @options["aws_key"],
|
28
28
|
:secret_access_key => @options["aws_secret"]
|
29
29
|
)
|
30
|
-
end
|
31
|
-
|
32
|
-
def deploy(simulate = false)
|
33
30
|
|
34
31
|
raise "No bucket selected." unless @options["aws_bucket"]
|
35
32
|
@bucket = AWS::S3::Bucket.find @options["aws_bucket"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def deploy(simulate = false)
|
36
36
|
|
37
37
|
path = File.expand_path(@options["path"])
|
38
38
|
raise "#{@options["path"]} is not a path." unless File.directory? path
|
@@ -54,9 +54,9 @@ class S3deploy
|
|
54
54
|
full_remote_path = (@options["remote_path"] + "/" + file).gsub( /\/\//, "/").gsub( /(^\/)|(\/$)/, "")
|
55
55
|
|
56
56
|
if @options["extras"].include?("replace_with_gzip") && has_gzip_version?(file, files)
|
57
|
-
full_path.gsub!(/.gz
|
58
|
-
file.gsub!(/.gz
|
59
|
-
full_remote_path.gsub!(/.gz
|
57
|
+
full_path.gsub!(/.gz$/i, "")
|
58
|
+
file.gsub!(/.gz$/i, "")
|
59
|
+
full_remote_path.gsub!(/.gz$/i, "")
|
60
60
|
skip_files << file << file + ".gz"
|
61
61
|
if is_gzip_smaller?(full_path)
|
62
62
|
file = file + ".gz"
|
@@ -79,7 +79,7 @@ class S3deploy
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def has_gzip_version?(file, files)
|
82
|
-
(file !~ /.+.gz$/ && files.include?("#{file}.gz")) || ( file =~ /.+.gz$/ && files.include?( file.gsub(/.gz
|
82
|
+
(file !~ /.+.gz$/i && files.include?("#{file}.gz")) || ( file =~ /.+.gz$/i && files.include?( file.gsub(/.gz$/i, "") ) )
|
83
83
|
end
|
84
84
|
|
85
85
|
def is_gzip_smaller?(full_path)
|
@@ -95,6 +95,14 @@ class S3deploy
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def empty(simulate)
|
99
|
+
puts "Emptying #{@options["aws_bucket"]} #{"(Simulating)" if simulate}"
|
100
|
+
@bucket.each do |o|
|
101
|
+
AWS::S3::S3Object.delete(o.key, @options["aws_bucket"]) unless simulate
|
102
|
+
puts "Deleted\t\t#{o.key}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
98
106
|
def s3_file_exists?(local, remote)
|
99
107
|
md5 = Digest::MD5.hexdigest(open(local).read)
|
100
108
|
!@bucket.objects.select{|o| o.key == remote && o.etag == md5 }.empty?
|
@@ -107,9 +115,19 @@ class S3deploy
|
|
107
115
|
options[:"Cache-Control"] = "public, max-age=31557600"
|
108
116
|
end
|
109
117
|
|
110
|
-
options[:
|
118
|
+
options[:content_type] = "text/html; charset=#{@options["html_charset"]}" if @options["html_charset"] && remote =~ /.+\.(html|htm)(\.gz)?$/i
|
119
|
+
options[:"Content-Encoding"] = "gzip" if local =~ /.+.gz$/i
|
120
|
+
|
121
|
+
extra_info = []
|
122
|
+
extra_info << "cache-headers" if options[:"Cache-Control"]
|
123
|
+
extra_info << "gzip" if options[:"Content-Encoding"]
|
124
|
+
extra_info << "charset=#{@options["html_charset"]}" if options[:content_type]
|
125
|
+
|
111
126
|
AWS::S3::S3Object.store(remote, open(local), @options["aws_bucket"], options) unless simulate
|
112
|
-
|
127
|
+
|
128
|
+
message = "Uploaded\t#{remote}"
|
129
|
+
message += " (#{extra_info.join(", ")})" unless extra_info.empty?
|
130
|
+
puts message
|
113
131
|
end
|
114
132
|
|
115
133
|
def self.install_config(default = false)
|
data/lib/s3deploy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-s3
|