capistrano-s3 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_STORE
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ LICENSE
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2012-2013 Jean-Philippe Doyle, Hookt Studios inc., Joshua Delsman/miomoba, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # s3-static-site
2
+
3
+ > Allows static websites deployment to Amazon S3 website buckets using Capistrano.
4
+
5
+ ## Hosting your website with Amazon S3
6
+
7
+ S3 provides special website enabled buckets that allows you to deliver website pages directly from S3.
8
+ The most important difference is that theses buckets serves an index document (ex. index.html) whenever a user specifies the URL for the root of your website, or a subfolder. And you can point your domain name directly to the S3 bucket cname.
9
+
10
+ To learn how to setup your website bucket, see [Amazon Documentation](http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?HostingWebsiteQS1.html).
11
+
12
+ ## Getting started
13
+
14
+ Setup capistrano, create a public folder and set your S3 bucket configurations in `deploy.rb`.
15
+
16
+ $ capify .
17
+ $ mkdir public
18
+ $ touch config/deploy.rb #see config instructions bellow
19
+ $ cap deploy
20
+
21
+ ### Configuring deployment
22
+
23
+ s3-static-site overrides the default Capistrano recipes for Rails projects with its own simple s3 publishing scripts.
24
+
25
+ ```ruby
26
+ # config/deploy.rb
27
+ require 's3-static-site'
28
+
29
+ set :bucket, "www.cool-website-bucket.com"
30
+ set :access_key_id, "CHANGETHIS"
31
+ set :secret_access_key, "CHANGETHIS"
32
+ ```
33
+
34
+ If you want to deploy to multiple buckets, have a look at
35
+ [Capistrano multistage](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension)
36
+ and configure a bucket per stage configuration.
37
+
38
+ #### S3 write options
39
+
40
+ s3-static-site sets files `:content_type` and `:acl` to `:public_read`, add or override with :
41
+
42
+ ```ruby
43
+ set :bucket_write_options, {
44
+ cache_control: "max-age=94608000, public"
45
+ }
46
+ ```
47
+
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
+
50
+ ### Advanced static website generation & assets management
51
+
52
+ If you wish to manage your assets with a packaging system, a simple way do to it
53
+ is using a combination of :
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).
61
+
62
+ Once you get this together, add a capistrano task to trigger website generation before deploy :
63
+
64
+ ```ruby
65
+ # config/deploy.rb
66
+ before 'deploy' do
67
+ run_locally "bundle exec ruby app.rb"
68
+ run_locally "bundle exec rake assetpack:build"
69
+ end
70
+ ```
71
+
72
+ ## Copyright
73
+
74
+ Copyright (c) 2012 Josh Delsman & miomoba, Inc. See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'rake'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Jean-Philippe Doyle","Josh Delsman"]
5
+ gem.email = ["jeanphilippe.doyle@hooktstudios.com"]
6
+ gem.description = "Using Ruby and Capistrano, build and deploy a static website to Amazon S3"
7
+ gem.summary = "Using Ruby and Capistrano, build and deploy a static website to Amazon S3"
8
+ gem.homepage = "http://github.com/hooktstudios/capistrano-s3"
9
+ gem.licenses = ["MIT"]
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "capistrano-s3"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = "0.2.1"
16
+
17
+ # Gem dependencies
18
+ gem.add_dependency("aws-sdk")
19
+ gem.add_dependency("capistrano")
20
+ gem.add_dependency("mime-types")
21
+ end
@@ -0,0 +1,79 @@
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
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jean-Philippe Doyle
9
+ - Josh Delsman
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: aws-sdk
17
+ prerelease: false
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ none: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ none: false
31
+ - !ruby/object:Gem::Dependency
32
+ name: capistrano
33
+ prerelease: false
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ none: false
40
+ type: :runtime
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ none: false
47
+ - !ruby/object:Gem::Dependency
48
+ name: mime-types
49
+ prerelease: false
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ none: false
56
+ type: :runtime
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ none: false
63
+ description: Using Ruby and Capistrano, build and deploy a static website to Amazon
64
+ S3
65
+ email:
66
+ - jeanphilippe.doyle@hooktstudios.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - capistrano-s3.gemspec
77
+ - lib/capistrano-s3.rb
78
+ homepage: http://github.com/hooktstudios/capistrano-s3
79
+ licenses:
80
+ - MIT
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ none: false
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ none: false
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.24
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Using Ruby and Capistrano, build and deploy a static website to Amazon S3
103
+ test_files: []
104
+ has_rdoc: