capistrano_s3 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -14,18 +14,26 @@ If the tarball is already in S3 (from a previous deployment, say to a staging in
14
14
  = Installation
15
15
  gem install capistrano_s3
16
16
 
17
+ = Usage
18
+ Please read carefully if upgrading from 0.1 as the options have changed.
19
+
17
20
  To use it, specify properties in <tt>config/deploy.rb</tt>:
18
21
  set :deploy_via, :s3_bucket
19
- set :deploy_s3_bucket, 'com.example.releases' # The name of the S3 bucket that should get releases
20
22
  s3_config = YAML::load(ERB.new(IO.read("secret/s3.yml")).result) # Follow this pattern and don't ckin your secrets
21
- # s3_config = { 'AWS_ACCOUNT_NUMBER' => '1234-5678-9012', 'AWS_ACCESS_KEY_ID' => 'ABCDEFGHIJKLMNOPQRST', 'AWS_SECRET_ACCESS_KEY' => 'abcdefghijklmnopqrstuvwxyz01234567890ABC' }
23
+ # s3_config = {
24
+ # 'access_key_id' => 'ABCDEFGHIJKLMNOPQRST',
25
+ # 'secret_access_key' => 'abcdefghijklmnopqrstuvwxyz01234567890ABC' ,
26
+ # 'bucket_name' => 'com.example.releases' # The name of the S3 bucket that should get releases
27
+ # }
22
28
  set :s3_config, s3_config
23
29
 
24
30
  Now regular capistrano deployment tasks will go through S3
25
31
 
26
32
  = About
27
33
 
28
- Rubyforge Project:: http://rubyforge.org/projects/capistrano-s3
29
- Author:: Bill Kirtley - bill.kirtley at [nospam] gmail dt com
34
+ GitHub Project:: http://github.com/Viximo/capistrano-s3
35
+ Authors::
36
+ Bill Kirtley - bill.kirtley at [nospam] gmail dt com
37
+ Matt Griffin - matt@griffinonline.org
30
38
  License:: Distributed under MIT License
31
39
  Copyright:: 2008 Bill Kirtley, Virosity Inc.
@@ -1,11 +1,9 @@
1
1
  require 'capistrano/recipes/deploy/strategy/copy'
2
- require 'fileutils'
3
- require 'tempfile' # Dir.tmpdir
4
2
 
5
3
  #implementing a capistrano deploy strategy that:
6
4
  # - Expects a deploy_bucket it can read from and write to
7
5
  # - Uses configuration[:s3_config] to find creds
8
- # - Names releases {application}_{revision}.tgz
6
+ # - Names releases {package_prefix}_{revision}.tgz
9
7
  # - Looks in the bucket for a file with that name - skip to actual deployment if found
10
8
  # - Checks out the specified revision, bundles it up, and pushes to the S3 bucket
11
9
  # - depends on the s3cmd command, perhaps installed with `gem install s3sync`
@@ -14,6 +12,9 @@ require 'tempfile' # Dir.tmpdir
14
12
  # Distributed via MIT license
15
13
  # Feedback appreciated: bill at [nospam] virosity dt com
16
14
 
15
+ # Note: this fork depends on a commit in this Capistrano fork which has not yet been pulled in
16
+ # http://github.com/Viximo/capistrano/commit/e9aa71293ae7d4150627891e3633b9e7bfecd437
17
+
17
18
  module Capistrano
18
19
  module Deploy
19
20
  module Strategy
@@ -21,15 +22,15 @@ module Capistrano
21
22
  class S3Bucket < Copy
22
23
 
23
24
  def deploy!
24
- logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
25
- logger.debug "#{configuration[:release_path]} #{File.basename(configuration[:release_path])}"
26
- put_package
27
-
28
- run "#{aws_environment} s3cmd get #{bucket_name}:#{package_name} #{remote_filename}"
29
- run "mkdir #{configuration[:release_path]} && cd #{configuration[:release_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
30
- logger.debug "done!"
25
+ if bucket_includes_package
26
+ logger.debug "#{package_name} already in bucket #{bucket_name}"
27
+ distribute!
28
+ else
29
+ logger.debug "#{package_name} not found in bucket #{bucket_name} so ckout to add it"
30
+ super
31
+ end
31
32
  end
32
-
33
+
33
34
  #!! implement me!
34
35
  # Performs a check on the remote hosts to determine whether everything
35
36
  # is setup such that a deploy could succeed.
@@ -37,44 +38,59 @@ module Capistrano
37
38
  # end
38
39
 
39
40
  private
41
+ def distribute!
42
+ put_package unless bucket_includes_package
43
+ run "#{s3cmd} get #{bucket_name}:#{package_name} #{remote_filename}"
44
+ run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
45
+
46
+ # Archive may have been cached from a previous release so rename the resulting dir
47
+ run "cd #{configuration[:releases_path]} && mv #{release_name} #{configuration[:release_path]}"
48
+ logger.debug "done!"
49
+ end
50
+
40
51
  def aws_environment
41
- @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']}"
52
+ @aws_environment ||= "AWS_ACCESS_KEY_ID=#{configuration[:s3_config]['access_key_id']} AWS_SECRET_ACCESS_KEY=#{configuration[:s3_config]['secret_access_key']}"
42
53
  end
54
+
55
+ def s3cmd
56
+ "env #{aws_environment} s3cmd"
57
+ end
58
+
43
59
  # Responsible for ensuring that the package for the current revision is in the bucket
44
60
  def put_package
45
- set :release_name, revision
46
- logger.debug "#{package_name} already in bucket #{bucket_name}" and return if bucket_includes_package
47
- logger.debug "#{package_name} not found in bucket #{bucket_name} so ckout to add it"
48
-
49
- # Do the checkout locally
50
- system(command)
51
- File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
52
-
53
- # Compress it
54
- logger.trace "compressing in #{destination}"
55
- logger.trace compress('*', package_path).join(" ")
56
-
57
- Dir.chdir(destination) { system(compress('*', package_path).join(" ")) }
58
-
59
- # Put to S3
60
61
  logger.trace "pushing to S3 bucket #{bucket_name} key #{package_name}"
61
- system("s3cmd put #{bucket_name}:#{package_name} #{package_path}")
62
+ system("#{s3cmd} put #{bucket_name}:#{package_name} #{filename}")
62
63
  end
63
64
 
64
65
  def bucket_includes_package
65
- /#{package_name}/.match(`s3cmd list #{bucket_name}:#{package_name}`)
66
+ if @bucket_includes_package.nil?
67
+ @bucket_includes_package = /#{package_name}/.match(`#{s3cmd} list #{bucket_name}:#{package_name}`)
68
+ @bucket_includes_package = false if @bucket_includes_package.nil?
69
+ end
70
+
71
+ @bucket_includes_package
66
72
  end
67
73
 
74
+ def release_name
75
+ "#{configuration[:s3_config]['package_prefix']}_#{revision}"
76
+ end
77
+
68
78
  def package_name
69
- @package_name ||= "#{configuration[:application]}_#{revision}.tgz"
79
+ @package_name ||= "#{release_name}.#{compression.extension}"
70
80
  end
71
81
 
72
- def package_path
73
- @package_path ||= File.join(tmpdir, package_name)
82
+ # Copy the checked out project to a directory using the name of the revision, not the release
83
+ # since the archive will be cached
84
+ def destination
85
+ @destination ||= File.join(tmpdir, release_name)
86
+ end
87
+
88
+ def remote_filename
89
+ @remote_filename ||= @remote_filename ||= File.join(remote_dir, package_name)
74
90
  end
75
91
 
76
92
  def bucket_name
77
- configuration[:deploy_s3_bucket]
93
+ configuration[:s3_config]['bucket_name']
78
94
  end
79
95
 
80
96
  def bucket
@@ -83,13 +99,13 @@ module Capistrano
83
99
 
84
100
  def initialize(config={})
85
101
  super(config)
86
-
102
+
87
103
  raise "Failed to find :s3_config" unless configuration[:s3_config]
88
- # Annoying that merge doesnt work because ENV isn't really a Hash:
89
- # ENV.merge(configuration[:s3_config])
90
- configuration[:s3_config].each_pair { |name, value| ENV[name] = value }
104
+
105
+ # Set defaults
106
+ configuration[:s3_config]['package_prefix'] ||= 'release'
107
+ configuration[:s3_config]['bucket_name'] ||= 'capistrano_s3_deploy'
91
108
  end
92
-
93
109
  end
94
110
  end
95
111
  end
@@ -1,8 +1,8 @@
1
- module Capistrano_S3 #:nodoc:
1
+ module CapistranoS3 #:nodoc:
2
2
  module Version #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 2
4
+ MINOR = 2
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -16,9 +16,8 @@ context "Capistrano::Deploy::Strategy::S3Bucket" do
16
16
  :release_path => "/u/apps/test/releases/1234567890",
17
17
  :real_revision => "154",
18
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' }
19
+ :s3_config => {'access_key_id' => 'ABCDEFGHIJKLMNOPQRST',
20
+ 'secret_access_key' => 'abcdefghijklmnopqrstuvwxyz01234567890ABC' }
22
21
  }
23
22
  @source = mock("source")
24
23
  @config.stubs(:source).returns(@source)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano_s3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bill Kirtley
@@ -16,29 +16,30 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-14 00:00:00 -05:00
19
+ date: 2011-03-30 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: capistrano
24
23
  prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ type: :runtime
25
+ name: capistrano
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
27
  none: false
27
28
  requirements:
28
29
  - - ">="
29
30
  - !ruby/object:Gem::Version
30
- hash: 11
31
+ hash: 51
31
32
  segments:
32
33
  - 2
33
- - 1
34
- - 0
35
- version: 2.1.0
36
- type: :runtime
37
- version_requirements: *id001
34
+ - 5
35
+ - 20
36
+ version: 2.5.20
37
+ requirement: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: s3sync
40
39
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ type: :runtime
41
+ name: s3sync
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
43
  none: false
43
44
  requirements:
44
45
  - - ">="
@@ -47,12 +48,9 @@ dependencies:
47
48
  segments:
48
49
  - 0
49
50
  version: "0"
50
- type: :runtime
51
- version_requirements: *id002
51
+ requirement: *id002
52
52
  description: A deployment strategy for capistrano using S3
53
- email:
54
- - bill.kirtley@gmail.com
55
- - matt@griffinonline.org
53
+ email: matt@griffinonline.org
56
54
  executables: []
57
55
 
58
56
  extensions: []
@@ -67,7 +65,7 @@ files:
67
65
  - README
68
66
  - MIT-LICENSE
69
67
  has_rdoc: true
70
- homepage: http://github.com/cluesque/capistrano-s3
68
+ homepage: http://github.com/Viximo/capistrano-s3
71
69
  licenses: []
72
70
 
73
71
  post_install_message:
@@ -95,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
93
  version: "0"
96
94
  requirements: []
97
95
 
98
- rubyforge_project: capistrano_s3
96
+ rubyforge_project:
99
97
  rubygems_version: 1.3.7
100
98
  signing_key:
101
99
  specification_version: 3