capistrano-s3-mirror 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/capistrano-s3-mirror.gemspec +51 -0
- data/lib/capistrano/s3-mirror.rb +131 -0
- metadata +81 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.8.3"
|
11
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.8.3)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rdoc
|
10
|
+
json (1.6.1)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rdoc (3.12)
|
13
|
+
json (~> 1.4)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.0.0)
|
20
|
+
jeweler (~> 1.8.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Femaref
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= capistrano-s3-mirror
|
2
|
+
|
3
|
+
Mirrors the content of the public directory to a specified s3 bucket/folder.
|
4
|
+
|
5
|
+
== Contributing to capistrano-s3-mirror
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Region Endpoints
|
16
|
+
Endpoint list for usage with `set :s3_region_endpoint, "endpoint"`
|
17
|
+
|
18
|
+
Region Endpoint Location Constraint Protocol
|
19
|
+
US Standard * s3.amazonaws.com (none required) HTTP and HTTPS
|
20
|
+
US West (Oregon) Region s3-us-west-2.amazonaws.com us-west-2 HTTP and HTTPS
|
21
|
+
US West (Northern California) Region s3-us-west-1.amazonaws.com us-west-1 HTTP and HTTPS
|
22
|
+
EU (Ireland) Region s3-eu-west-1.amazonaws.com EU HTTP and HTTPS
|
23
|
+
Asia Pacific (Singapore) Region s3-ap-southeast-1.amazonaws.com ap-southeast-1 HTTP and HTTPS
|
24
|
+
Asia Pacific (Tokyo) Region s3-ap-northeast-1.amazonaws.com ap-northeast-1 HTTP and HTTPS
|
25
|
+
South America (Sao Paulo) Region s3-sa-east-1.amazonaws.com sa-east-1 HTTP and HTTPS
|
26
|
+
|
27
|
+
|
28
|
+
== Copyright
|
29
|
+
|
30
|
+
Copyright (c) 2012 Femaref. See LICENSE.txt for
|
31
|
+
further details.
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "capistrano-s3-mirror"
|
18
|
+
gem.homepage = "http://github.com/Femaref/capistrano-s3-mirror"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{mirrors the public folder to amazon s3}
|
21
|
+
gem.description = %Q{mirrors the public folder to amazon s3}
|
22
|
+
gem.email = "femaref@googlemail.com"
|
23
|
+
gem.authors = ["Femaref"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rdoc/task'
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
31
|
+
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
33
|
+
rdoc.title = "capistrano-s3-mirror #{version}"
|
34
|
+
rdoc.rdoc_files.include('README*')
|
35
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
36
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "capistrano-s3-mirror"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Femaref"]
|
12
|
+
s.date = "2012-04-21"
|
13
|
+
s.description = "mirrors the public folder to amazon s3"
|
14
|
+
s.email = "femaref@googlemail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"capistrano-s3-mirror.gemspec",
|
28
|
+
"lib/capistrano/s3-mirror.rb"
|
29
|
+
]
|
30
|
+
s.homepage = "http://github.com/Femaref/capistrano-s3-mirror"
|
31
|
+
s.licenses = ["MIT"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = "1.8.10"
|
34
|
+
s.summary = "mirrors the public folder to amazon s3"
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
41
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
45
|
+
end
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
begin
|
2
|
+
require "aws/s3"
|
3
|
+
rescue LoadError
|
4
|
+
puts "aws-s3 gem needs to be installed"
|
5
|
+
puts "install via 'gem install aws-s3'"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
10
|
+
abort "capistrano/ext/multistage requires Capistrano 2"
|
11
|
+
end
|
12
|
+
|
13
|
+
Capistrano::Configuration.instance.load do
|
14
|
+
namespace :deploy do
|
15
|
+
desc "mirrors the content of the public folder to amazon s3"
|
16
|
+
task :s3_mirror do
|
17
|
+
|
18
|
+
if !exists? :s3_access_key_id
|
19
|
+
set(:s3_access_key_id) do
|
20
|
+
Capistrano::CLI.ui.ask("Enter s3_access_key_id: ")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if !exists? :s3_secret_access_key
|
25
|
+
set(:s3_secret_access_key) do
|
26
|
+
Capistrano::CLI.password_prompt("Enter s3_secret_access_key: ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if !exists? :s3_bucket_name
|
31
|
+
set(:s3_bucket_name) do
|
32
|
+
Capistrano::CLI.ui.ask("Enter s3_bucket_name: ")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if !exists? :s3_base_path
|
37
|
+
set(:s3_base_path) do
|
38
|
+
Capistrano::CLI.ui.ask("Enter s3_base_path: ")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if !exists? :s3_region_endpoint
|
43
|
+
set(:s3_region_endpoint) do
|
44
|
+
Capistrano::CLI.ui.ask("Enter s3_region_endpoint: ")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sync s3_access_key_id, s3_secret_access_key, s3_bucket_name, s3_base_path, s3_region_endpoint
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sync (key_id, secret_access_key, bucket_name, base_path, s3_region_endpoint)
|
55
|
+
AWS::S3::DEFAULT_HOST.replace(s3_region_endpoint)
|
56
|
+
AWS::S3::Base.establish_connection!(:access_key_id => key_id, :secret_access_key => secret_access_key)
|
57
|
+
|
58
|
+
bucket = AWS::S3::Bucket.find(bucket_name)
|
59
|
+
|
60
|
+
#/bucket_name/path/to/File
|
61
|
+
#/path/to/file
|
62
|
+
|
63
|
+
context = File.join(bucket_name, base_path).split("/")
|
64
|
+
|
65
|
+
# filter out directories
|
66
|
+
remote_data = bucket.objects.select{ |object| object.content_type != "application/x-directory"}
|
67
|
+
# remove the bucket name from the path
|
68
|
+
remote_data = remote_map(remote_data, context)
|
69
|
+
remote = Hash[remote_data]
|
70
|
+
|
71
|
+
local_data = Dir.chdir("public") do
|
72
|
+
# map local files to path => md5(file)
|
73
|
+
Dir["**/**"].select{ |d| !File.directory? d }.map { |path| [ path, Digest::MD5.file(path).hexdigest ] }
|
74
|
+
end
|
75
|
+
local = Hash[local_data]
|
76
|
+
|
77
|
+
new = local.keys - remote.keys
|
78
|
+
deleted = remote.keys - local.keys
|
79
|
+
both = local.keys & remote.keys
|
80
|
+
|
81
|
+
uploaded_count = 0
|
82
|
+
deleted_count = 0
|
83
|
+
updated_count = 0
|
84
|
+
|
85
|
+
Dir.chdir("public") do
|
86
|
+
new.each do |entry|
|
87
|
+
AWS::S3::S3Object.store(entry, open(entry), bucket_name, :access => :public_read)
|
88
|
+
uploaded_count += 1
|
89
|
+
end
|
90
|
+
|
91
|
+
deleted.each do |entry|
|
92
|
+
object = AWS::S3::S3Object.find(entry, bucket_name)
|
93
|
+
object.delete
|
94
|
+
|
95
|
+
deleted_count += 1
|
96
|
+
end
|
97
|
+
|
98
|
+
both.each do |entry|
|
99
|
+
if local[entry] != remote[entry].etag
|
100
|
+
AWS::S3::S3Object.store(entry, open(entry), bucket_name)
|
101
|
+
|
102
|
+
updated_count += 1
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
puts "uploaded #{uploaded_count}, deleted #{deleted_count}, updated #{updated_count}"
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
def remote_map (remote_data, context)
|
112
|
+
remote_data.map do |object|
|
113
|
+
cur_path = object.path.split("/")
|
114
|
+
|
115
|
+
if cur_path[0] == ""
|
116
|
+
cur_path = cur_path.drop(1)
|
117
|
+
end
|
118
|
+
|
119
|
+
cur_context = context.clone
|
120
|
+
|
121
|
+
cur_path = cur_path.drop_while do |element|
|
122
|
+
element == cur_context.shift
|
123
|
+
end
|
124
|
+
|
125
|
+
if cur_context.count > 0
|
126
|
+
abort "file error: didn't fit the bucket/base/path description, offending path: #{object.path}"
|
127
|
+
end
|
128
|
+
|
129
|
+
[File.join(cur_path), object]
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-s3-mirror
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Femaref
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &70253142064500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70253142064500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jeweler
|
27
|
+
requirement: &70253142063900 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.8.3
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70253142063900
|
36
|
+
description: mirrors the public folder to amazon s3
|
37
|
+
email: femaref@googlemail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files:
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- capistrano-s3-mirror.gemspec
|
52
|
+
- lib/capistrano/s3-mirror.rb
|
53
|
+
homepage: http://github.com/Femaref/capistrano-s3-mirror
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: 4570354828540185952
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: mirrors the public folder to amazon s3
|
81
|
+
test_files: []
|