mina-s3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mina-s3.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stas SUȘCOV
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # AWS S3 support for Mina
2
+
3
+ You can use mina now to deploy static websites to AWS S3.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mina-s3'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mina-s3
18
+
19
+ ## Usage
20
+
21
+ Use mina to generate the config file:
22
+
23
+ $ bundle exec mina init
24
+
25
+ Load the S3 task:
26
+
27
+ ```ruby
28
+ require 'mina/s3'
29
+ ```
30
+
31
+ Add some settings to the `config/deploy.rb` file.
32
+
33
+ ```ruby
34
+ set :s3_bucket_name, 'mina'
35
+ set :aws_access_key_id, 'YOUR_KEY'
36
+ set :aws_secret_access_key, 'YOUR_SECRET'
37
+ set :s3_files_pattern, ['assets/**/**', '*.html']
38
+ ```
39
+
40
+ Update `deploy` task to invoke `aws:s3:deploy` task:
41
+
42
+ ```ruby
43
+ task :deploy do
44
+ invoke :'aws:s3:deploy'
45
+ end
46
+ ```
47
+
48
+ Deploy it!
49
+
50
+ $ bundle exec mina deploy
51
+
52
+ Use `--verbose` flag if you want to see the AWS logger calls.
53
+
54
+ To clear the bucket, use the `aws:s3:empty` task:
55
+
56
+ $ bundle exec mina aws:s3:empty
57
+
58
+ Thats it.
59
+
60
+ ## Todo
61
+
62
+ Write some tests.
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
71
+
72
+ ## Thanks and credits
73
+
74
+ This was inspired from Josh Delsman work on [s3-static-site](https://github.com/voxxit/s3-static-site) gem.
75
+
76
+ Huge thanks to [mina](https://github.com/nadarei/mina) developers for the awesome tool.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/mina/s3.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'aws/s3'
2
+ require 'mime/types'
3
+ require 'logger'
4
+
5
+ # # Modules: AWS S3
6
+ # Adds settings and tasks for uploading to AWS S3
7
+ #
8
+ # require 'mina/s3'
9
+ #
10
+ # ## Settings
11
+ # Any and all of these settings can be overwritten in your `deploy.rb`.
12
+ #
13
+ # ### s3_bucket_name
14
+ # Sets the S3 bucket name
15
+
16
+ set_default :s3_bucket_name, domain
17
+
18
+ # ### aws_access_key_id
19
+ # Sets the default AWS S3 access key ID
20
+
21
+ set_default :aws_access_key_id, 'CHANGE THIS'
22
+
23
+ # ### aws_secret_access_key
24
+ # Sets the default AWS S3 secret access key
25
+
26
+ set_default :aws_secret_access_key, 'CHANGE THIS'
27
+
28
+ # ### s3_files_pattern
29
+ # Sets the default pattern to match files needed to be uploaded
30
+ # Take a look at `Dir.glob` for examples
31
+ # Defaults to: ['assets/**/**', '*.html', '*.css']
32
+
33
+ set_default :s3_files_pattern, ['assets/**/**', '*.html', '*.css']
34
+
35
+ # ### s3_move_from_to
36
+ # Renames local files location
37
+ # Ex.: {:from => 'public/', :to => ''}
38
+ # will rename everything in public dir to root dir on S3
39
+ # Defaults to: false
40
+
41
+ set_default :s3_move_from_to, false
42
+
43
+ # ### s3
44
+ # Sets the s3 connection object
45
+
46
+ set_default :s3, proc{
47
+ # Send logging to STDOUT
48
+ AWS.config(:logger => Logger.new(STDOUT)) if verbose_mode?
49
+
50
+ AWS::S3.new(
51
+ :access_key_id => aws_access_key_id,
52
+ :secret_access_key => aws_secret_access_key
53
+ )
54
+ }
55
+
56
+ # ### s3_bucket
57
+ # Sets the s3 bucket
58
+ set_default :s3_bucket, proc { s3.buckets[s3_bucket_name] }
59
+
60
+ # ## Deploy tasks
61
+ # These tasks are meant to be invoked inside deploy scripts, not invoked on
62
+ # their own.
63
+
64
+ namespace 'aws:s3' do
65
+ # ### aws:s3:deploy
66
+ # Starts a deploy to AWS S3
67
+ desc 'Starts a deploy to AWS S3'
68
+ task :deploy do
69
+ print_str '-----> Starting AWS S3 deployment'
70
+ files = Dir.glob(s3_files_pattern).each do |file|
71
+ if !File.directory?(file)
72
+ path = file
73
+
74
+ contents = open(file)
75
+
76
+ # Do some renaming if any
77
+ path.gsub!(s3_move_from_to[:from], s3_move_from_to[:to]) if s3_move_from_to
78
+ # Remove preceding slash for S3
79
+ path.gsub!(/^\//, "")
80
+
81
+ types = MIME::Types.type_for(File.basename(file))
82
+ if types.empty?
83
+ options = { :acl => :public_read }
84
+ else
85
+ options = { :acl => :public_read,:content_type => types[0] }
86
+ end
87
+
88
+ s3_bucket.objects[path].write(contents, options)
89
+ print_str 'Deployed ~> %s%s' % [s3_bucket.url, path]
90
+ end # if
91
+ end # files.each
92
+ end
93
+
94
+ # ### aws:s3:empty
95
+ # Empties bucket of any files
96
+ desc 'Empty the AWS S3 bucket'
97
+ task :empty do
98
+ s3_bucket.clear!
99
+ print_str '-----> Cleaned %s' % s3_bucket.url
100
+ end
101
+ end
data/lib/mina-s3.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Mina
2
+ module S3
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
data/mina-s3.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mina-s3'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'mina-s3'
8
+ gem.version = Mina::S3::VERSION
9
+ gem.authors = ['Stas SUȘCOV']
10
+ gem.email = ['stas@nerd.ro']
11
+ gem.description = %q{Adds AWS S3 support for mina.}
12
+ gem.summary = %q{Deploy to S3 using mina.}
13
+ gem.homepage = 'https://github.com/stas/mina-s3'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'mina'
20
+ gem.add_dependency 'aws-sdk'
21
+ gem.add_dependency 'mime-types'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stas SUȘCOV
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mina
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-sdk
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mime-types
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Adds AWS S3 support for mina.
79
+ email:
80
+ - stas@nerd.ro
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/mina-s3.rb
91
+ - lib/mina/s3.rb
92
+ - mina-s3.gemspec
93
+ homepage: https://github.com/stas/mina-s3
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: 669874291
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: 669874291
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Deploy to S3 using mina.
123
+ test_files: []