leeroy_app 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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +40 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +103 -0
  7. data/LICENSE +21 -0
  8. data/README.md +40 -0
  9. data/Rakefile +5 -0
  10. data/bin/leeroy +18 -0
  11. data/hierarchy.md +39 -0
  12. data/leeroy.gemspec +42 -0
  13. data/lib/leeroy/app.rb +132 -0
  14. data/lib/leeroy/env.rb +116 -0
  15. data/lib/leeroy/helpers/aws.rb +403 -0
  16. data/lib/leeroy/helpers/dumpable.rb +72 -0
  17. data/lib/leeroy/helpers/env.rb +42 -0
  18. data/lib/leeroy/helpers/logging.rb +36 -0
  19. data/lib/leeroy/helpers/polling.rb +67 -0
  20. data/lib/leeroy/helpers/state.rb +59 -0
  21. data/lib/leeroy/helpers.rb +9 -0
  22. data/lib/leeroy/state.rb +70 -0
  23. data/lib/leeroy/task/base.rb +61 -0
  24. data/lib/leeroy/task/image.rb +126 -0
  25. data/lib/leeroy/task/instantiate.rb +200 -0
  26. data/lib/leeroy/task/sleep.rb +29 -0
  27. data/lib/leeroy/task/stub.rb +40 -0
  28. data/lib/leeroy/task/terminate.rb +49 -0
  29. data/lib/leeroy/task.rb +17 -0
  30. data/lib/leeroy/types/dash.rb +17 -0
  31. data/lib/leeroy/types/image.rb +53 -0
  32. data/lib/leeroy/types/instance.rb +67 -0
  33. data/lib/leeroy/types/mash.rb +17 -0
  34. data/lib/leeroy/types/packedstring.rb +25 -0
  35. data/lib/leeroy/types/phase.rb +20 -0
  36. data/lib/leeroy/types/semaphore.rb +30 -0
  37. data/lib/leeroy/types/statedata.rb +44 -0
  38. data/lib/leeroy/types/statemetadata.rb +29 -0
  39. data/lib/leeroy/types/userdata.rb +13 -0
  40. data/lib/leeroy/version.rb +3 -0
  41. data/lib/leeroy.rb +7 -0
  42. data/spec/spec_helper.rb +105 -0
  43. data/spec/support/aruba.rb +1 -0
  44. data/spec/use_aruba_with_rspec_spec.rb +11 -0
  45. metadata +333 -0
@@ -0,0 +1,67 @@
1
+ require 'leeroy'
2
+ require 'leeroy/types/dash'
3
+ require 'leeroy/types/mash'
4
+ require 'leeroy/types/phase'
5
+ require 'leeroy/types/userdata'
6
+ require 'leeroy/helpers/dumpable'
7
+ require 'leeroy/helpers/logging'
8
+
9
+ module Leeroy
10
+ module Types
11
+ class Instance < Leeroy::Types::Dash
12
+
13
+ include Leeroy::Helpers::Dumpable
14
+ include Leeroy::Helpers::Logging
15
+
16
+ property :phase, required: true, coerce: Leeroy::Types::Phase
17
+ property :aws_params
18
+
19
+ # AWS-specific params
20
+ property :iam_instance_profile, required: true
21
+ property :image_id, required: true
22
+ property :instance_type, required: true
23
+ property :key_name, required: true
24
+ property :max_count, required: true
25
+ property :min_count, required: true
26
+ property :security_group_ids, required: true
27
+ property :subnet_id, required: true
28
+ property :user_data, default: '', coerce: Leeroy::Types::UserData
29
+
30
+ def initialize(*args, &block)
31
+ self.aws_params = [
32
+ :iam_instance_profile,
33
+ :image_id,
34
+ :instance_type,
35
+ :key_name,
36
+ :max_count,
37
+ :min_count,
38
+ :security_group_ids,
39
+ :subnet_id,
40
+ :user_data,
41
+ ]
42
+
43
+ self.dump_properties = self.aws_params
44
+
45
+ super
46
+ end
47
+
48
+ def run_params
49
+ begin
50
+ params_hash = Leeroy::Types::Mash.new
51
+
52
+ self.aws_params.each {|param| params_hash.store(param.to_s, self.fetch(param.to_s))}
53
+
54
+ # UserData is special!
55
+
56
+ params_hash.store('user_data', self.fetch('user_data').encoded_for_ec2)
57
+
58
+ params_hash
59
+
60
+ rescue StandardError => e
61
+ raise e
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ require 'hashie'
2
+
3
+ module Leeroy
4
+ module Types
5
+ class Mash < Hashie::Mash
6
+ include Hashie::Extensions::KeyConversion
7
+ include Hashie::Extensions::MethodAccess
8
+ include Hashie::Extensions::IndifferentAccess
9
+ include Hashie::Extensions::Coercion
10
+
11
+ def dumper
12
+ self.to_hash
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'base64'
2
+ require 'zlib'
3
+
4
+ require 'leeroy/helpers/dumpable'
5
+ require 'leeroy/types/dash'
6
+
7
+ module Leeroy
8
+ module Types
9
+ class PackedString < String
10
+ include Leeroy::Helpers::Dumpable
11
+
12
+ def pack(input = self.to_s)
13
+ Base64.urlsafe_encode64(Zlib::Deflate.deflate(input))
14
+ end
15
+
16
+ def unpack(input = self.to_s)
17
+ Zlib::Inflate.inflate(Base64.urlsafe_decode64(input))
18
+ end
19
+
20
+ alias_method :dumper, :pack
21
+ alias_method :extract, :unpack
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Leeroy
2
+ module Types
3
+ class Phase < String
4
+ VALID_PHASE = ['gold_master', 'application']
5
+
6
+ def initialize(*args, &block)
7
+ begin
8
+ super
9
+
10
+ phase = self.to_s
11
+ raise "invalid value for phase: '#{phase}'" unless VALID_PHASE.include?(phase)
12
+
13
+ rescue StandardError => e
14
+ raise e
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'leeroy/helpers/dumpable'
2
+ require 'leeroy/types/packedstring'
3
+ require 'leeroy/types/dash'
4
+
5
+ module Leeroy
6
+ module Types
7
+ class Semaphore < Leeroy::Types::Dash
8
+ include Leeroy::Helpers::Dumpable
9
+
10
+ property :bucket
11
+ property :object
12
+ property :payload
13
+
14
+ def initialize(*args, &block)
15
+ super
16
+
17
+ self.dump_properties = [
18
+ :bucket,
19
+ :object,
20
+ :payload,
21
+ ]
22
+ end
23
+
24
+ def to_s
25
+ "s3://#{self.bucket}/#{self.object}"
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'yell'
2
+
3
+ require 'leeroy/helpers/dumpable'
4
+ require 'leeroy/helpers/logging'
5
+ require 'leeroy/types/dash'
6
+ require 'leeroy/types/mash'
7
+ require 'leeroy/types/phase'
8
+ require 'leeroy/types/semaphore'
9
+
10
+ module Leeroy
11
+ module Types
12
+ class StateData < Leeroy::Types::Dash
13
+ include Leeroy::Helpers::Logging
14
+ include Leeroy::Helpers::Dumpable
15
+
16
+ property :message, coerce: String
17
+ property :app_name, coerce: String
18
+ property :instanceid, coerce: String
19
+ property :imageid, coerce: String
20
+ property :phase, coerce: Leeroy::Types::Phase
21
+ property :semaphore, coerce: Leeroy::Types::Semaphore
22
+ property :sgid, coerce: String
23
+ property :subnetid, coerce: String
24
+ property :vpcid, coerce: String
25
+
26
+ def initialize(*args, &block)
27
+ super
28
+
29
+ self.dump_properties = [
30
+ :app_name,
31
+ :imageid,
32
+ :instanceid,
33
+ :message,
34
+ :phase,
35
+ :semaphore,
36
+ :sgid,
37
+ :subnetid,
38
+ :vpcid,
39
+ ]
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ require 'chronic'
2
+ require 'yell'
3
+
4
+ require 'leeroy/helpers/logging'
5
+ require 'leeroy/types/dash'
6
+
7
+ module Leeroy
8
+ module Types
9
+ class StateMetadata < Leeroy::Types::Dash
10
+ include Leeroy::Helpers::Dumpable
11
+ include Leeroy::Helpers::Logging
12
+
13
+ property :task, default: nil
14
+ property :previous, default: nil
15
+ property :started, coerce: Proc.new { |t| Chronic.parse(t) }, default: 'now'
16
+
17
+ def initialize(*args, &block)
18
+ super
19
+
20
+ self.dump_properties = [
21
+ :task,
22
+ :previous,
23
+ :started,
24
+ ]
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require 'base64'
2
+
3
+ require 'leeroy/types/packedstring'
4
+
5
+ module Leeroy
6
+ module Types
7
+ class UserData < Leeroy::Types::PackedString
8
+ def encoded_for_ec2(input = self.to_s)
9
+ Base64.urlsafe_encode64(input)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Leeroy
2
+ VERSION = "0.1.0"
3
+ end
data/lib/leeroy.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'leeroy/env'
2
+ require 'leeroy/version'
3
+ require 'leeroy/task'
4
+
5
+ module Leeroy
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,105 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
97
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
98
+
99
+ if RUBY_VERSION < '1.9.3'
100
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
101
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
102
+ else
103
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
104
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
105
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/rspec'
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'version', :type => :aruba do
4
+ @announce
5
+ let(:file) { 'file.txt' }
6
+ let(:content) { 'Hello World' }
7
+
8
+ before(:each) { write_file file, content }
9
+
10
+ it { expect(read(file)).to eq [content] }
11
+ end