opsworks-deploy 0.0.1 → 0.0.2

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: e82a69d510154428bd0aef2d0a27b06759025039
4
- data.tar.gz: 206e3ca74911ae1d84507abb5d72e390349c9c61
3
+ metadata.gz: 76638c8dee3a0b74124bb8b8ef20c6b47ab0c3c4
4
+ data.tar.gz: e90b5fddecd07907cd71bfcd70297346bbe1ded4
5
5
  SHA512:
6
- metadata.gz: a1cc54964ac80288d7d64a8d9633b9c706580cb7b876df5bca5d1530fc2aab31c6656c2e8e48572b8850b1fca102bed9ffbbfde93ff149ff11d40650393ea180
7
- data.tar.gz: 76fe3636fcd3c3d8474c331b4311740b64e857fd5474e2529513e21e3984cf257fa3b87be105a24e431c763b73617a85518e094c862d0efb794bc6855ec89a15
6
+ metadata.gz: 7b6627f9265af659444ff8bb0b317458f328b31baaf63feeb39fa405fdf40af08130f5ed2c4e55553c9f6bcf8b3b5228a37ce918d4816855a1da3b326f3743f0
7
+ data.tar.gz: 72c76ee59ceaada2b1b1bb44244fe04271dbf74a14bccac9d601157551ba7ef27ef288e88eb7f844c0591776895032d942b2bed8c4a6fb936ff9aaa4ad559fbf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/README.md CHANGED
@@ -43,6 +43,13 @@ Then run:
43
43
 
44
44
  Note, your IAM keys should only allow deploy access to OpsWorks, but you should never check them into source control.
45
45
 
46
+ ## Testing
47
+
48
+ Use rspec for test
49
+
50
+ rake test
51
+
52
+
46
53
  ## Contributing
47
54
 
48
55
  1. Fork it
@@ -50,7 +57,3 @@ Note, your IAM keys should only allow deploy access to OpsWorks, but you should
50
57
  3. Commit your changes (`git commit -am 'Add some feature'`)
51
58
  4. Push to the branch (`git push origin my-new-feature`)
52
59
  5. Create new Pull Request
53
-
54
- ## TODO
55
-
56
- This is a quick alpha. We need to add test cases to project.
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "rspec/core/rake_task"
1
3
  require "bundler/gem_tasks"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task default: :spec
8
+ task test: :spec
@@ -27,17 +27,17 @@ module Opsworks::Deploy
27
27
  return true if deployment_desc.data[:status] == 'successful'
28
28
  end
29
29
 
30
- def self.get_stack
31
- if ENV['STACK_ID'].present? && ENV['APP_ID'].present?
30
+ def self.get_stack(rails_env=nil)
31
+ if !ENV['STACK_ID'].nil? && !ENV['APP_ID'].nil?
32
32
  return {stack_id: ENV['STACK_ID'], app_id: ENV['APP_ID']}
33
- elsif File.exists?("#{Rails.root}/config/stacks.json")
33
+ elsif defined?(Rails) && !rails_env.nil? && File.exists?("#{Rails.root}/config/stacks.json")
34
34
  # Try to grab from .stack file
35
35
  stacks = JSON(File.read("#{Rails.root}/config/stacks.json"))
36
- raise "Missing stacks configuration for #{RAILS_ENV}" if stacks[RAILS_ENV].empty?
36
+ raise "Missing stacks configuration for #{rails_env}" if stacks[rails_env].empty?
37
37
 
38
- return stacks[RAILS_ENV].with_indifferent_access
38
+ return stacks[rails_env]
39
39
  else
40
- raise "Must set STACK_ID/APP_ID or have config/stacks.json for RAILS_ENV"
40
+ raise "Must set STACK_ID/APP_ID or have config/stacks.json for rails env `#{rails_env}`"
41
41
  end
42
42
  end
43
43
 
@@ -65,14 +65,16 @@ module Opsworks::Deploy
65
65
  def self.deploy(opts={})
66
66
  opts = {
67
67
  migrate: true,
68
- wait: false
68
+ wait: false,
69
+ rails_env: nil
69
70
  }.merge(opts)
70
71
 
71
- stack = Opsworks::Deploy.get_stack # Get stack environment
72
+ stack = Opsworks::Deploy.get_stack(opts[:rails_env]) # Get stack environment
72
73
 
73
74
  Opsworks::Deploy.configure_aws! # Ensure we are properly configured
74
-
75
- deployment = AWS.ops_works.client.create_deployment( stack_id: stack[:stack_id], app_id: stack[:app_id], command: {name: 'deploy', args: {"migrate" => [opts[:migrate] ? "true" : "false"]}} )
75
+ p opts
76
+ p stack
77
+ 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"] }} )
76
78
 
77
79
  puts deployment.inspect
78
80
 
@@ -1,5 +1,5 @@
1
1
  module Opsworks
2
2
  module Deploy
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -2,13 +2,14 @@
2
2
  namespace :opsworks do
3
3
 
4
4
  desc 'Deploy to Opsworks'
5
- task :deploy do |t, args|
6
- RAILS_ENV ||= ENV['RAILS_ENV']
7
- raise "Please set RAILS_ENV environment var" if RAILS_ENV.blank?
5
+ task :deploy, [:rails_env] => :environment do |t, args|
6
+ rails_env = args[:rails_env] || ENV['RAILS_ENV']
8
7
 
9
- puts "Deploying #{RAILS_ENV}..."
8
+ raise ArgumentError, "Please pass rails_env as argument or set RAILS_ENV environment var" if rails_env.nil? || rails_env == ""
9
+
10
+ puts "Deploying #{rails_env}..."
10
11
 
11
- Opsworks::Deploy.deploy
12
+ Opsworks::Deploy.deploy(rails_env: rails_env)
12
13
 
13
14
  puts "Finished successfully"
14
15
  end
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "json"
27
+ spec.add_development_dependency 'aws-sdk'
25
28
  end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'rake'
3
+ require 'json'
4
+ require 'aws'
5
+
6
+ describe 'opsworks:deploy rake task' do
7
+
8
+ before(:all) do
9
+ load File.expand_path("../../lib/opsworks/tasks/opsworks.rake", __FILE__)
10
+ Rake::Task.define_task(:environment)
11
+ end
12
+
13
+ after(:each) do
14
+ Rake::Task["opsworks:deploy"].reenable
15
+ end
16
+
17
+ it "should call invoke with argument when given arg" do
18
+ expect(Opsworks::Deploy).to receive(:deploy).with(rails_env: 'test-1')
19
+ Rake::Task["opsworks:deploy"].invoke('test-1')
20
+ end
21
+
22
+ it "should call invoke with argument when given env" do
23
+ begin
24
+ ENV['RAILS_ENV'] = "test-2"
25
+ expect(Opsworks::Deploy).to receive(:deploy).with(rails_env: 'test-2')
26
+ Rake::Task["opsworks:deploy"].invoke
27
+ ensure
28
+ ENV['RAILS_ENV'] = nil
29
+ end
30
+ end
31
+
32
+ it "should fail when no env supplied deploy" do
33
+ expect { Rake::Task["opsworks:deploy"].invoke() }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it "should run opsworks deploy" do
37
+ begin
38
+ config = {
39
+ 'test-3' => {
40
+ stack_id: 'sid',
41
+ app_id: 'aid'
42
+ }
43
+ }
44
+
45
+ # Mock ENV vars
46
+ ENV['RAILS_ENV'] = "test-3"
47
+ ENV['IAM_KEY'] = ENV['IAM_SECRET'] = "a"
48
+
49
+ # Allow rails-generated config
50
+ Rails = double("rails")
51
+ expect(Rails).to receive(:root).and_return(".").twice
52
+ expect(File).to receive(:exists?).and_return(true)
53
+ expect(File).to receive(:read).and_return(config.to_json)
54
+
55
+ # Mock the AWS features
56
+ client = double("client")
57
+ expect(client).to receive(:create_deployment)
58
+
59
+ ops_works = double("ops_works")
60
+ expect(ops_works).to receive(:client).and_return(client)
61
+
62
+ expect(AWS).to receive(:ops_works).and_return(ops_works)
63
+
64
+ # Call rake task
65
+ Rake::Task["opsworks:deploy"].invoke
66
+ ensure # clear ENV vars
67
+ ENV['RAILS_ENV'] = ENV['IAM_KEY'] = ENV['IAM_SECRET'] = nil
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'opsworks-deploy'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsworks-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-06-24 00:00:00.000000000 Z
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
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: aws-sdk
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'
55
97
  description: Quick and easy rake task for deploying to AWS OpsWorks
56
98
  email:
57
99
  - hayesgm@gmail.com
@@ -60,6 +102,7 @@ extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
62
104
  - .gitignore
105
+ - .rspec
63
106
  - Gemfile
64
107
  - LICENSE.txt
65
108
  - README.md
@@ -70,6 +113,8 @@ files:
70
113
  - lib/opsworks/deploy/version.rb
71
114
  - lib/opsworks/tasks/opsworks.rake
72
115
  - opsworks-deploy.gemspec
116
+ - spec/opsworks_deploy_spec.rb
117
+ - spec/spec_helper.rb
73
118
  homepage: ''
74
119
  licenses:
75
120
  - MIT
@@ -95,4 +140,6 @@ signing_key:
95
140
  specification_version: 4
96
141
  summary: A quick rake task that will deploy to AWS OpsWorks. This can be added as
97
142
  a post-step in Continuous Integration. `rake opsworks:deply`
98
- test_files: []
143
+ test_files:
144
+ - spec/opsworks_deploy_spec.rb
145
+ - spec/spec_helper.rb