s3-deploy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s3-deploy.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec', '2.11.0'
7
+ gem 'rake', '0.9.2.2'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Thomas Fankhauser
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.
@@ -0,0 +1,42 @@
1
+ # S3::Deploy
2
+
3
+ A simply command line tool that uploads all folder contents to an S3 bucket. On re-upload it checks the last modification date and doesn't
4
+ upload files that weren't changed.
5
+
6
+ ## Installation
7
+
8
+ Install it yourself as:
9
+
10
+ $ gem install s3-deploy
11
+
12
+ ## Usage
13
+
14
+ Create a `aws.yml` file on level above the actual upload directory:
15
+
16
+ access_key_id: ABCEDEFGHIJKLMNOP
17
+ secret_access_key: i4t58763g4vlsdvfu34v6z
18
+ s3_endpoint: s3-eu-west-1.amazonaws.com
19
+ bucket: "abucket"
20
+
21
+ Then simply run `s3-deploy` in the folder you want to deploy, e.g.
22
+
23
+ > ll
24
+ total 2
25
+ -rw-r--r--@ 1 tommy staff 150 Dec 12 13:55 aws.yml
26
+ drw-r--r-- 1 tommy staff 746 Dec 12 13:56 public
27
+ > cd public
28
+ > s3-deploy
29
+
30
+ You can also specify a folder and a bucket prefix, if you want:
31
+
32
+ > s3-deploy assets prefix/in/bucket
33
+
34
+ which will upload the `assets` directory to `prefix/in/bucket/assets`.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "./../lib/s3-deploy"
4
+
5
+ source, prefix = ARGV
6
+ S3::Deploy.upload! :source => source, :prefix => prefix
@@ -0,0 +1,74 @@
1
+ require "aws-sdk"
2
+ require "ostruct"
3
+ require "s3-deploy/version"
4
+
5
+ module S3
6
+ module Deploy
7
+ class << self
8
+
9
+ # Loads the aws config from one level up by default
10
+ def config path = "../aws.yml"
11
+ @@config ||= OpenStruct.new(YAML.load_file(path))
12
+ end
13
+
14
+ # Collects all files from the public directory for the upload
15
+ def files source = "."
16
+ Dir["#{source}/**/*"].select{ |path| !File.directory?(path) }
17
+ end
18
+
19
+ # Takes the file list and uploads it to the S3 bucket
20
+ def upload! params = {}
21
+ puts "\nUploading to S3:#{config.bucket}"
22
+ puts "--------------------------------"
23
+
24
+ params[:source] ||= "."
25
+ params[:prefix] ||= ""
26
+ files(params[:source]).each do |file|
27
+
28
+ # Build path and check if file was updated locally
29
+ file_without_source = file.gsub("#{params[:source]}/", "")
30
+ target = "#{params[:prefix]}#{file_without_source}"
31
+ modified = file_was_updated_locally?(file, target)
32
+
33
+ # Show upload progress
34
+ puts "#{'# ' unless modified}#{file} -> #{target}"
35
+
36
+ # Upload
37
+ write_to_S3(file, target) if modified
38
+ end
39
+
40
+ puts "--------------------------------"
41
+ puts "Done\n"
42
+ end
43
+
44
+ private
45
+
46
+ # Returns or initializes a S3 bucket
47
+ def bucket
48
+ @@bucket ||= begin
49
+ AWS.config(
50
+ :access_key_id => config.access_key_id,
51
+ :secret_access_key => config.secret_access_key,
52
+ :s3_endpoint => config.s3_endpoint
53
+ )
54
+ AWS::S3.new.buckets[config.bucket]
55
+ end
56
+ end
57
+
58
+ # Compares the last modified time of the local file, and the file on the S3
59
+ def file_was_updated_locally?(file, target)
60
+ begin
61
+ File.mtime(file) > bucket.objects[target].last_modified
62
+ rescue
63
+ true
64
+ end
65
+ end
66
+
67
+ # Actually uploads a file to the S3
68
+ def write_to_S3(file, target)
69
+ bucket.objects[target].write(File.open(file, "r"), :acl => :public_read)
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module S3
2
+ module Deploy
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -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 's3-deploy/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "s3-deploy"
8
+ gem.version = S3::Deploy::VERSION
9
+ gem.authors = ["Thomas Fankhauser"]
10
+ gem.email = ["tommy@southdesign.de"]
11
+ gem.description = %q{Uploads a folder to S3. On a new upload it checks if the file was updated locally, else it doesn't upload it}
12
+ gem.summary = %q{Uploads a folder to S3 and keeps it in sync}
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-sdk", "1.6.9"
21
+ end
Binary file
@@ -0,0 +1,30 @@
1
+ require "helper"
2
+
3
+ describe S3::Deploy do
4
+
5
+ context(:aws) do
6
+ it "loads an aws.yml by default path" do
7
+ described_class.config.should be_a(OpenStruct)
8
+ end
9
+
10
+ it "loads an aws.yml by custom path" do
11
+ described_class.config("../aws.yml").should be_a(OpenStruct)
12
+ end
13
+ end
14
+
15
+ context(:files) do
16
+
17
+ it "collects all files on . path" do
18
+ described_class.files.should have_at_least(8).files
19
+ end
20
+
21
+ it "collects all files in spec/files path" do
22
+ described_class.files("spec/files").should have(3).files
23
+ end
24
+
25
+ it "uploads all files to S3" do
26
+ described_class.upload! :source => "spec/files"
27
+ end
28
+ end
29
+
30
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ require 's3-deploy'
3
+
4
+ module Helpers
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include Helpers
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Fankhauser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: &70106577461480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70106577461480
25
+ description: Uploads a folder to S3. On a new upload it checks if the file was updated
26
+ locally, else it doesn't upload it
27
+ email:
28
+ - tommy@southdesign.de
29
+ executables:
30
+ - s3-deploy
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .rspec
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/s3-deploy
41
+ - lib/s3-deploy.rb
42
+ - lib/s3-deploy/version.rb
43
+ - s3-deploy.gemspec
44
+ - spec/.DS_Store
45
+ - spec/deploy_spec.rb
46
+ - spec/files/subfolder/test-3.rb
47
+ - spec/files/test-1.rb
48
+ - spec/files/test-2.rb
49
+ - spec/helper.rb
50
+ homepage: ''
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.11
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Uploads a folder to S3 and keeps it in sync
74
+ test_files:
75
+ - spec/.DS_Store
76
+ - spec/deploy_spec.rb
77
+ - spec/files/subfolder/test-3.rb
78
+ - spec/files/test-1.rb
79
+ - spec/files/test-2.rb
80
+ - spec/helper.rb