jammit-s3 0.5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/bin/jammit-s3 +4 -0
- data/jammit-s3.gemspec +23 -0
- data/lib/jammit-s3.rb +2 -0
- data/lib/jammit/s3_command_line.rb +92 -0
- data/lib/jammit/s3_uploader.rb +63 -0
- metadata +120 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Jacques Crocker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/jammit-s3
ADDED
data/jammit-s3.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'jammit-s3'
|
3
|
+
s.version = '0.5.3.0'
|
4
|
+
|
5
|
+
s.homepage = "http://documentcloud.github.com/jammit/"
|
6
|
+
s.summary = "Asset Packaging for Rails with Deployment to S3/Cloudfront"
|
7
|
+
s.description = <<-EOS
|
8
|
+
Jammit-S3 is an extension to the awesome Jammit library that handles deployment to s3 and cloudfront.
|
9
|
+
EOS
|
10
|
+
|
11
|
+
s.authors = ['Jacques Crocker']
|
12
|
+
s.email = 'railsjedi@gmail.com'
|
13
|
+
s.rubyforge_project = 'jammit-s3'
|
14
|
+
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
s.executables = ['jammit-s3']
|
17
|
+
|
18
|
+
s.add_dependency 'jammit', '>= 0.5.3'
|
19
|
+
s.add_dependency 'mimemagic', '>= 0.1.7'
|
20
|
+
s.add_dependency 's3', ">= 0.3.4"
|
21
|
+
|
22
|
+
s.files = Dir['lib/**/*', 'bin/*', 'jammit-s3.gemspec', 'LICENSE', 'README']
|
23
|
+
end
|
data/lib/jammit-s3.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'jammit/command_line'
|
2
|
+
|
3
|
+
require 's3'
|
4
|
+
module Jammit
|
5
|
+
class S3CommandLine < CommandLine
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
upload_assets_to_s3
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload_assets_to_s3
|
12
|
+
verify_s3_configuration
|
13
|
+
ensure_bucket_exists
|
14
|
+
upload_assets
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def verify_s3_configuration
|
19
|
+
unless get_bucket_name.is_a?(String) && get_bucket_name.length > 0
|
20
|
+
puts "\nA valid s3_bucket name is required."
|
21
|
+
puts "Please add one to your Jammit config (config/assets.yml):\n\n"
|
22
|
+
puts "s3_bucket: my-bucket-name\n\n"
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
unless get_access_key_id.is_a?(String) && get_access_key_id.length > 0
|
26
|
+
puts "access_key_id: '#{get_access_key_id}' is not valid"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
unless get_secret_access_key.is_a?(String) && get_secret_access_key.length > 0
|
30
|
+
puts "secret_access_key: '#{get_secret_access_key}' is not valid"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def upload_assets
|
36
|
+
S3Uploader.new(s3_bucket).upload
|
37
|
+
end
|
38
|
+
|
39
|
+
def s3_service
|
40
|
+
@s3_service ||= S3::Service.new(:access_key_id => get_access_key_id, :secret_access_key => get_secret_access_key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def s3_bucket
|
44
|
+
@s3_bucket ||= ensure_bucket_exists
|
45
|
+
end
|
46
|
+
|
47
|
+
def ensure_bucket_exists
|
48
|
+
bucket_name = get_bucket_name
|
49
|
+
|
50
|
+
# find or create the bucket
|
51
|
+
bucket = begin
|
52
|
+
s3_service.buckets.find(bucket_name)
|
53
|
+
rescue S3::Error::NoSuchBucket
|
54
|
+
puts "Bucket not found. Creating '#{bucket_name}'..."
|
55
|
+
bucket = s3_service.buckets.build(bucket_name)
|
56
|
+
|
57
|
+
begin
|
58
|
+
bucket.save(get_bucket_location)
|
59
|
+
rescue S3::Error::BucketAlreadyExists => e
|
60
|
+
# tell them to pick another name
|
61
|
+
puts e.message
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
end
|
65
|
+
bucket
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_bucket_name
|
69
|
+
# TODO: use highline if needed
|
70
|
+
Jammit.configuration[:s3_bucket]
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_access_key_id
|
74
|
+
# TODO: use highline if needed
|
75
|
+
Jammit.configuration[:s3_access_key_id]
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_secret_access_key
|
79
|
+
# TODO: use highline if needed
|
80
|
+
Jammit.configuration[:s3_secret_access_key]
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_bucket_location
|
84
|
+
location = Jammit.configuration[:s3_bucket_location]
|
85
|
+
if location == "eu"
|
86
|
+
:eu
|
87
|
+
else
|
88
|
+
:us
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'mimemagic'
|
2
|
+
|
3
|
+
module Jammit
|
4
|
+
class S3Uploader
|
5
|
+
def initialize(bucket)
|
6
|
+
@bucket = bucket
|
7
|
+
end
|
8
|
+
|
9
|
+
def upload
|
10
|
+
puts "Pushing assets to S3 bucket: #{@bucket.name}"
|
11
|
+
globs = []
|
12
|
+
|
13
|
+
# add default package path
|
14
|
+
if Jammit.gzip_assets
|
15
|
+
globs << "public/#{Jammit.package_path}/**/*.gz"
|
16
|
+
else
|
17
|
+
globs << "public/#{Jammit.package_path}/**/*.css"
|
18
|
+
globs << "public/#{Jammit.package_path}/**/*.js"
|
19
|
+
end
|
20
|
+
|
21
|
+
# add images
|
22
|
+
globs << "public/images/**/*"
|
23
|
+
|
24
|
+
# add custom configuration if defined
|
25
|
+
s3_upload_files = Jammit.configuration[:s3_upload_files]
|
26
|
+
globs << s3_upload_files if s3_upload_files.is_a?(String)
|
27
|
+
globs += s3_upload_files if s3_upload_files.is_a?(Array)
|
28
|
+
|
29
|
+
# upload all the globs
|
30
|
+
globs.each do |glob|
|
31
|
+
upload_from_glob(glob)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def upload_from_glob(glob)
|
36
|
+
puts "Pushing files from #{glob}"
|
37
|
+
puts "#{ASSET_ROOT}/#{glob}"
|
38
|
+
Dir["#{ASSET_ROOT}/#{glob}"].each do |local_path|
|
39
|
+
next if File.directory?(local_path)
|
40
|
+
remote_path = local_path.gsub(/^#{ASSET_ROOT}\/public\//, "")
|
41
|
+
|
42
|
+
use_gzip = false
|
43
|
+
|
44
|
+
# handle gzipped files
|
45
|
+
if File.extname(remote_path) == ".gz"
|
46
|
+
use_gzip = true
|
47
|
+
remote_path = remote_path.gsub(/\.gz$/, "")
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "pushing file to s3: #{remote_path}"
|
51
|
+
|
52
|
+
# save to s3
|
53
|
+
new_object = @bucket.objects.build(remote_path)
|
54
|
+
new_object.content_type = MimeMagic.by_path(remote_path)
|
55
|
+
new_object.content = open(local_path)
|
56
|
+
new_object.content_encoding = "gzip" if use_gzip
|
57
|
+
new_object.save
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jammit-s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 107
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 3
|
10
|
+
- 0
|
11
|
+
version: 0.5.3.0
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Jacques Crocker
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-10-03 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: jammit
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 13
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 5
|
34
|
+
- 3
|
35
|
+
version: 0.5.3
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mimemagic
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 21
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 1
|
50
|
+
- 7
|
51
|
+
version: 0.1.7
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: s3
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 27
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 3
|
66
|
+
- 4
|
67
|
+
version: 0.3.4
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
70
|
+
description: " Jammit-S3 is an extension to the awesome Jammit library that handles deployment to s3 and cloudfront.\n"
|
71
|
+
email: railsjedi@gmail.com
|
72
|
+
executables:
|
73
|
+
- jammit-s3
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files: []
|
77
|
+
|
78
|
+
files:
|
79
|
+
- lib/jammit/s3_command_line.rb
|
80
|
+
- lib/jammit/s3_uploader.rb
|
81
|
+
- lib/jammit-s3.rb
|
82
|
+
- bin/jammit-s3
|
83
|
+
- jammit-s3.gemspec
|
84
|
+
- LICENSE
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://documentcloud.github.com/jammit/
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project: jammit-s3
|
115
|
+
rubygems_version: 1.3.7
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Asset Packaging for Rails with Deployment to S3/Cloudfront
|
119
|
+
test_files: []
|
120
|
+
|