git-2-s3 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kurt Didenhover <kdidenhover@gmail.com>
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.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ = Introduction
2
+
3
+ This gem is based off of Capistrano_s3 gem found at Github. This gem pushes each file in your repository to s3 whereas the Capistrano_s3 gem compresses your repository and pushes to s3 as a single compressed file.
4
+
5
+ Git-2-S3 is a capistrano deployment strategy that will:
6
+
7
+ * git clone locally
8
+ * push the files to S3
9
+ * each server pulls the files from S3
10
+
11
+ This allows one to push a github repository to Amazon's S3 Data storage.
12
+
13
+ = Installation
14
+ gem install git-2-s3
15
+
16
+ To use it, specify properties in <tt>config/deploy.rb</tt>:
17
+ set :deploy_via, :s3_bucket
18
+ set :deploy_s3_bucket, 'com.example.releases' # The name of the S3 bucket that should get releases
19
+ s3_config = YAML::load(ERB.new(IO.read("secret/s3.yml")).result) # Follow this pattern and don't check in your secrets
20
+ # s3_config = { 'AWS_ACCOUNT_NUMBER' => '1234-5678-9012', 'AWS_ACCESS_KEY_ID' => 'ABCDEFGHIJKLMNOPQRST', 'AWS_SECRET_ACCESS_KEY' => 'abcdefghijklmnopqrstuvwxyz01234567890ABC' }
21
+ set :s3_config, s3_config
22
+
23
+ Now regular Capistrano deployment tasks will go to S3
24
+
25
+ = About
26
+
27
+ Author:: Kurt Didenhover - kdidenhover at [nospam] gmail dt com
28
+ License:: Distributed under MIT License
29
+ Copyright:: 2010 Kurt Didenhover
@@ -0,0 +1,88 @@
1
+ require 'capistrano/recipes/deploy/strategy/copy'
2
+ require 'fileutils'
3
+ require 'tempfile' # Dir.tmpdir
4
+
5
+ #implementing a capistrano deploy strategy that:
6
+ # - Expects a deploy_bucket it can read from and write to
7
+ # - Uses configuration[:s3_config] to find creds
8
+ # - Checks out the specified revision, and pushes each file to the S3 bucket
9
+ # - depends on the s3cmd command, perhaps installed with `gem install s3sync`
10
+
11
+ # Copyright 2010 Kurt Didenhover
12
+ # Distributed via MIT license
13
+ # Feedback appreciated: kdidenhover at [nospam] gmail dt com
14
+
15
+ module Capistrano
16
+ module Deploy
17
+ module Strategy
18
+
19
+ class S3Bucket < Copy
20
+
21
+ def deploy!
22
+ logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
23
+ logger.debug "#{configuration[:release_path]} #{File.basename(configuration[:release_path])}"
24
+ put_package
25
+
26
+ run "#{aws_environment} s3cmd get #{bucket_name}:#{package_name} #{remote_filename}"
27
+ run "mkdir #{configuration[:release_path]} && cd #{configuration[:release_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
28
+ logger.debug "done!"
29
+ end
30
+
31
+ #!! implement me!
32
+ # Performs a check on the remote hosts to determine whether everything
33
+ # is setup such that a deploy could succeed.
34
+ # def check!
35
+ # end
36
+
37
+ private
38
+ def aws_environment
39
+ @aws_environment ||= "AWS_ACCOUNT_NUMBER=#{configuration[:s3_config]['AWS_ACCOUNT_NUMBER']} AWS_ACCESS_KEY_ID=#{configuration[:s3_config]['AWS_ACCESS_KEY_ID']} AWS_SECRET_ACCESS_KEY=#{configuration[:s3_config]['AWS_SECRET_ACCESS_KEY']}"
40
+ end
41
+ # Responsible for ensuring that the package for the current revision is in the bucket
42
+ def put_package
43
+ set :release_name, revision
44
+
45
+ # Do the checkout locally
46
+ system(command)
47
+
48
+ Dir.chdir(destination)
49
+
50
+ # Put to S3
51
+ logger.trace "pushing repo contents to S3 bucket #{bucket_name}"
52
+ Dir.foreach(destination) do |entry|
53
+ name = File.basename(entry)
54
+ next if name == "." || name == ".." || name == ".git"
55
+ system("s3cmd put #{bucket_name}:#{name} #{package_path}")
56
+ end
57
+
58
+ end
59
+
60
+ def package_name
61
+ @package_name ||= "#{configuration[:application]}_#{revision}.tgz"
62
+ end
63
+
64
+ def package_path
65
+ @package_path ||= File.join(tmpdir, package_name)
66
+ end
67
+
68
+ def bucket_name
69
+ configuration[:deploy_s3_bucket]
70
+ end
71
+
72
+ def bucket
73
+ @bucket ||= Bucket.find(bucket_name) or raise "Failed to find bucket #{configuration[:deploy_s3_bucket]}"
74
+ end
75
+
76
+ def initialize(config={})
77
+ super(config)
78
+
79
+ raise "Failed to find :s3_config" unless configuration[:s3_config]
80
+ # Annoying that merge doesnt work because ENV isn't really a Hash:
81
+ # ENV.merge(configuration[:s3_config])
82
+ configuration[:s3_config].each_pair { |name, value| ENV[name] = value }
83
+ end
84
+
85
+ end
86
+ end
87
+ end
88
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Git_2_S3 #:nodoc:
2
+ module Version #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ require 'capistrano/logger'
4
+ require 'capistrano/recipes/deploy/strategy/s3_bucket'
5
+ require 'stringio'
6
+
7
+ context "Capistrano::Deploy::Strategy::S3Bucket" do
8
+ def setup
9
+ logger = Capistrano::Logger.new(:output => StringIO.new)
10
+ # Uncomment this line to see the output a cap user would see for debugging
11
+ logger = Capistrano::Logger.new
12
+ logger.level = Capistrano::Logger::MAX_LEVEL
13
+ @config = { :application => "testapp",
14
+ :logger => logger,
15
+ :releases_path => "/u/apps/test/releases",
16
+ :release_path => "/u/apps/test/releases/1234567890",
17
+ :real_revision => "154",
18
+ :deploy_s3_bucket => 'com.example.bucket',
19
+ :s3_config => {'AWS_ACCOUNT_NUMBER' => '1234-5678-9012',
20
+ 'AWS_ACCESS_KEY_ID' => 'ABCDEFGHIJKLMNOPQRST',
21
+ 'AWS_SECRET_ACCESS_KEY' => 'abcdefghijklmnopqrstuvwxyz01234567890ABC' }
22
+ }
23
+ @source = mock("source")
24
+ @config.stubs(:source).returns(@source)
25
+ @config.stubs(:set)
26
+ @strategy = Capistrano::Deploy::Strategy::S3Bucket.new(@config)
27
+ Dir.stubs(:tmpdir).returns("/tmp/dir")
28
+ end
29
+
30
+ specify "does push to S3" do
31
+ @strategy.expects(:`).returns("--------------------\n")
32
+ prepare_deploy
33
+ @source.expects(:checkout).with("154", "/tmp/dir/1234567890").returns(:local_checkout)
34
+ @strategy.expects(:system).with(:local_checkout)
35
+ Dir.expects(:chdir).with("/tmp/dir/1234567890").yields
36
+ @strategy.expects(:system).with('s3cmd put com.example.bucket:testapp_154.tgz /tmp/dir/testapp_154.tgz')
37
+ @strategy.deploy!
38
+ end
39
+
40
+ private
41
+
42
+ def aws_credential_envs
43
+ "AWS_ACCOUNT_NUMBER=1234-5678-9012 AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOPQRST AWS_SECRET_ACCESS_KEY=abcdefghijklmnopqrstuvwxyz01234567890ABC"
44
+ end
45
+
46
+ # These are expected for any deploy
47
+ def prepare_deploy
48
+ @strategy.expects(:run).with("#{aws_credential_envs} s3cmd get com.example.bucket:testapp_154.tgz /tmp/1234567890.tar.gz")
49
+ @strategy.expects(:run).with("mkdir /u/apps/test/releases/1234567890 && cd /u/apps/test/releases/1234567890 && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
50
+ end
51
+
52
+ end
53
+
54
+
@@ -0,0 +1,18 @@
1
+ $:.unshift 'lib/', File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'rubygems'
4
+
5
+ try = proc do |library, version|
6
+ begin
7
+ dashed = library.gsub('/','-')
8
+ require library
9
+ gem dashed, version
10
+ rescue LoadError
11
+ puts "=> You need the #{library} gem to run these tests.",
12
+ "=> $ sudo gem install #{dashed}"
13
+ exit
14
+ end
15
+ end
16
+
17
+ try['test/spec', '>= 0.3']
18
+ try['mocha', '>= 0.4']
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-2-s3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Kurt Didenhover
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-12 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 0
34
+ version: 2.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: s3sync
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: A deployment strategy that takes a github repository and pushes the files into an S3 bucket using capistrano
52
+ email: kdidenhover@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - lib/capistrano/recipes/deploy/strategy/s3_bucket.rb
61
+ - lib/version.rb
62
+ - test/deploy_s3_bucket_test.rb
63
+ - test/test_helper.rb
64
+ - README
65
+ - MIT-LICENSE
66
+ has_rdoc: true
67
+ homepage: http://github.com/heyaustria/git-2-s3
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.7
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A deployment strategy to S3 from github using capistrano
100
+ test_files: []
101
+