s3-static-site 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "aws-s3"
4
+ gem "capistrano"
5
+ gem "haml"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aws-s3 (0.6.2)
5
+ builder
6
+ mime-types
7
+ xml-simple
8
+ builder (3.0.0)
9
+ capistrano (2.5.19)
10
+ highline
11
+ net-scp (>= 1.0.0)
12
+ net-sftp (>= 2.0.0)
13
+ net-ssh (>= 2.0.14)
14
+ net-ssh-gateway (>= 1.0.0)
15
+ git (1.2.5)
16
+ haml (3.0.25)
17
+ highline (1.6.1)
18
+ jeweler (1.5.2)
19
+ bundler (~> 1.0.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ mime-types (1.16)
23
+ net-scp (1.0.4)
24
+ net-ssh (>= 1.99.1)
25
+ net-sftp (2.0.5)
26
+ net-ssh (>= 2.0.9)
27
+ net-ssh (2.1.0)
28
+ net-ssh-gateway (1.0.1)
29
+ net-ssh (>= 1.99.1)
30
+ rake (0.8.7)
31
+ rcov (0.9.9)
32
+ shoulda (2.11.3)
33
+ xml-simple (1.0.14)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ aws-s3
40
+ bundler (~> 1.0.0)
41
+ capistrano
42
+ haml
43
+ jeweler (~> 1.5.2)
44
+ rcov
45
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Josh Delsman
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.
@@ -0,0 +1,65 @@
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.
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake'
13
+ require 'jeweler'
14
+
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "s3-static-site"
17
+ gem.homepage = "http://github.com/voxxit/s3-static-site"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Using Ruby and Capistrano, build and deploy a static website to Amazon S3}
20
+ gem.description = %Q{Using Ruby and Capistrano, build and deploy a static website to Amazon S3}
21
+ gem.email = "jdelsman@voxxit.com"
22
+ gem.authors = ["Josh Delsman"]
23
+ end
24
+
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+
41
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,81 @@
1
+ require 'haml'
2
+ require 'aws/s3'
3
+
4
+ unless Capistrano::Configuration.respond_to?(:instance)
5
+ abort "s3-static-site 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, `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
+ AWS::S3::Base.establish_connection!(
26
+ :access_key_id => access_key_id,
27
+ :secret_access_key => secret_access_key
28
+ )
29
+ end
30
+
31
+ # Deployment recipes
32
+ namespace :deploy do
33
+ namespace :s3 do
34
+ desc "Empties bucket of all files. Caution when using this command, as it cannot be undone!"
35
+ task :empty do
36
+ establish_connection!
37
+
38
+ puts "Emptying bucket..."
39
+
40
+ AWS::S3::Bucket.find(bucket).delete_all
41
+ end
42
+
43
+ desc "Upload files to the bucket in the current state"
44
+ task :upload_files do
45
+ establish_connection!
46
+
47
+ files.each do |file|
48
+ if !File.directory?(file)
49
+ path = base_file_path(file)
50
+
51
+ puts "Uploading #{path}..."
52
+
53
+ contents = case File.extname(path)
54
+ when ".haml"
55
+ path.gsub!(".haml", "")
56
+
57
+ engine = Haml::Engine.new(File.read(file))
58
+ engine.render
59
+ when ".sass"
60
+ path.gsub!(".sass", "")
61
+
62
+ engine = Sass::Engine.new(File.read(file))
63
+ engine.render
64
+ else
65
+ open(file)
66
+ end
67
+
68
+ AWS::S3::S3Object.store(path, contents, bucket, :access => :public_read)
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ task :update do
75
+ s3.empty
76
+ s3.upload_files
77
+ end
78
+
79
+ task :restart do; end
80
+ end
81
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+ require 'shoulda'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+
18
+ require 's3-static-site'
19
+
20
+ class Test::Unit::TestCase
21
+ end
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ class TestS3StaticSite < Test::Unit::TestCase
4
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3-static-site
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Josh Delsman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-22 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: aws-s3
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: haml
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: shoulda
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: bundler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: jeweler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.5.2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rcov
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ description: Using Ruby and Capistrano, build and deploy a static website to Amazon S3
94
+ email: jdelsman@voxxit.com
95
+ executables: []
96
+
97
+ extensions: []
98
+
99
+ extra_rdoc_files:
100
+ - LICENSE.txt
101
+ - README.rdoc
102
+ files:
103
+ - .document
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - Rakefile
109
+ - VERSION
110
+ - lib/s3-static-site.rb
111
+ - test/helper.rb
112
+ - test/test_s3-static-site.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/voxxit/s3-static-site
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 4424967007506553392
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: "0"
137
+ requirements: []
138
+
139
+ rubyforge_project:
140
+ rubygems_version: 1.5.2
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Using Ruby and Capistrano, build and deploy a static website to Amazon S3
144
+ test_files:
145
+ - test/helper.rb
146
+ - test/test_s3-static-site.rb