s3deploy 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 s3deploy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christopher Lindblom
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,29 @@
1
+ # S3deploy
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 's3deploy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install s3deploy
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/s3deploy ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml"
4
+ require "s3deploy"
5
+
6
+ def import_settings(file)
7
+ settings = YAML::parse_file(file).to_ruby if File.file? file
8
+ return settings && settings.class == Hash ? settings : {}
9
+ end
@@ -0,0 +1,3 @@
1
+ class S3deploy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/s3deploy.rb ADDED
@@ -0,0 +1,101 @@
1
+ require "s3deploy/version"
2
+ require "AWS/S3"
3
+ require "YAML"
4
+
5
+ class S3deploy
6
+
7
+ AWS_REGIONS = %W(us-west-2 us-west-1 eu-west-1 ap-southeast-1 ap-northeast-1 sa-east-1)
8
+
9
+ def initialize(options = {})
10
+ defaults = { "path" => ".", "remote_path" => "" }
11
+ @options = defaults.merge(options)
12
+ @options.merge! import_settings(File.expand_path("~/.s3deploy/.s3deploy.yml"))
13
+ @options.merge! import_settings(File.expand_path("./.s3deploy.yml"))
14
+
15
+ puts @options
16
+ raise "No AWS credentials given." unless @options["aws_key"] && @options["aws_secret"]
17
+
18
+ set_aws_region(@options["aws_region"]) if @options["aws_region"]
19
+
20
+ AWS::S3::Base.establish_connection!(
21
+ :access_key_id => @options["aws_key"],
22
+ :secret_access_key => @options["aws_secret"]
23
+ )
24
+
25
+ puts "Will deploy to #{@options["aws_bucket"]}"
26
+ end
27
+
28
+ def deploy
29
+
30
+ raise "No bucket selected." unless @options["aws_bucket"]
31
+ bucket = AWS::S3::Bucket.find @options["aws_bucket"]
32
+
33
+ path = File.expand_path(@options["path"])
34
+ puts "path: #{path}"
35
+ raise "#{@options["path"]} is not a path." unless File.directory? path
36
+
37
+ files = all_files(path).map { |f| f.gsub(/^#{path}\//, "")}
38
+
39
+ files.each do |file|
40
+ full_path = (path + "/" + file).gsub( /\/\//, "/")
41
+ full_remote_path = (@options["remote_path"] + "/" + file).gsub( /\/\//, "/").gsub( /(^\/)|(\/$)/, "")
42
+ upload_file(full_path, full_remote_path)
43
+ end
44
+
45
+ end
46
+
47
+ def upload_file(local, remote)
48
+ AWS::S3::S3Object.store(remote, open(local), @options["aws_bucket"])
49
+ puts "Uploading #{local} to #{remote}"
50
+ end
51
+
52
+ def self.install_config(default = false)
53
+ install_path = default ? File.expand_path("~/.s3deploy/.s3deploy.yml") : File.expand_path("./.s3deploy.yml")
54
+
55
+ raise "Configuration file already exist." if File.exist? install_path
56
+
57
+ if default
58
+ `mkdir -p #{File.dirname(install_path)}` unless File.directory? File.dirname(install_path)
59
+ end
60
+
61
+ `cp #{File.dirname(File.expand_path(__FILE__)) + "/.s3deploy.yml"} #{install_path}`
62
+
63
+ puts "A configuration file has been created at #{install_path}"
64
+ end
65
+
66
+ def all_files(path = ".")
67
+ files = []
68
+ Dir.new(path).each do |row|
69
+ next if %W{. .. .git}.include? row
70
+
71
+ full_path = "#{path}/#{row}"
72
+
73
+ if File.directory?(full_path)
74
+ files |= all_files(full_path)
75
+ else
76
+ files << full_path
77
+ end
78
+ end
79
+ files
80
+ end
81
+
82
+ def import_settings(file)
83
+ settings = YAML::parse_file(file).to_ruby if File.file? file
84
+ if settings && settings.class == Hash
85
+ settings.delete_if { |k,v| k != "aws_region" && v.nil? }
86
+ else
87
+ Hash.new
88
+ end
89
+ end
90
+
91
+ def set_aws_region(region)
92
+
93
+ unless AWS_REGIONS.include? region.downcase
94
+ raise "#{region} is not a valid region, please select from #{AWS_REGIONS.join(", ")} or leave it blank for US Standard."
95
+ end
96
+
97
+ AWS::S3::DEFAULT_HOST.replace "s3-#{region}.amazonaws.com"
98
+
99
+ end
100
+
101
+ end
data/s3deploy.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 's3deploy/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "s3deploy"
8
+ gem.version = S3deploy::VERSION
9
+ gem.authors = ["Christopher Lindblom"]
10
+ gem.email = ["chris@topher.se"]
11
+ gem.description = %q{Deploy static websites to Amazon S3}
12
+ gem.summary = %q{Deploy static websites to Amazon S3}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency("aws-s3")
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Lindblom
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-s3
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
+ description: Deploy static websites to Amazon S3
31
+ email:
32
+ - chris@topher.se
33
+ executables:
34
+ - s3deploy
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/s3deploy
44
+ - lib/s3deploy.rb
45
+ - lib/s3deploy/version.rb
46
+ - s3deploy.gemspec
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Deploy static websites to Amazon S3
71
+ test_files: []