infopark_opsworks_helpers 0.2.2 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a24732f2352838a569437fd2388fca6baa4c9952
4
- data.tar.gz: 0ebffb524adfbb5445def02c5910f5e33ed04574
2
+ SHA256:
3
+ metadata.gz: ee10378fc4133be59d126584816c551d7a8bfc57e236bcdae923d50475ba2611
4
+ data.tar.gz: e476439b4784349f4d50786f87a8b8850cf885c720f70f2dcc1b06fbc8b2458c
5
5
  SHA512:
6
- metadata.gz: 67ca53b809f6d0c3c57da081173f02655853288b8bb6932c356016e815e8de53223063a55dbd7ecfb8b424ff8c2f3c902bd176fbf56f2477709dac22fbad472e
7
- data.tar.gz: afcdded05cedff41b5830e00917fac6d44b95a839d839313032b36eed80a28a243c4cb973ccb2b4a40b3d0a381bc15cf4b0197f996a7ed5f47cae5a6d9107ac6
6
+ metadata.gz: e60a60c94f1e201b0b8e1380093241fd7fef835e26e125ffddd507bdb51a98596d1b39483e43558b525f5e76553faa56ab2b762c8caf3fab0e9fc8e523ff5f31
7
+ data.tar.gz: dbee21c953be88fe630183865285f2be8dbc03fdb6e5b7a8648847e3325e1a444736cc71acb1030081898125e493c6ebd20e8e4c51b62b06054bef509e7d79e1
@@ -1,6 +1,10 @@
1
1
  require "opsworks_helpers/engine"
2
- require "opsworks_helpers/deploy"
3
2
  require "opsworks_helpers/status_checks"
3
+ require "opsworks_helpers/opsworks_client"
4
+ require "opsworks_helpers/opsworks_resource"
5
+ require "opsworks_helpers/deployment"
6
+ require "opsworks_helpers/stack"
7
+ require "opsworks_helpers/app"
4
8
 
5
9
  module OpsworksHelpers
6
10
 
@@ -0,0 +1,19 @@
1
+ module OpsworksHelpers
2
+ class App < OpsworksResource
3
+
4
+ def self.all(stack_id)
5
+ new.all(stack_id)
6
+ end
7
+
8
+ def all(stack_id)
9
+ opsworks.describe_apps(stack_id: stack_id).apps.map do |app|
10
+ self.class.new(app)
11
+ end
12
+ end
13
+
14
+ def id
15
+ opsworks_resource.app_id
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ begin
2
+ require 'aws-sdk'
3
+ rescue LoadError
4
+ fail 'Please add `aws-sdk` to your Gemfile if you want to use the deployment features.'
5
+ end
6
+
7
+ module OpsworksHelpers
8
+ class Deployment < OpsworksResource
9
+
10
+ def id
11
+ opsworks_resource.deployment_id
12
+ end
13
+
14
+ def command_name
15
+ command[:name]
16
+ end
17
+
18
+ def create(command, comment: 'Run via in-app rake task')
19
+ @command = command
20
+
21
+ @opsworks_resource = opsworks.create_deployment(
22
+ stack_id: stack_id,
23
+ app_id: app_id,
24
+ command: command,
25
+ comment: comment
26
+ )
27
+ end
28
+
29
+ def deploy(stack:nil, app:nil, comment:nil)
30
+ @stack_id = stack if stack
31
+ @app_id = app if app
32
+
33
+ @command = {
34
+ name: 'deploy',
35
+ args: { migrate: ['true'] }
36
+ }
37
+ create(command, comment: comment)
38
+ end
39
+
40
+ def display_deployment_result
41
+ begin
42
+ puts "[#{id}] Waiting for command '#{command_name}' to finish..."
43
+ opsworks.wait_until(:deployment_successful, deployment_ids: [id])
44
+ puts "[#{id}] Command '#{command_name}' successful."
45
+ true
46
+ rescue ::Aws::Waiters::Errors::WaiterFailed => e
47
+ puts "[#{id}] Command '#{command_name}' failed. Message: #{e.message}"
48
+ false
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ attr_accessor :command
55
+
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ module OpsworksHelpers
2
+ module OpsworksClient
3
+
4
+ attr_accessor :stack_id, :app_id
5
+
6
+ private
7
+
8
+ def opsworks
9
+ @opsworks ||= Aws::OpsWorks::Client.new(region: aws_region)
10
+ end
11
+
12
+ def stack_id
13
+ @stack_id || ENV['AWS_OPSWORKS_STACK_ID'] ||
14
+ fail('Please provide AWS_OPSWORKS_STACK_ID in env.')
15
+ end
16
+
17
+ def app_id
18
+ @app_id || ENV['AWS_OPSWORKS_APP_ID'] ||
19
+ fail('Please provide AWS_OPSWORKS_APP_ID in env.')
20
+ end
21
+
22
+ def aws_region
23
+ ENV.fetch('AWS_REGION', 'us-east-1')
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module OpsworksHelpers
2
+ class OpsworksResource
3
+ include OpsworksClient
4
+
5
+ def self.all
6
+ new.all
7
+ end
8
+
9
+ def initialize(resource=nil)
10
+ @opsworks_resource = resource
11
+ end
12
+
13
+ def inspect
14
+ string = "#<#{self.class.name}:#{self.object_id} "
15
+ fields = inspect_fields.map{|field| "#{field}: #{self.send(field)}"}
16
+ string << fields.join(", ") << ">"
17
+ end
18
+
19
+ def name
20
+ opsworks_resource.name
21
+ end
22
+
23
+ private
24
+
25
+ attr_accessor :opsworks_resource
26
+
27
+ def inspect_fields
28
+ %i(id name)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module OpsworksHelpers
2
+ class Stack < OpsworksResource
3
+
4
+ def all
5
+ opsworks.describe_stacks.stacks.map do |stack|
6
+ self.class.new(stack)
7
+ end
8
+ end
9
+
10
+ def id
11
+ opsworks_resource.stack_id
12
+ end
13
+
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module OpsworksHelpers
2
- VERSION = "0.2.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,26 +1,55 @@
1
- namespace 'opsworks' do
1
+ begin
2
+ require 'opsworks_helpers/deployment'
3
+ rescue
4
+ end
2
5
 
3
- client = OpsworksHelpers::Deploy.new
6
+ if defined?(OpsworksHelpers::Deployment)
7
+ namespace 'opsworks' do
4
8
 
5
- desc 'Deploy application to stack (and migrate database)'
6
- task :deploy => :environment do
7
- command_name = 'deploy'
8
- deployment_id = client.deploy({
9
- name: command_name,
10
- args: { migrate: ['true'] }
11
- })
9
+ client = OpsworksHelpers::Deployment.new
12
10
 
13
- client.display_deployment_result(command_name, deployment_id)
14
- end
11
+ desc 'Deploy application to stack (and migrate database)'
12
+ task :deploy => :environment do
13
+ stacks = OpsworksHelpers::Stack.all
14
+ stack_id = if stacks.size > 1
15
+ STDOUT.puts 'Which stack?'
16
+ stacks.each_with_index do |stack, index|
17
+ STDOUT.puts "#{index + 1}. #{stack.name}"
18
+ end
19
+ input = STDIN.gets.chomp.to_i
20
+
21
+ stacks[input - 1].id
22
+ else
23
+ stacks[0].id
24
+ end
25
+
26
+ apps = OpsworksHelpers::App.all(stack_id)
27
+ app_id = if apps.size > 1
28
+ STDOUT.puts "\nWhich app?"
29
+ apps.each_with_index do |app, index|
30
+ STDOUT.puts "#{index + 1}. #{app.name}"
31
+ end
32
+ input = STDIN.gets.chomp.to_i
33
+
34
+ apps[input - 1].id
35
+ else
36
+ apps[0].id
37
+ end
15
38
 
16
- %w(rollback restart start stop configure setup).each do |command_name|
17
- desc "Run command '#{command_name}' on OpsWorks"
18
- task command_name => :environment do
19
- deployment_id = client.deploy({name: command_name})
39
+ deployment = client.deploy(stack: stack_id, app: app_id)
20
40
 
21
- client.display_deployment_result(command_name, deployment_id)
41
+ client.display_deployment_result
22
42
  end
23
43
 
24
- end
44
+ %w(rollback restart start stop configure setup).each do |command_name|
45
+ desc "Run command '#{command_name}' on OpsWorks"
46
+ task command_name => :environment do
47
+ deployment_id = client.create({name: command_name})
48
+
49
+ client.display_deployment_result
50
+ end
25
51
 
52
+ end
53
+
54
+ end
26
55
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_opsworks_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infopark AG
8
8
  - Benjamin Zimmer
9
+ - Felix Abele
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2016-06-06 00:00:00.000000000 Z
13
+ date: 2020-06-19 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -71,44 +72,16 @@ dependencies:
71
72
  name: rails
72
73
  requirement: !ruby/object:Gem::Requirement
73
74
  requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '4.2'
77
- type: :runtime
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '4.2'
84
- - !ruby/object:Gem::Dependency
85
- name: haml-rails
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :runtime
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
75
+ - - "<"
96
76
  - !ruby/object:Gem::Version
97
- version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: aws-sdk
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '2'
77
+ version: '5.3'
105
78
  type: :runtime
106
79
  prerelease: false
107
80
  version_requirements: !ruby/object:Gem::Requirement
108
81
  requirements:
109
- - - "~>"
82
+ - - "<"
110
83
  - !ruby/object:Gem::Version
111
- version: '2'
84
+ version: '5.3'
112
85
  description:
113
86
  email:
114
87
  - info@infopark.de
@@ -117,20 +90,19 @@ extensions: []
117
90
  extra_rdoc_files: []
118
91
  files:
119
92
  - Rakefile
120
- - app/assets/javascripts/opsworks_helpers/application.js
121
- - app/assets/stylesheets/opsworks_helpers/application.css
122
93
  - app/controllers/opsworks_helpers/application_controller.rb
123
- - app/helpers/opsworks_helpers/application_helper.rb
124
- - app/views/application/status.html.haml
125
- - app/views/layouts/opsworks_helpers/application.html.haml
126
94
  - config/routes.rb
127
95
  - lib/opsworks_helpers.rb
128
- - lib/opsworks_helpers/deploy.rb
96
+ - lib/opsworks_helpers/app.rb
97
+ - lib/opsworks_helpers/deployment.rb
129
98
  - lib/opsworks_helpers/engine.rb
99
+ - lib/opsworks_helpers/opsworks_client.rb
100
+ - lib/opsworks_helpers/opsworks_resource.rb
101
+ - lib/opsworks_helpers/stack.rb
130
102
  - lib/opsworks_helpers/status_checks.rb
131
103
  - lib/opsworks_helpers/version.rb
132
104
  - lib/tasks/opsworks_helpers_tasks.rake
133
- homepage: https://github.com/infopark/opsworks-helpers
105
+ homepage: https://github.com/infopark/infopark_opsworks_helpers
134
106
  licenses: []
135
107
  metadata: {}
136
108
  post_install_message:
@@ -148,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
120
  - !ruby/object:Gem::Version
149
121
  version: '0'
150
122
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.5.1
123
+ rubygems_version: 3.0.3
153
124
  signing_key:
154
125
  specification_version: 4
155
126
  summary: Provides little helper functions for managing AWS OpsWorks stacks.
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,4 +0,0 @@
1
- module OpsworksHelpers
2
- module ApplicationHelper
3
- end
4
- end
@@ -1 +0,0 @@
1
- %h1 Status
@@ -1,11 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title OpsworksHelpers
5
- = stylesheet_link_tag "opsworks_helpers/application", media: "all"
6
- = javascript_include_tag "opsworks_helpers/application"
7
- = csrf_meta_tags
8
-
9
- %body
10
-
11
- = yield
@@ -1,42 +0,0 @@
1
- require 'aws-sdk'
2
-
3
- module OpsworksHelpers
4
- class Deploy
5
-
6
- def deploy(command, comment='Run via in-app rake task')
7
- client.create_deployment(
8
- stack_id: opsworks_stack_id,
9
- app_id: opsworks_app_id,
10
- command: command,
11
- comment: comment
12
- ).deployment_id
13
- end
14
-
15
- def display_deployment_result(command_name, deployment_id)
16
- begin
17
- puts "[#{deployment_id}] Waiting for command '#{command_name}' to finish..."
18
- client.wait_until(:deployment_successful, deployment_ids: [deployment_id])
19
- puts "[#{deployment_id}] Command '#{command_name}' successful."
20
- true
21
- rescue ::Aws::Waiters::Errors::WaiterFailed => e
22
- puts "[#{deployment_id}] Command '#{command_name}' failed. Message: #{e.message}"
23
- false
24
- end
25
- end
26
-
27
- private
28
-
29
- def client
30
- @client ||= Aws::OpsWorks::Client.new(region: 'us-east-1')
31
- end
32
-
33
- def opsworks_stack_id
34
- ENV['AWS_OPSWORKS_STACK_ID'] || fail('Please provide AWS_OPSWORKS_STACK_ID in env.')
35
- end
36
-
37
- def opsworks_app_id
38
- ENV['AWS_OPSWORKS_APP_ID'] || fail('Please provide AWS_OPSWORKS_APP_ID in env.')
39
- end
40
-
41
- end
42
- end