ebx 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .DS_Store
20
+ eb/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ebx.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ebx (0.0.1)
5
+ aws-sdk (~> 1.17.0)
6
+ commander (~> 4.1.5)
7
+ pry (> 0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ aws-sdk (1.17.0)
13
+ json (~> 1.4)
14
+ nokogiri (< 1.6.0)
15
+ uuidtools (~> 2.1)
16
+ coderay (1.0.9)
17
+ commander (4.1.5)
18
+ highline (~> 1.6.11)
19
+ highline (1.6.19)
20
+ json (1.8.0)
21
+ method_source (0.8.2)
22
+ nokogiri (1.5.10)
23
+ pry (0.9.12.2)
24
+ coderay (~> 1.0.5)
25
+ method_source (~> 0.8)
26
+ slop (~> 3.4)
27
+ rake (10.1.0)
28
+ slop (3.4.6)
29
+ uuidtools (2.1.4)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.3)
36
+ ebx!
37
+ rake
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Funnerator Enterprises, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Bullard
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Ebx
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ebx'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ebx
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ebx ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+
6
+ require 'ebx'
7
+
8
+ program :version, '0.0.1'
9
+ program :description, 'eb eXtended'
10
+
11
+ DEFAULT_ENV = ['production', 'development', 'staging', 'test']
12
+
13
+ command :init do |c|
14
+ c.syntax = 'ebx init [options]'
15
+ c.summary = 'Init a new project'
16
+ # c.description = 'test'
17
+ # c.example 'description', 'command example'
18
+ # c.option '--some-switch', 'Some switch that does something'
19
+ #
20
+ #
21
+ ##
22
+ # queue.add(TryLoadEbConfigFileOperation(queue))
23
+ # queue.add(ReadAwsCredentialFileOperation(queue))
24
+ # queue.add(AskForConfigFileParameterOperation(queue))
25
+ # queue.add(ValidateParameterOperation(queue))
26
+ # queue.add(RotateOptionsettingFileOperation(queue))
27
+ # queue.add(SanitizeBranchOperation(queue))
28
+ # queue.add(UpdateAwsCredentialFileOperation(queue))
29
+ # queue.add(SanitizeAppVersionNameOperation(queue))
30
+ # queue.add(SaveEbConfigFileOperation(queue))
31
+ # queue.add(UpdateDevToolsConfigOperation(queue))
32
+ # queue.add(CheckGitIgnoreFileOperation(queue))
33
+ #
34
+ c.action do |args, options|
35
+ DEFAULT_ENV.each do |env|
36
+ ENV['AWS_ENV'] = env
37
+ AwsEnvironmentConfig.init_config
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+ # elif command == CommandType.START:
44
+ # queue.add(CheckGitIgnoreFileOperation(queue))
45
+ # queue.add(LoadEbConfigFileOperation(queue))
46
+ # queue.add(ReadAwsCredentialFileOperation(queue))
47
+ # queue.add(TryGetCurrentBranchOperation(queue))
48
+ # queue.add(AskForMissiongParameterOperation(queue))
49
+ # queue.add(ValidateParameterOperation(queue))
50
+ # queue.add(CreateApplicationOperation(queue))
51
+ # queue.add(CreateApplicationVersionOperation(queue))
52
+ # queue.add(CreateEnvironmentOperation(queue))
53
+ # queue.add(SleepOperation(queue))
54
+ # queue.add(SaveConfigurationSettingOperation(queue))
55
+ # queue.add(WaitForCreateEnvironmentFinishOperation(queue))
56
+
57
+
58
+ command :start do |c|
59
+ c.syntax = 'ebx start [env] [options]'
60
+ c.summary = 'Create an environment'
61
+
62
+ c.action do |args, options|
63
+ ENV['AWS_ENV'] ||= (args.shift || 'development')
64
+
65
+ AwsCredentialConfig.set_credentials
66
+ DeployGroup.new.create
67
+ end
68
+ end
69
+
70
+ command :status do |c|
71
+ c.action do |args, options|
72
+ ENV['AWS_ENV'] ||= (args.shift || 'development')
73
+ AwsCredentialConfig.set_credentials
74
+
75
+ settings = {
76
+ app_name: 'test_app',
77
+ app_description: 'test desc',
78
+ version_description: 'a version'
79
+ }
80
+ env = AwsEnvironment.new(settings)
81
+ env.describe[:environments].each do |env|
82
+ say env.to_s
83
+ end
84
+ end
85
+ end
data/ebx.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ebx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ebx"
8
+ spec.version = Ebx::VERSION
9
+ spec.authors = ["Alex Bullard"]
10
+ spec.email = ["abullrd@gmail.com"]
11
+ spec.description = "eb eXtended"
12
+ spec.summary = "A extended version of the Amazon ElasticBeanstalk commandline tool"
13
+ spec.homepage = "https://github.com/Funnerator/ebx.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["ebx"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency("commander", "~> 4.1.5")
25
+ spec.add_runtime_dependency("aws-sdk", "~> 1.17.0")
26
+ spec.add_runtime_dependency("pry", "> 0")
27
+ end
data/lib/ebx.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'aws'
2
+ require 'pry'
3
+
4
+ require 'ebx/version'
5
+ require 'ebx/aws_credential_config'
6
+ require 'ebx/aws_application'
7
+ require 'ebx/aws_application_version'
8
+ require 'ebx/aws_environment'
9
+ require 'ebx/aws_environment_config'
10
+ require 'ebx/deploy_group'
11
+ require 'ebx/elastic_beanstalk'
12
+ require 'ebx/version'
13
+
14
+ DEFAULT_REGION = 'us-east-1'
@@ -0,0 +1,26 @@
1
+ class AwsApplication
2
+ attr_accessor :settings
3
+
4
+ def initialize(settings)
5
+ @settings = settings
6
+ end
7
+
8
+ def create
9
+ begin
10
+ if describe[:applications].empty?
11
+ ElasticBeanstalk.instance.client.create_application(
12
+ application_name: settings['name'],
13
+ description: settings['description']
14
+ )
15
+ end
16
+ rescue Exception
17
+ raise $! # TODO
18
+ end
19
+ end
20
+
21
+ def describe
22
+ ElasticBeanstalk.instance.client.describe_applications(
23
+ application_names: [settings['name']]
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ class AwsApplicationVersion
2
+ attr_accessor :settings
3
+
4
+ def initialize(settings)
5
+ @settings = settings
6
+ end
7
+
8
+ def create
9
+ begin
10
+ if describe[:application_versions].empty?
11
+ ElasticBeanstalk.instance.client.create_application_version(
12
+ application_name: settings['name'],
13
+ version_label: version
14
+ #source_bundle: {
15
+ # s3_bucket: settings[:source_bucket],
16
+ # s3_key: settings[:source_key]
17
+ #}
18
+ )
19
+ end
20
+ rescue Exception
21
+ raise $! # TODO
22
+ end
23
+ end
24
+
25
+ def describe
26
+ ElasticBeanstalk.instance.client.describe_application_versions(
27
+ application_name: settings['name'],
28
+ version_labels: [version]
29
+ )
30
+ end
31
+
32
+ def version
33
+ `git rev-parse HEAD`
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+ class AwsCredentialConfig
4
+ class << self
5
+ # Use same credential file as eb
6
+ def set_credentials
7
+ File.open(File.expand_path('.elasticbeanstalk/aws_credential_file', Dir.home), 'r') do |f|
8
+ secrets = f.readlines.reduce({}) do |h, line|
9
+ k, v = *line.split("=")
10
+ h[k] = v.strip
11
+ h
12
+ end
13
+
14
+ AWS.config(
15
+ access_key_id: secrets['AWSAccessKeyId'],
16
+ secret_access_key: secrets['AWSSecretKey'],
17
+ dynamo_db: { api_version: '2012-08-10' }
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ class AwsEnvironment
2
+ attr_accessor :settings
3
+
4
+ def initialize(settings)
5
+ @settings = settings
6
+ end
7
+
8
+ def create
9
+ begin
10
+ if describe[:environments].empty?
11
+ ElasticBeanstalk.instance.client.create_environment(
12
+ application_name: settings['name'],
13
+ version_label: version,
14
+ environment_name: name,
15
+ solution_stack_name: settings['solution_stack'],
16
+ #option_settings: [{
17
+ # namespace: 'aws:autoscaling:launchconfiguration',
18
+ # option_name: 'IamInstanceProfile',
19
+ # option_value: 'ElasticBeanstalkProfile'
20
+ #}]
21
+ )
22
+ end
23
+ rescue Exception
24
+ raise $! # TODO
25
+ end
26
+ end
27
+
28
+ def version
29
+ `git rev-parse HEAD`
30
+ end
31
+
32
+ def name
33
+ "#{ENV['AWS_ENV']}-#{`git rev-parse --abbrev-ref HEAD`}".strip.gsub(/\s/, '-')[0..23]
34
+ end
35
+
36
+ def describe
37
+ binding.pry
38
+ ElasticBeanstalk.instance.client.describe_environments({
39
+ environment_names: [name]
40
+ })
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ class AwsEnvironmentConfig
4
+
5
+ class << self
6
+ def config_path
7
+ File.expand_path("eb/environment.yml", Dir.pwd)
8
+ end
9
+
10
+ def config_exists?
11
+ FileTest.file?(config_path)
12
+ end
13
+
14
+ def read_config
15
+ @config ||= YAML.load_file(config_path)
16
+ end
17
+
18
+ def init_config
19
+ create_dir('.ebextentions')
20
+ create_dir('eb')
21
+
22
+ unless FileTest.file?(config_path)
23
+ FileUtils.cp(File.expand_path('../../generators/templates/environment.yml', __FILE__), config_path)
24
+ end
25
+
26
+ read_config
27
+ end
28
+
29
+ def create_dir(name)
30
+ dir = File.expand_path(name, Dir.pwd)
31
+
32
+ raise "#{name} exists and is not a directory" if FileTest.file?(dir)
33
+ unless FileTest.directory?(dir)
34
+ Dir.mkdir(dir)
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,25 @@
1
+ class DeployGroup
2
+ attr_accessor :global_settings
3
+
4
+ def initialize
5
+ @global_settings = AwsEnvironmentConfig.read_config[ENV['AWS_ENV']]
6
+ end
7
+
8
+ def create
9
+ global_settings['environments'].each do |env_settings|
10
+ AWS.config(region: env_settings['region'] || Ebx::DEFAULT_REGION)
11
+ ElasticBeanstalk.instance.update_settings
12
+
13
+ env_settings = global_settings.merge(env_settings)
14
+
15
+ app = AwsApplication.new(env_settings)
16
+ app.create
17
+
18
+ ver = AwsApplicationVersion.new(env_settings)
19
+ ver.create
20
+
21
+ env = AwsEnvironment.new(env_settings)
22
+ env.create
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ class ElasticBeanstalk
4
+ include Singleton
5
+
6
+ def initialize
7
+ update_settings
8
+ end
9
+
10
+ def client
11
+ @eb.client
12
+ end
13
+
14
+ def update_settings
15
+ @eb = AWS::ElasticBeanstalk.new
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Ebx
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,21 @@
1
+ base: &base
2
+ name: 'test_app'
3
+ description: 'test desc'
4
+ solution_stack: '64bit Amazon Linux running Ruby 1.9.3'
5
+ environments:
6
+ - region: 'us-west-2'
7
+ storage:
8
+ type: 'dynamodb'
9
+ - region: 'us-east-1'
10
+
11
+ production:
12
+ <<: *base
13
+
14
+ test:
15
+ <<: *base
16
+
17
+ staging:
18
+ <<: *base
19
+
20
+ development:
21
+ <<: *base
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ebx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Bullard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: commander
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 4.1.5
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.5
62
+ - !ruby/object:Gem::Dependency
63
+ name: aws-sdk
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.17.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.17.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>'
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>'
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: eb eXtended
95
+ email:
96
+ - abullrd@gmail.com
97
+ executables:
98
+ - ebx
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - bin/ebx
110
+ - ebx.gemspec
111
+ - lib/ebx.rb
112
+ - lib/ebx/aws_application.rb
113
+ - lib/ebx/aws_application_version.rb
114
+ - lib/ebx/aws_credential_config.rb
115
+ - lib/ebx/aws_environment.rb
116
+ - lib/ebx/aws_environment_config.rb
117
+ - lib/ebx/deploy_group.rb
118
+ - lib/ebx/elastic_beanstalk.rb
119
+ - lib/ebx/version.rb
120
+ - lib/generators/templates/environment.yml
121
+ homepage: https://github.com/Funnerator/ebx.git
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.23
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: A extended version of the Amazon ElasticBeanstalk commandline tool
146
+ test_files: []