capistrano-s3 0.2.1 → 0.2.2

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.
File without changes
data/NEWS ADDED
@@ -0,0 +1,3 @@
1
+ New in 0.2.2
2
+
3
+ * Bugfix : fixed an error caused previously by removing SASS & HAML dependency.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # s3-static-site
1
+ # capistrano-s3
2
2
 
3
3
  > Allows static websites deployment to Amazon S3 website buckets using Capistrano.
4
4
 
@@ -20,11 +20,11 @@ Setup capistrano, create a public folder and set your S3 bucket configurations i
20
20
 
21
21
  ### Configuring deployment
22
22
 
23
- s3-static-site overrides the default Capistrano recipes for Rails projects with its own simple s3 publishing scripts.
23
+ capistrano-s3 overrides the default Capistrano recipes for Rails projects with its own simple s3 publishing scripts.
24
24
 
25
25
  ```ruby
26
26
  # config/deploy.rb
27
- require 's3-static-site'
27
+ require 'capistrano-s3'
28
28
 
29
29
  set :bucket, "www.cool-website-bucket.com"
30
30
  set :access_key_id, "CHANGETHIS"
@@ -37,7 +37,7 @@ and configure a bucket per stage configuration.
37
37
 
38
38
  #### S3 write options
39
39
 
40
- s3-static-site sets files `:content_type` and `:acl` to `:public_read`, add or override with :
40
+ capistrano-s3 sets files `:content_type` and `:acl` to `:public_read`, add or override with :
41
41
 
42
42
  ```ruby
43
43
  set :bucket_write_options, {
@@ -47,28 +47,21 @@ set :bucket_write_options, {
47
47
 
48
48
  See aws-sdk [S3Object.write doc](http://rubydoc.info/github/amazonwebservices/aws-sdk-for-ruby/master/AWS/S3/S3Object#write-instance_method) for all available options.
49
49
 
50
- ### Advanced static website generation & assets management
50
+ ### Website generation & assets management
51
51
 
52
52
  If you wish to manage your assets with a packaging system, a simple way do to it
53
53
  is using a combination of :
54
54
 
55
- - [Sinatra](https://github.com/sinatra/sinatra) : simple web framework that we extend for our needs
56
- - [Sinatra-AssetPack](https://github.com/rstacruz/sinatra-assetpack) : deals with version management for all kind of assets
57
- - [Sinatra-Static](https://github.com/paulasmuth/sinatra-static) : generate your complete website in `public/`, allowing an `s3-static-site` deployment
58
-
59
- IMPORTANT : to achieve `Sinatra-AssetPack` and `Sinatra-Static` compatibility, see [pull request #1](https://github.com/paulasmuth/sinatra-static/pull/1)
60
- or use [a patched fork](https://github.com/hooktstudios/sinatra-static).
55
+ - [sinatra](https://github.com/sinatra/sinatra) : simple web framework that we extend for our needs
56
+ - [sinatra-assetpack](https://github.com/hooktstudios/sinatra-assetpack) : deals with version management for all kind of assets
57
+ - [sinatra-export](https://github.com/hooktstudios/sinatra-export) : generate your complete website in `public/`, allowing an `s3-static-site` deployment
61
58
 
62
59
  Once you get this together, add a capistrano task to trigger website generation before deploy :
63
60
 
64
61
  ```ruby
65
62
  # config/deploy.rb
66
63
  before 'deploy' do
67
- run_locally "bundle exec ruby app.rb"
64
+ run_locally "bundle exec ruby sinata:export"
68
65
  run_locally "bundle exec rake assetpack:build"
69
66
  end
70
- ```
71
-
72
- ## Copyright
73
-
74
- Copyright (c) 2012 Josh Delsman & miomoba, Inc. See LICENSE.txt for details.
67
+ ```
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "capistrano-s3"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.2.1"
15
+ gem.version = "0.2.2"
16
16
 
17
17
  # Gem dependencies
18
18
  gem.add_dependency("aws-sdk")
@@ -0,0 +1,34 @@
1
+ require 'capistrano/s3/publisher'
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort "capistrano-s3 requires Capistrano >= 2."
5
+ end
6
+
7
+ Capistrano::Configuration.instance(true).load do
8
+ def _cset(name, *args, &block)
9
+ set(name, *args, &block) if !exists?(name)
10
+ end
11
+
12
+ _cset :deployment_path, Dir.pwd.gsub("\n", "") + "/public"
13
+
14
+ # Deployment recipes
15
+ namespace :deploy do
16
+ namespace :s3 do
17
+ desc "Empties bucket of all files. Caution when using this command, as it cannot be undone!"
18
+ task :empty do
19
+ Publisher.clear!(access_key_id, secret_access_key)
20
+ end
21
+
22
+ desc "Upload files to the bucket in the current state"
23
+ task :upload_files do
24
+ Publisher.publish!(access_key_id, secret_access_key, bucket, deployment_path, bucket_write_options)
25
+ end
26
+ end
27
+
28
+ task :update do
29
+ s3.upload_files
30
+ end
31
+
32
+ task :restart do; end
33
+ end
34
+ end
@@ -0,0 +1,57 @@
1
+ require 'aws/s3'
2
+ require 'mime/types'
3
+
4
+ module Publisher
5
+
6
+ def self.publish!(key, secret, bucket, source, extra_options)
7
+ s3 = self.establish_connection!(key, secret)
8
+
9
+ self.files(source).each do |file|
10
+ if !File.directory?(file)
11
+ path = self.base_file_path(source, file)
12
+ path.gsub!(/^\//, "") # Remove preceding slash for S3
13
+
14
+ contents = open(file)
15
+
16
+ types = MIME::Types.type_for(File.basename(file))
17
+ if types.empty?
18
+ options = {
19
+ :acl => :public_read
20
+ }
21
+ else
22
+ options = {
23
+ :acl => :public_read,
24
+ :content_type => types[0]
25
+ }
26
+ end
27
+ options.merge!(extra_options)
28
+ s3.buckets[bucket].objects[path].write(contents, options)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.clear!(key, secret, bucket)
34
+ s3 = self.establish_connection!(key, secret)
35
+ s3.buckets[bucket].clear!
36
+ end
37
+
38
+ private
39
+
40
+ # Establishes the connection to Amazon S3
41
+ def self.establish_connection!(key, secret)
42
+ # Send logging to STDOUT
43
+ AWS.config(:logger => Logger.new(STDOUT))
44
+ AWS::S3.new(
45
+ :access_key_id => key,
46
+ :secret_access_key => secret
47
+ )
48
+ end
49
+
50
+ def self.base_file_path(root, file)
51
+ file.gsub(root, "")
52
+ end
53
+
54
+ def self.files(deployment_path)
55
+ Dir.glob("#{deployment_path}/**/*")
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-12 00:00:00.000000000 Z
13
+ date: 2013-01-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -70,11 +70,13 @@ extra_rdoc_files: []
70
70
  files:
71
71
  - .gitignore
72
72
  - Gemfile
73
- - LICENSE.txt
73
+ - LICENSE
74
+ - NEWS
74
75
  - README.md
75
76
  - Rakefile
76
77
  - capistrano-s3.gemspec
77
- - lib/capistrano-s3.rb
78
+ - lib/capistrano/s3.rb
79
+ - lib/capistrano/s3/publisher.rb
78
80
  homepage: http://github.com/hooktstudios/capistrano-s3
79
81
  licenses:
80
82
  - MIT
data/lib/capistrano-s3.rb DELETED
@@ -1,79 +0,0 @@
1
- require 'aws/s3'
2
- require 'mime/types'
3
-
4
- unless Capistrano::Configuration.respond_to?(:instance)
5
- abort "capistrano-s3 requires Capistrano >= 2."
6
- end
7
-
8
- Capistrano::Configuration.instance(true).load do
9
- def _cset(name, *args, &block)
10
- set(name, *args, &block) if !exists?(name)
11
- end
12
-
13
- _cset :deployment_path, Dir.pwd.gsub("\n", "") + "/public"
14
-
15
- def base_file_path(file)
16
- file.gsub(deployment_path, "")
17
- end
18
-
19
- def files
20
- Dir.glob("#{deployment_path}/**/*")
21
- end
22
-
23
- # Establishes the connection to Amazon S3
24
- def establish_connection!
25
- # Send logging to STDOUT
26
- AWS.config(:logger => Logger.new(STDOUT))
27
-
28
- AWS::S3.new(
29
- :access_key_id => access_key_id,
30
- :secret_access_key => secret_access_key
31
- )
32
- end
33
-
34
- # Deployment recipes
35
- namespace :deploy do
36
- namespace :s3 do
37
- desc "Empties bucket of all files. Caution when using this command, as it cannot be undone!"
38
- task :empty do
39
- _s3 = establish_connection!
40
- _s3.buckets[bucket].clear!
41
- end
42
-
43
- desc "Upload files to the bucket in the current state"
44
- task :upload_files do
45
- _s3 = establish_connection!
46
-
47
- files.each do |file|
48
- if !File.directory?(file)
49
- path = base_file_path(file)
50
- path.gsub!(/^\//, "") # Remove preceding slash for S3
51
-
52
- contents = case File.extname(path)
53
- open(file)
54
-
55
- types = MIME::Types.type_for(File.basename(file))
56
- if types.empty?
57
- options = {
58
- :acl => :public_read
59
- }
60
- else
61
- options = {
62
- :acl => :public_read,
63
- :content_type => types[0]
64
- }
65
- end
66
- options.merge!(bucket_write_options)
67
- _s3.buckets[bucket].objects[path].write(contents, options)
68
- end
69
- end
70
- end
71
- end
72
-
73
- task :update do
74
- s3.upload_files
75
- end
76
-
77
- task :restart do; end
78
- end
79
- end