dumbwaiter 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee61708863374cdb339fae14fb5f750f52b1a13f
4
+ data.tar.gz: 239abdfa0c7d8a4dc81a3575806bba5dc758e4bb
5
+ SHA512:
6
+ metadata.gz: 5b04376369f0d489bd1fdedcdfe5fb970782017cd4867eae437017112c53d7bc64d4df9bec2621178875e63be4e0bd706a2e723861f91f31c1164c47bcfbb6b4
7
+ data.tar.gz: 28eaa1dd456eb828cb7eb3988bfd077b149d901ef4a5a5f2aefec11543ce48893c8a7ca41d88d6c2af59c55afdc821e546049a534b058f0c9f12161defdf6989
@@ -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
@@ -0,0 +1 @@
1
+ dumbwaiter
@@ -0,0 +1 @@
1
+ 2.0.0-p353
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ script: script/ci.sh
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "guard-rspec"
7
+ gem "guard-bundler"
8
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ guard :rspec do
4
+ watch(%r{^spec/.+_spec\.rb$})
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch('spec/spec_helper.rb') { "spec" }
7
+ end
8
+
9
+ guard :bundler do
10
+ watch('Gemfile')
11
+ # Uncomment next line if your Gemfile contains the `gemspec' command.
12
+ # watch(/^.+\.gemspec/)
13
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Doc Ritezel
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,47 @@
1
+ Dumbwaiter
2
+ ==========
3
+
4
+ Dumbwaiter hoists your Rails application up to OpsWorks and ratchets deployment
5
+ information back down.
6
+
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'dumbwaiter'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dumbwaiter
22
+
23
+
24
+ Usage
25
+ -----
26
+
27
+ Deploy the "cinnamon" branch of the "syrup" application to the "Pancake" stack:
28
+
29
+ `dumbwaiter deploy Pancake syrup cinnamon`
30
+
31
+ Roll back the "Snowman" stack:
32
+
33
+ `dumbwaiter rollback Snowman`
34
+
35
+ List the deployments on the "Maniacal Checklist" stack:
36
+
37
+ `dumbwaiter list "Maniacal Checklist"`
38
+
39
+
40
+ Contributing
41
+ ------------
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+ require "dumbwaiter"
4
+ Dumbwaiter::Cli.start
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dumbwaiter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dumbwaiter"
8
+ spec.version = Dumbwaiter::VERSION
9
+ spec.authors = ["Doc Ritezel"]
10
+ spec.email = ["doc@ministryofvelocity.com"]
11
+ spec.description = %q{Hoist your code up to Opsworks}
12
+ spec.summary = %q{Monitor, deploy and maintain your Opsworks application stacks}
13
+ spec.homepage = "https://github.com/minifast/dumbwaiter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^spec/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk-core"
22
+ spec.add_dependency "hashie"
23
+ spec.add_dependency "thor"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "gem-release"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,4 @@
1
+ module Dumbwaiter; end
2
+
3
+ require "dumbwaiter/cli"
4
+ require "dumbwaiter/version"
@@ -0,0 +1,91 @@
1
+ require "thor"
2
+ require "aws-sdk-core"
3
+ require "dumbwaiter/deployment_custom_json"
4
+
5
+ module Dumbwaiter
6
+ class Cli < Thor
7
+ class MissingStack < Error; end
8
+ class MissingApp < Error; end
9
+
10
+ desc "deploy STACK_NAME APP_NAME GIT_REF", "Deploy an application revision"
11
+ def deploy(stack_name, app_name, revision)
12
+ stack_id = stack_id_for_name(stack_name)
13
+ custom_json = DeploymentCustomJson.create(app_name, revision).to_json
14
+ opsworks.create_deployment(
15
+ stack_id: stack_id,
16
+ app_id: app_id_for_name(stack_id, app_name),
17
+ command: {name: "deploy", args: {migrate: ["true"]}},
18
+ custom_json: custom_json
19
+ )
20
+ end
21
+
22
+ desc "rollback STACK_NAME APP_NAME", "Roll back an application"
23
+ def rollback(stack_name, app_name)
24
+ stack_id = stack_id_for_name(stack_name)
25
+ opsworks.create_deployment(
26
+ stack_id: stack_id,
27
+ app_id: app_id_for_name(stack_id, app_name),
28
+ command: {name: "rollback"}
29
+ )
30
+ end
31
+
32
+ desc "list STACK_NAME", "List all the deployments for a stack"
33
+ def list(stack_name)
34
+ stack_id = stack_id_for_name(stack_name)
35
+ app_deployments = deployments(stack_id).select do |deployment|
36
+ %w(rollback deploy).include?(deployment.command.name)
37
+ end
38
+
39
+ app_deployments.each do |deployment|
40
+ custom_json = DeploymentCustomJson.from_json(deployment.custom_json || "{}")
41
+ Kernel.puts "#{deployment.created_at} - #{deployment.command.name} - #{deployment.status} - #{custom_json.git_ref}"
42
+ end
43
+ end
44
+
45
+ no_tasks do
46
+ def app_id_for_name(stack_id, app_name)
47
+ app_id = app_ids_by_name(stack_id)[app_name]
48
+ raise MissingApp.new("No app named #{app_name}") unless app_id
49
+ app_id
50
+ end
51
+
52
+ def stack_id_for_name(stack_name)
53
+ stack_id = stack_ids_by_name[stack_name]
54
+ raise MissingStack.new("No stack named #{stack_name}") unless stack_id
55
+ stack_id
56
+ end
57
+
58
+ def stack_ids_by_name
59
+ @stack_ids_by_name ||= stacks.reduce({}) do |result, stack|
60
+ result[stack.name] = stack.stack_id
61
+ result
62
+ end
63
+ end
64
+
65
+ def app_ids_by_name(stack_id)
66
+ apps(stack_id).reduce({}) do |result, app|
67
+ result[app.name] = app.app_id
68
+ result
69
+ end
70
+ end
71
+
72
+ def stacks
73
+ @stacks ||= opsworks.describe_stacks.stacks
74
+ end
75
+
76
+ def apps(stack_id)
77
+ @apps ||= {}
78
+ @apps[stack_id] ||= opsworks.describe_apps(stack_id: stack_id).apps
79
+ end
80
+
81
+ def deployments(stack_id)
82
+ @deployments ||= {}
83
+ @deployments[stack_id] ||= opsworks.describe_deployments(stack_id: stack_id).deployments
84
+ end
85
+
86
+ def opsworks
87
+ @opsworks ||= Aws::OpsWorks.new(region: "us-east-1")
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,24 @@
1
+ require "hashie"
2
+ require "json"
3
+
4
+ class Dumbwaiter::DeploymentCustomJson < Hashie::Mash
5
+ def self.from_json(json_string)
6
+ new(JSON.parse(json_string))
7
+ end
8
+
9
+ def self.create(name, ref)
10
+ {deploy: {name => {scm: {revision: ref}}}}
11
+ end
12
+
13
+ def app_name
14
+ self.deploy.keys.first unless self.deploy.nil?
15
+ end
16
+
17
+ def git_ref
18
+ if self.app_name.nil?
19
+ "HEAD"
20
+ else
21
+ self.deploy[self.app_name].scm.revision
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Dumbwaiter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ bundle exec rspec
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe Dumbwaiter::Cli do
4
+ let(:fake_stack) { double(:stack, name: "ducks", stack_id: "cool") }
5
+ let(:fake_stacks) { double(:stacks, stacks: [fake_stack]) }
6
+
7
+ let(:fake_app) { double(:app, name: "reifel", app_id: "wat") }
8
+ let(:fake_apps) { double(:apps, apps: [fake_app]) }
9
+
10
+ let(:custom_json) { {deploy: {"reifel" => {scm: {revision: "corn"}}}} }
11
+
12
+ subject(:cli) { Dumbwaiter::Cli.new }
13
+
14
+ before { cli.opsworks.stub(describe_stacks: fake_stacks, describe_apps: fake_apps) }
15
+
16
+ describe "#deploy" do
17
+ context "when the stack exists" do
18
+ it "deploys the stack with the resolved id" do
19
+ cli.opsworks.should_receive(:create_deployment) do |params|
20
+ params[:stack_id].should == "cool"
21
+ params[:command].should == {name: "deploy", args: {migrate: ["true"]}}
22
+ params[:custom_json].should == custom_json.to_json
23
+ end
24
+ cli.deploy("ducks", "reifel", "corn")
25
+ end
26
+ end
27
+
28
+ context "when the stack does not exist" do
29
+ let(:fake_stack) { double(:stack, name: "tacos", stack_id: "great") }
30
+
31
+ it "blows up" do
32
+ expect {
33
+ cli.deploy("ducks", "reifel", "corn")
34
+ }.to raise_error(Dumbwaiter::Cli::MissingStack)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#rollback" do
40
+ context "when the stack exists" do
41
+ it "rolls back the stack with the resolved id" do
42
+ cli.opsworks.should_receive(:create_deployment) do |params|
43
+ params[:stack_id].should == "cool"
44
+ params[:app_id].should == "wat"
45
+ params[:command].should == {name: "rollback"}
46
+ end
47
+ cli.rollback("ducks", "reifel")
48
+ end
49
+ end
50
+
51
+ context "when the stack does not exist" do
52
+ let(:fake_stack) { double(:stack, name: "tacos", stack_id: "great") }
53
+
54
+ it "blows up" do
55
+ expect {
56
+ cli.rollback("ducks", "reifel")
57
+ }.to raise_error(Dumbwaiter::Cli::MissingStack)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "#list" do
63
+ let(:fake_command) { double(:command, name: "deploy", args: "not again!")}
64
+ let(:fake_deployment) { double(:deployment, stack_id: "cool", created_at: "meat", status: "meh", command: fake_command, custom_json: custom_json.to_json) }
65
+ let(:fake_deployments) { double(:deployments, deployments: [fake_deployment]) }
66
+
67
+ before { cli.opsworks.stub(describe_deployments: fake_deployments) }
68
+
69
+ context "when the stack exists" do
70
+ it "lists the deployments" do
71
+ Kernel.stub(:puts) { |string| string.should =~ /meat.+meh.+corn/ }
72
+ cli.list("ducks")
73
+ end
74
+ end
75
+
76
+ context "when the stack does not exist" do
77
+ let(:fake_stack) { double(:stack, name: "tacos", stack_id: "great") }
78
+
79
+ it "blows up" do
80
+ expect {
81
+ cli.list("ducks")
82
+ }.to raise_error(Dumbwaiter::Cli::MissingStack)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Dumbwaiter::DeploymentCustomJson do
4
+ subject(:json) { Dumbwaiter::DeploymentCustomJson.new(custom_json) }
5
+
6
+ context "when the custom json does not contain a revision" do
7
+ let(:custom_json) { {} }
8
+
9
+ its(:app_name) { should be_nil }
10
+ its(:git_ref) { should == "HEAD" }
11
+ end
12
+
13
+ context "when the custom json contains a revision" do
14
+ let(:custom_json) { {deploy: {"reifel" => {scm: {revision: "corn"}}}} }
15
+
16
+ its(:app_name) { should == "reifel" }
17
+ its(:git_ref) { should == "corn" }
18
+ end
19
+
20
+ describe ".create" do
21
+ let(:json) { Dumbwaiter::DeploymentCustomJson.create("socks", "ham") }
22
+
23
+ specify { json.should == {deploy: {"socks" => {scm: {revision: "ham"}}}} }
24
+ end
25
+
26
+ describe ".from_json" do
27
+ let(:json_string) { JSON.dump(deploy: {"toes" => {scm: {revision: "jam"}}}) }
28
+ subject(:json) { Dumbwaiter::DeploymentCustomJson.from_json(json_string) }
29
+
30
+ its(:app_name) { should == "toes" }
31
+ its(:git_ref) { should == "jam" }
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "dumbwaiter"
5
+
6
+ Aws.config = {access_key_id: "tacos", secret_access_key: "secret chocolate"}
7
+
8
+ # This file was generated by the `rspec --init` command. Conventionally, all
9
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
10
+ # Require this file using `require "spec_helper"` to ensure that it is only
11
+ # loaded once.
12
+ #
13
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
14
+ RSpec.configure do |config|
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = "random"
24
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dumbwaiter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doc Ritezel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gem-release
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: rspec
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
+ description: Hoist your code up to Opsworks
98
+ email:
99
+ - doc@ministryofvelocity.com
100
+ executables:
101
+ - dumbwaiter
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .ruby-gemset
108
+ - .ruby-version
109
+ - .travis.yml
110
+ - Gemfile
111
+ - Guardfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - bin/dumbwaiter
115
+ - dumbwaiter.gemspec
116
+ - lib/dumbwaiter.rb
117
+ - lib/dumbwaiter/cli.rb
118
+ - lib/dumbwaiter/deployment_custom_json.rb
119
+ - lib/dumbwaiter/version.rb
120
+ - script/ci.sh
121
+ - spec/lib/dumbwaiter/cli_spec.rb
122
+ - spec/lib/dumbwaiter/deployment_custom_json_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: https://github.com/minifast/dumbwaiter
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.14
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Monitor, deploy and maintain your Opsworks application stacks
148
+ test_files:
149
+ - spec/lib/dumbwaiter/cli_spec.rb
150
+ - spec/lib/dumbwaiter/deployment_custom_json_spec.rb
151
+ - spec/spec_helper.rb