s3deploy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -2
- data/bin/s3deploy +28 -9
- data/lib/.s3deploy.yml +15 -7
- data/lib/s3deploy/version.rb +1 -1
- data/lib/s3deploy.rb +65 -11
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# S3deploy
|
2
2
|
|
3
|
-
|
3
|
+
S3deploy is a tool for deploying static websites to Amazon S3.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,9 +18,38 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Get an Amazon AWS account and create the bucket you want to use. Set up the bucket to be used as a website.
|
22
|
+
|
23
|
+
### Create configuration files
|
24
|
+
|
25
|
+
Create a folder configuration file like this:
|
26
|
+
|
27
|
+
$ s3deploy init
|
28
|
+
|
29
|
+
Then update the newly created .s3deploy.yml with your settings.
|
30
|
+
You might want to create a default configuration file where you can store information shared between sites, like Amazon access key, secret and region. You do that with this command:
|
31
|
+
|
32
|
+
$ s3deploy init --default
|
33
|
+
|
34
|
+
This configuration file will be created in your home directory in the .s3deploy folder. Update this file with your info, remember that the settings in the .s3deploy.yml in the project folder takes precedance over settings in this file.
|
35
|
+
|
36
|
+
### Deployment
|
37
|
+
|
38
|
+
Deploying is easy now, just type:
|
39
|
+
|
40
|
+
$ s3deploy
|
41
|
+
|
42
|
+
If you want to test-drive your configuration you can simulate a deploy
|
43
|
+
|
44
|
+
$ s3deploy simulate
|
45
|
+
|
46
|
+
## Whats in the pipe-line
|
47
|
+
1. Setting caching-headers by regex
|
48
|
+
2. Skipping files by regex
|
49
|
+
3. Putting it on github for others to contribute
|
22
50
|
|
23
51
|
## Contributing
|
52
|
+
(you cant do this riktigt now, but it will be on the githubz soon)
|
24
53
|
|
25
54
|
1. Fork it
|
26
55
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/bin/s3deploy
CHANGED
@@ -2,13 +2,32 @@
|
|
2
2
|
|
3
3
|
require "s3deploy"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
begin
|
6
|
+
if ARGV.empty?
|
7
|
+
unless S3deploy.config_files?
|
8
|
+
raise "Create config files first with 's3deploy init' or 's3deploy init --default'."
|
9
|
+
end
|
10
|
+
s3deploy = S3deploy.new
|
11
|
+
s3deploy.deploy
|
12
|
+
elsif ARGV.first == "init"
|
13
|
+
S3deploy.install_config(ARGV.include? "--default")
|
14
|
+
elsif ARGV.first == "simulate"
|
15
|
+
s3deploy = S3deploy.new
|
16
|
+
s3deploy.deploy(true)
|
17
|
+
else
|
18
|
+
puts <<-eos
|
19
|
+
S3deploy usage.
|
20
|
+
|
21
|
+
s3deploy init (creates folder configuration)
|
22
|
+
s3deploy init --default (creates default configuration)
|
23
|
+
|
24
|
+
s3deploy (deploys the site to Amazon S3)
|
25
|
+
s3deploy simulate (simulates a deployment of the site to Amazon S3)
|
26
|
+
|
27
|
+
Folder configurations takes precedence over default configurations.
|
28
|
+
I put my aws key, secret and region in default and the rest in folder.
|
29
|
+
eos
|
30
|
+
end
|
31
|
+
rescue Exception => e
|
32
|
+
puts e.message
|
14
33
|
end
|
data/lib/.s3deploy.yml
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
---
|
2
|
-
aws_key:
|
3
|
-
aws_secret:
|
4
|
-
aws_bucket:
|
5
|
-
aws_region:
|
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.
|
6
15
|
extras:
|
7
|
-
|
8
|
-
|
9
|
-
- ssl
|
16
|
+
#- delete_old_files # deletes files that were in the bucket but not in the latest deploy
|
17
|
+
#- replace_with_gzip # replaces files with gz versions if they exist
|
data/lib/s3deploy/version.rb
CHANGED
data/lib/s3deploy.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
require "s3deploy/version"
|
2
2
|
require "AWS/S3"
|
3
|
+
require "digest/md5"
|
4
|
+
require "yaml" unless defined? YAML
|
3
5
|
|
4
6
|
class S3deploy
|
5
7
|
|
6
8
|
AWS_REGIONS = %W(us-west-2 us-west-1 eu-west-1 ap-southeast-1 ap-northeast-1 sa-east-1)
|
7
9
|
|
10
|
+
def self.config_files?
|
11
|
+
File.exists?( File.expand_path "~/.s3deploy/.s3deploy.yml" ) || File.exists?( File.expand_path "./.s3deploy.yml" )
|
12
|
+
end
|
13
|
+
|
8
14
|
def initialize(options = {})
|
9
15
|
defaults = { "path" => ".", "remote_path" => "" }
|
10
16
|
@options = defaults.merge(options)
|
11
17
|
@options.merge! import_settings(File.expand_path("~/.s3deploy/.s3deploy.yml"))
|
12
18
|
@options.merge! import_settings(File.expand_path("./.s3deploy.yml"))
|
13
19
|
|
14
|
-
|
20
|
+
@options["extras"] ||= []
|
21
|
+
|
15
22
|
raise "No AWS credentials given." unless @options["aws_key"] && @options["aws_secret"]
|
16
23
|
|
17
24
|
set_aws_region(@options["aws_region"]) if @options["aws_region"]
|
@@ -20,32 +27,79 @@ class S3deploy
|
|
20
27
|
:access_key_id => @options["aws_key"],
|
21
28
|
:secret_access_key => @options["aws_secret"]
|
22
29
|
)
|
23
|
-
|
24
|
-
puts "Will deploy to #{@options["aws_bucket"]}"
|
25
30
|
end
|
26
31
|
|
27
|
-
def deploy
|
32
|
+
def deploy(simulate = false)
|
28
33
|
|
29
34
|
raise "No bucket selected." unless @options["aws_bucket"]
|
30
|
-
bucket = AWS::S3::Bucket.find @options["aws_bucket"]
|
35
|
+
@bucket = AWS::S3::Bucket.find @options["aws_bucket"]
|
31
36
|
|
32
37
|
path = File.expand_path(@options["path"])
|
33
|
-
puts "path: #{path}"
|
34
38
|
raise "#{@options["path"]} is not a path." unless File.directory? path
|
35
39
|
|
36
|
-
|
40
|
+
puts "Deploying to #{@options["aws_bucket"]}"
|
37
41
|
|
42
|
+
files = all_files(path).map { |f| f.gsub(/^#{path}\//, "")}
|
43
|
+
skip_files = []
|
44
|
+
active_files = []
|
38
45
|
files.each do |file|
|
46
|
+
next if skip_files.include? file
|
47
|
+
|
39
48
|
full_path = (path + "/" + file).gsub( /\/\//, "/")
|
40
49
|
full_remote_path = (@options["remote_path"] + "/" + file).gsub( /\/\//, "/").gsub( /(^\/)|(\/$)/, "")
|
41
|
-
|
50
|
+
|
51
|
+
if @options["extras"].include?("replace_with_gzip") && has_gzip_version?(file, files)
|
52
|
+
full_path.gsub!(/.gz$/, "")
|
53
|
+
file.gsub!(/.gz$/, "")
|
54
|
+
full_remote_path.gsub!(/.gz$/, "")
|
55
|
+
skip_files << file << file + ".gz"
|
56
|
+
if is_gzip_smaller?(full_path)
|
57
|
+
file = file + ".gz"
|
58
|
+
full_path = full_path + ".gz"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
active_files << full_remote_path
|
63
|
+
|
64
|
+
if s3_file_exists?(full_path, full_remote_path)
|
65
|
+
puts "Skipped\t\t#{full_remote_path}"
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
upload_file(full_path, full_remote_path, simulate)
|
70
|
+
end
|
71
|
+
|
72
|
+
only_keep(active_files, simulate) if @options["extras"].include?("delete_old_files")
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def has_gzip_version?(file, files)
|
77
|
+
(file !~ /.+.gz$/ && files.include?("#{file}.gz")) || ( file =~ /.+.gz$/ && files.include?( file.gsub(/.gz$/, "") ) )
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_gzip_smaller?(full_path)
|
81
|
+
open("#{full_path}.gz").size < open("#{full_path}").size
|
82
|
+
end
|
83
|
+
|
84
|
+
def only_keep(active_files, simulate)
|
85
|
+
@bucket.each do |o|
|
86
|
+
unless active_files.include?( o.key )
|
87
|
+
AWS::S3::S3Object.delete(o.key, @options["aws_bucket"]) unless simulate
|
88
|
+
puts "Deleted\t\t#{o.key}"
|
89
|
+
end
|
42
90
|
end
|
91
|
+
end
|
43
92
|
|
93
|
+
def s3_file_exists?(local, remote)
|
94
|
+
md5 = Digest::MD5.hexdigest(open(local).read)
|
95
|
+
!@bucket.objects.select{|o| o.key == remote && o.etag == md5 }.empty?
|
44
96
|
end
|
45
97
|
|
46
|
-
def upload_file(local, remote)
|
47
|
-
|
48
|
-
|
98
|
+
def upload_file(local, remote, simulate, options = {})
|
99
|
+
options[:access] = :public_read
|
100
|
+
options[:"Content-Encoding"] = "gzip" if local =~ /.+.gz$/
|
101
|
+
AWS::S3::S3Object.store(remote, open(local), @options["aws_bucket"], options) unless simulate
|
102
|
+
puts "Uploaded\t#{remote}"
|
49
103
|
end
|
50
104
|
|
51
105
|
def self.install_config(default = false)
|
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.0.
|
4
|
+
version: 0.0.3
|
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-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-s3
|