s3-static-site 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
@@ -0,0 +1,72 @@
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
+ # config/deploy.rb
26
+ require 's3-static-site'
27
+
28
+ set :bucket, "www.cool-website-bucket.com"
29
+ set :access_key_id, "CHANGETHIS"
30
+ set :secret_access_key, "CHANGETHIS"
31
+
32
+ If you want to deploy to multiple buckets, have a look at
33
+ [Capistrano multistage](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension)
34
+ and configure a bucket per stage configuration.
35
+
36
+ #### S3 write options
37
+
38
+ s3-static-site sets files `:content_type` and `:acl` to `:public_read`, add or override with :
39
+
40
+ set :bucket_write_options, {
41
+ cache_control: "max-age=94608000, public"
42
+ }
43
+
44
+ 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.
45
+
46
+ ### Built-in HAML template rendering and SASS compile
47
+
48
+ On deployment, `.haml` and `.sass` are generated and uploaded (source .haml and .sass are not uploaded).
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
+ # config/deploy.rb
65
+ before 'deploy' do
66
+ run_locally "bundle exec ruby app.rb"
67
+ run_locally "bundle exec rake assetpack:build"
68
+ end
69
+
70
+ ## Copyright
71
+
72
+ Copyright (c) 2012 Josh Delsman & miomoba, Inc. See LICENSE.txt for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,5 +1,6 @@
1
1
  require 'haml'
2
2
  require 'aws/s3'
3
+ require 'mime/types'
3
4
 
4
5
  unless Capistrano::Configuration.respond_to?(:instance)
5
6
  abort "s3-static-site requires Capistrano >= 2."
@@ -10,7 +11,8 @@ Capistrano::Configuration.instance(true).load do
10
11
  set(name, *args, &block) if !exists?(name)
11
12
  end
12
13
 
13
- _cset :deployment_path, `pwd`.gsub("\n", "") + "/public"
14
+ _cset :deployment_path, Dir.pwd.gsub("\n", "") + "/public"
15
+ _cset :deploy_to, ""
14
16
 
15
17
  def base_file_path(file)
16
18
  file.gsub(deployment_path, "")
@@ -64,7 +66,20 @@ Capistrano::Configuration.instance(true).load do
64
66
  open(file)
65
67
  end
66
68
 
67
- _s3.buckets[bucket].objects[path].write(contents, :acl => :public_read)
69
+ types = MIME::Types.type_for(File.basename(file))
70
+ if types.empty?
71
+ options = {
72
+ :acl => :public_read
73
+ }
74
+ else
75
+ options = {
76
+ :acl => :public_read,
77
+ :content_type => types[0]
78
+ }
79
+ end
80
+
81
+ target = deploy_to.empty? ? path : File.join(deploy_to, path)
82
+ _s3.buckets[bucket].objects[target].write(contents, options)
68
83
  end
69
84
  end
70
85
  end
@@ -76,4 +91,4 @@ Capistrano::Configuration.instance(true).load do
76
91
 
77
92
  task :restart do; end
78
93
  end
79
- end
94
+ end
@@ -12,10 +12,11 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "s3-static-site"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.2.0"
15
+ gem.version = "0.3.0"
16
16
 
17
17
  # Gem dependencies
18
18
  gem.add_dependency("aws-sdk")
19
19
  gem.add_dependency("capistrano")
20
20
  gem.add_dependency("haml")
21
+ gem.add_dependency("mime-types")
21
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3-static-site
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  type: :runtime
@@ -40,7 +40,7 @@ dependencies:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :runtime
@@ -56,7 +56,23 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mime-types
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '>='
60
76
  - !ruby/object:Gem::Version
61
77
  version: '0'
62
78
  description: Using Ruby and Capistrano, build and deploy a static website to Amazon
@@ -69,9 +85,8 @@ extra_rdoc_files: []
69
85
  files:
70
86
  - .gitignore
71
87
  - Gemfile
72
- - Gemfile.lock
73
88
  - LICENSE.txt
74
- - README.rdoc
89
+ - README.md
75
90
  - Rakefile
76
91
  - VERSION
77
92
  - lib/s3-static-site.rb
@@ -86,19 +101,20 @@ require_paths:
86
101
  required_ruby_version: !ruby/object:Gem::Requirement
87
102
  none: false
88
103
  requirements:
89
- - - ! '>='
104
+ - - '>='
90
105
  - !ruby/object:Gem::Version
91
106
  version: '0'
92
107
  required_rubygems_version: !ruby/object:Gem::Requirement
93
108
  none: false
94
109
  requirements:
95
- - - ! '>='
110
+ - - '>='
96
111
  - !ruby/object:Gem::Version
97
112
  version: '0'
98
113
  requirements: []
99
114
  rubyforge_project:
100
- rubygems_version: 1.8.24
115
+ rubygems_version: 1.8.25
101
116
  signing_key:
102
117
  specification_version: 3
103
118
  summary: Using Ruby and Capistrano, build and deploy a static website to Amazon S3
104
119
  test_files: []
120
+ has_rdoc:
@@ -1,65 +0,0 @@
1
- = s3-static-site
2
-
3
- Allows users to deploy static websites to Amazon S3 using Capistrano.
4
-
5
- == Setup
6
-
7
- In order to get started, you need to install the following gem:
8
-
9
- gem install s3-static-site
10
-
11
- This will install the gem, along with the dependencies: Capistrano 2+ and AWS::S3.
12
-
13
- == Creating a website
14
-
15
- To start a static website, just create a folder somewhere on your hard drive:
16
-
17
- mkdir -p ~/www.tastyrails.com
18
-
19
- Once you do that, you'll need to generate deployment scripts
20
-
21
- cd ~/www.tastyrails.com
22
- capify .
23
- cat /dev/null > config/deploy.rb
24
-
25
- == Configure your deployment
26
-
27
- s3-static-site overrides the default Capistrano recipes for Rails projects with its own scripts. Here's a sample deployment script to get you started:
28
-
29
- require 's3-static-site'
30
-
31
- set :bucket, "www.tastyrails.com"
32
- set :access_key_id, "access-key-id"
33
- set :secret_access_key, "secret-access-key"
34
-
35
- Replace the +access_key_id+ and +secret_access_key+ from the values found in the AWS Management Console.
36
-
37
- == Create your bucket
38
-
39
- If you haven't already created a bucket for use with Amazon S3 static website hosting, you'll need to do this before deployment. Instructions can be found here:
40
-
41
- http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?HostingWebsiteQS1.html
42
-
43
- == Deploying
44
-
45
- After setting up your +config/deploy.rb+ file and creating the bucket with Amazon, you can deploy using the following command:
46
-
47
- cap deploy
48
-
49
- == Rendering with HAML or SASS
50
-
51
- s3-static-site allows you to either upload files to S3 as you'd statically find them on your hard drive, or you can use HAML or SASS to generate HTML using Ruby.
52
-
53
- For HAML generation, append +.haml+ to the end of your file, like:
54
-
55
- index.html.haml
56
-
57
- For SASS:
58
-
59
- stylesheet.css.sass
60
-
61
- When uploaded to S3, the +.haml+ and +.sass+ will be removed, leaving either +index.html+ or +stylesheet.css+.
62
-
63
- == Copyright
64
-
65
- Copyright (c) 2011 Josh Delsman. See LICENSE.txt for details.