opsworks-deploy 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5939f9e0c6486f191a53017f878a64a5933aae16
4
- data.tar.gz: 23df8ddd45c57e62fe927b9cbfbb4e876fc3d183
3
+ metadata.gz: 8500b0b3413c6604a04f213dc9d7ec9e4ba0fef2
4
+ data.tar.gz: 5f95eeac4a9db79e051d5373283fd1529818698f
5
5
  SHA512:
6
- metadata.gz: 5e80fd5f36d9865f8b338ae0e11a4f1b4073ec84c986bc98e3610f320bc4416509caaf8085587d29f1c0e3846ae0cbfaa5c782517e90a6d9be526a04b39c4d22
7
- data.tar.gz: 43aa67dd70cb0a85cf9292253674b3f6d56543e5c5c310067b914d5d66d9005a9a71d2c2190281d1dcedc8762e110e6e26a94925a5c6ffe512be02d9f2bb45f6
6
+ metadata.gz: 5e2cb3109791345ff674c786de567375526034cdd74b5d7721793187ffb8cd2bf5a736cdfe2f9ce7fb1ba2a8b6cb6b8dc446083dec6d57cb1c6a124fe78cb558
7
+ data.tar.gz: 5c3c8387db7972f806889db0d1e3e38f74d9780ed06beee6862c9771a2604d23002587ec8d5f79ecf05fe3aad0de7a0ccc8421d2e475c0736a32a31f65a79682
data/README.md CHANGED
@@ -29,7 +29,7 @@ Or, if you would prefer to add items to config files:
29
29
  config/stacks.json
30
30
 
31
31
  {
32
- "staging": { "stack_id": "...", "app_id": "..." }
32
+ "staging": { "stack_id": "...", "app_id": "...", "custom_json": {} }
33
33
  }
34
34
 
35
35
  ~/.aws_config
@@ -65,3 +65,7 @@ Use rspec for test
65
65
  3. Commit your changes (`git commit -am 'Add some feature'`)
66
66
  4. Push to the branch (`git push origin my-new-feature`)
67
67
  5. Create new Pull Request
68
+
69
+ ## Acknowledgements
70
+
71
+ Thanks to @zacstewart for adding support for custom json.
@@ -2,60 +2,9 @@ require "opsworks/deploy/version"
2
2
  require 'aws-sdk'
3
3
 
4
4
  module Opsworks::Deploy
5
-
6
- require 'opsworks/deploy/railtie' if defined?(Rails)
7
-
8
- def self.wait_on_deployment(deployment)
9
- deployment_id = deployment.data[:deployment_id]
10
- deployment_desc = nil
11
-
12
- while true
13
- deployment_desc = AWS.ops_works.client.describe_deployments(deployment_ids: [deployment_id])
14
-
15
- status = deployment_desc.data[:deployments].first[:status]
16
-
17
- case status
18
- when 'running'
19
- sleep 10
20
- when 'successful'
21
- return true
22
- else
23
- raise "Failed to run deployment: #{deployment_id} - #{status}"
24
- end
25
- end
26
-
27
- return true if deployment_desc.data[:status] == 'successful'
28
- end
29
-
30
- # Look for config/stacks.json or stacks.json
31
- def self.get_config_stacks
32
- cwd = Dir.getwd
33
- files = ["#{cwd}/config/stacks.json","#{cwd}/stacks.json"]
34
-
35
- if !cwd.nil? && cwd.length > 0
36
- files.each do |file|
37
- if File.exists?(file)
38
- return JSON(File.read(file))
39
- end
40
- end
41
- end
5
+ DEPLOYMENT_POLL_INTERVAL = 10
42
6
 
43
- return nil
44
- end
45
-
46
- def self.get_stack(env=nil)
47
-
48
- # First try to get from env, then stack files
49
- if !ENV['STACK_ID'].nil? && !ENV['APP_ID'].nil?
50
- return {stack_id: ENV['STACK_ID'], app_id: ENV['APP_ID']}
51
- elsif stacks = get_config_stacks
52
- raise "Missing stacks configuration for #{env} in stacks.json" if stacks[env].nil?
53
-
54
- return stacks[env]
55
- else
56
- raise "Must set STACK_ID and APP_ID or have config/stacks.json for env `#{env}`"
57
- end
58
- end
7
+ require 'opsworks/deploy/railtie' if defined?(Rails)
59
8
 
60
9
  def self.configure_aws!
61
10
  # First, try to pull these from the environment
@@ -72,28 +21,94 @@ module Opsworks::Deploy
72
21
  raise ArgumentError, "Must set IAM_KEY environment variable" if iam_key.nil? || iam_key.length == 0
73
22
  raise ArgumentError, "Must set IAM_SECRET environment variable" if iam_secret.nil? || iam_secret.length == 0
74
23
 
75
- AWS.config({
76
- access_key_id: iam_key,
77
- secret_access_key: iam_secret,
78
- })
24
+ AWS.config(access_key_id: iam_key, secret_access_key: iam_secret)
79
25
  end
80
26
 
81
27
  def self.deploy(opts={})
82
- opts = {
83
- migrate: true,
84
- wait: false,
85
- env: nil
86
- }.merge(opts)
28
+ Opsworks::Deploy.configure_aws!
29
+ Deployment.new(opts).deploy
30
+ end
87
31
 
88
- stack = Opsworks::Deploy.get_stack(opts[:env]) # Get stack environment
32
+ class Deployment
33
+ attr_reader :client, :deployment, :options
89
34
 
90
- Opsworks::Deploy.configure_aws! # Ensure we are properly configured
91
-
92
- deployment = AWS.ops_works.client.create_deployment( stack_id: stack[:stack_id] || stack['stack_id'], app_id: stack[:app_id] || stack['app_id'], command: {name: 'deploy', args: {"migrate" => [ opts[:migrate] ? "true" : "false"] }} )
35
+ def initialize(options, client = AWS.ops_works.client)
36
+ @options = {
37
+ migrate: true,
38
+ wait: false,
39
+ env: nil
40
+ }.merge(options)
41
+ @client = client
42
+ end
43
+
44
+ def deploy
45
+ @deployment = client.create_deployment(arguments)
46
+ puts @deployment.inspect
47
+ wait_on_deployment if options[:wait]
48
+ end
93
49
 
94
- puts deployment.inspect
50
+ private
95
51
 
96
- Opsworks::Deploy.wait_on_deployment(deployment) if opts[:wait]
52
+ def arguments
53
+ {
54
+ stack_id: configuration['stack_id'],
55
+ app_id: configuration['app_id'],
56
+ command: command
57
+ }.tap do |args|
58
+ args[:custom_json] = custom_json if custom_json?
59
+ end
60
+ end
61
+
62
+ def command
63
+ {name: 'deploy', args: {'migrate' => [options[:migrate] ? 'true' : 'false']}}
64
+ end
65
+
66
+ def custom_json
67
+ configuration['custom_json'].to_json
68
+ end
69
+
70
+ def custom_json?
71
+ configuration.has_key?('custom_json')
72
+ end
73
+
74
+ def configuration
75
+ @configuration ||= if !ENV['STACK_ID'].nil? && !ENV['APP_ID'].nil?
76
+ {'stack_id' => ENV['STACK_ID'], 'app_id' => ENV['APP_ID']}
77
+ elsif stacks = configured_environments
78
+ stacks.fetch(environment) do
79
+ raise "Missing stacks configuration for #{environment} in stacks.json"
80
+ end
81
+ else
82
+ raise "Must set STACK_ID and APP_ID or have config/stacks.json for env `#{environment}`"
83
+ end
84
+ end
85
+
86
+ def environment
87
+ options.fetch(:env)
88
+ end
89
+
90
+ # Look for config/stacks.json or stacks.json
91
+ def configured_environments
92
+ files = Dir['config/stacks.json','stacks.json']
93
+ file = files.first and JSON.parse(File.read(file))
94
+ end
95
+
96
+ def wait_on_deployment
97
+ deployment_id = deployment.data[:deployment_id]
98
+ loop do
99
+ deployment_description = client.describe_deployments(
100
+ deployment_ids: [deployment_id]
101
+ )
102
+ status = deployment_description.data[:deployments].first[:status]
103
+
104
+ case status
105
+ when 'running' then sleep DEPLOYMENT_POLL_INTERVAL
106
+ when 'successful' then break
107
+ else
108
+ raise "Failed to run deployment: #{deployment_id} - #{status}"
109
+ end
110
+ end
111
+ end
97
112
  end
98
113
 
99
114
  end
@@ -1,5 +1,5 @@
1
1
  module Opsworks
2
2
  module Deploy
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Geoff Hayes"]
10
10
  spec.email = ["hayesgm@gmail.com"]
11
11
  spec.description = %q{Quick and easy rake task for deploying to AWS OpsWorks}
12
- spec.summary = %q{A quick rake task that will deploy to AWS OpsWorks. This can be added as a post-step in Continuous Integration. `rake opsworks:deply`}
12
+ spec.summary = %q{A quick rake task that will deploy to AWS OpsWorks. This can be added as a post-step in Continuous Integration. `rake opsworks:deploy`}
13
13
  spec.homepage = "https://github.com/hayesgm/opsworks-deploy"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,12 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'aws-sdk'
21
+ spec.add_runtime_dependency 'aws-sdk', '~> 1.62'
22
22
  spec.add_runtime_dependency 'json'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "json"
28
- spec.add_development_dependency 'aws-sdk'
29
27
  end
@@ -46,7 +46,7 @@ describe 'opsworks:deploy rake task' do
46
46
  ENV['IAM_KEY'] = ENV['IAM_SECRET'] = "a"
47
47
 
48
48
  # Allow file config
49
- expect(File).to receive(:exists?).and_return(true)
49
+ allow(Dir).to receive(:[]).and_return(['config/stacks.json'])
50
50
  expect(File).to receive(:read).and_return(config.to_json)
51
51
 
52
52
  expected_params = { stack_id: "sid", app_id: "aid", command: {name: 'deploy', args: {"migrate" => [ "false" ] } } }
@@ -81,7 +81,7 @@ describe 'opsworks:deploy rake task' do
81
81
  ENV['IAM_KEY'] = ENV['IAM_SECRET'] = "a"
82
82
 
83
83
  # Allow file config
84
- expect(File).to receive(:exists?).and_return(true)
84
+ allow(Dir).to receive(:[]).and_return(['config/stacks.json'])
85
85
  expect(File).to receive(:read).and_return(config.to_json)
86
86
 
87
87
  expected_params = { stack_id: "sid", app_id: "aid", command: {name: 'deploy', args: {"migrate" => [ "true" ] } } }
@@ -103,4 +103,37 @@ describe 'opsworks:deploy rake task' do
103
103
  end
104
104
  end
105
105
 
106
- end
106
+ it "sets deploy's custom_json" do
107
+ config = {
108
+ 'test-5' => {
109
+ 'stack_id' => 'a_stack_id',
110
+ 'app_id' => 'an_app_id',
111
+ 'custom_json' => {'deploy' => {'appshortname' => {'database' => {'adapter' => 'postgresql'}}}}
112
+ }
113
+ }
114
+
115
+ ENV['IAM_KEY'] = 'an_iam_key'
116
+ ENV['IAM_SECRET'] = 'an_iam_secret'
117
+
118
+ allow(Dir).to receive(:[]).and_return(['config/stacks.json'])
119
+ expect(File).to receive(:read).and_return(config.to_json)
120
+ ops_works = double("ops_works")
121
+ client = double("client")
122
+ allow(AWS).to receive(:ops_works).and_return(ops_works)
123
+ allow(ops_works).to receive(:client).and_return(client)
124
+
125
+ expected_params = {
126
+ stack_id: 'a_stack_id',
127
+ app_id: 'an_app_id',
128
+ command: {name: 'deploy', args: {'migrate' => ['true']}},
129
+ custom_json: '{"deploy":{"appshortname":{"database":{"adapter":"postgresql"}}}}'
130
+ }
131
+
132
+ expect(client).to receive(:create_deployment).with(expected_params)
133
+ Rake::Task["opsworks:deploy"].invoke("test-5","true")
134
+
135
+ ENV.delete('IAM_KEY')
136
+ ENV.delete('IAM_SECRET')
137
+ end
138
+
139
+ end
metadata CHANGED
@@ -1,111 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsworks-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Hayes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-05 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.62'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.62'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: json
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: aws-sdk
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
73
+ - - ">="
102
74
  - !ruby/object:Gem::Version
103
75
  version: '0'
104
76
  type: :development
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
- - - '>='
80
+ - - ">="
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  description: Quick and easy rake task for deploying to AWS OpsWorks
@@ -115,8 +87,8 @@ executables: []
115
87
  extensions: []
116
88
  extra_rdoc_files: []
117
89
  files:
118
- - .gitignore
119
- - .rspec
90
+ - ".gitignore"
91
+ - ".rspec"
120
92
  - Gemfile
121
93
  - LICENSE.txt
122
94
  - README.md
@@ -140,21 +112,21 @@ require_paths:
140
112
  - lib
141
113
  required_ruby_version: !ruby/object:Gem::Requirement
142
114
  requirements:
143
- - - '>='
115
+ - - ">="
144
116
  - !ruby/object:Gem::Version
145
117
  version: '0'
146
118
  required_rubygems_version: !ruby/object:Gem::Requirement
147
119
  requirements:
148
- - - '>='
120
+ - - ">="
149
121
  - !ruby/object:Gem::Version
150
122
  version: '0'
151
123
  requirements: []
152
124
  rubyforge_project:
153
- rubygems_version: 2.1.11
125
+ rubygems_version: 2.2.2
154
126
  signing_key:
155
127
  specification_version: 4
156
128
  summary: A quick rake task that will deploy to AWS OpsWorks. This can be added as
157
- a post-step in Continuous Integration. `rake opsworks:deply`
129
+ a post-step in Continuous Integration. `rake opsworks:deploy`
158
130
  test_files:
159
131
  - spec/opsworks_deploy_spec.rb
160
132
  - spec/spec_helper.rb