ops_tasks 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: b6a3c8ccecfba3b559bd9cb05d98cde21377bdd2
4
- data.tar.gz: db7cbf29fc79be28b207bcb97146057ca3fb8901
3
+ metadata.gz: befcd3a34d35b3135cd31a592fef6638d3da37e9
4
+ data.tar.gz: 0b76d581ebf5a7cb009463e2ceecc86dde03b24a
5
5
  SHA512:
6
- metadata.gz: b41142e8b5a9e65042f31fe01c058226e4aeba34d7e1b57ff076fcbdf9ab70c4d96e03b5280a6595f92258bb0a2e387cf2fc81249e225103c6f652ace3105e52
7
- data.tar.gz: fece55529f5e89d9bbdb20589f26e955be29ce899d7c59bd5c2f27ed4035f50053d6261038bbc1c0d16fefac19cf576fb0652a503ad33c924bead221354e1349
6
+ metadata.gz: f9e979ef040817397cb2e4a2053d53c39b47d928706f75b0fa8fe567db7d13dd308f3a7b6f7b7063d00c0c561c90f7f799b95cac9efb5de7cb1c4e609e8aac19
7
+ data.tar.gz: a57ec4d202c09c4728818d78b637c029cce8ba9b777fbb6e2379445ffbfd5e33f5f8f5814e16eef15e55e3a688310c2b6db609c102468ce81b1945cb73a394c7
data/lib/ops_tasks.rb CHANGED
@@ -1,74 +1,6 @@
1
- require 'aws-sdk'
2
- require 'say2slack'
3
- require 'highline/import'
4
-
5
1
  module OpsTasks
6
2
  require 'ops_tasks/railtie' if defined?(Rails)
7
- class Deployment
8
- def initialize(args)
9
- if args.size > 0
10
- @client = AWS::OpsWorks::Client.new
11
- @layer_id = args[:layer_id]
12
- @recipe = args[:recipe]
13
- @stack_id = args[:stack_id]
14
- @slack_channel = args[:room]
15
- @project = args[:project]
16
- else
17
- puts "No args given"
18
- exit
19
- end
20
- end
21
-
22
- def instance_ids
23
- client = AWS::OpsWorks::Client.new
24
- instance_objects = client.describe_instances(:layer_id => @layer_id)
25
- return instance_objects.instances.map{|i| i.instance_id}.to_a
26
- end
27
-
28
- def deploy
29
- print "#{@project}: Preparing deployment... "
30
- id = @client.create_deployment(
31
- :stack_id => @stack_id,
32
- :instance_ids => instance_ids,
33
- :command => {
34
- name: "execute_recipes",
35
- args: {"recipes" => [@recipe]}
36
- }
37
- )[:deployment_id]
38
- puts "successful"
39
- return id
40
- end
41
-
42
- def update_cookbooks
43
- print "#{@project}: Preparing cookbook update... "
44
-
45
- id = @client.create_deployment(
46
- :stack_id => @stack_id,
47
- :instance_ids => instance_ids,
48
- :command => {name: 'update_custom_cookbooks'}
49
- )[:deployment_id]
50
- puts "successful"
51
- return id
52
- end
53
-
54
-
55
- def status(deployment_id)
56
- @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
57
- end
58
-
59
- def wait_for_completion(deployment_id, task="deployment")
60
- print "#{@project}: Running... "
61
- status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
62
- "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel)
63
- until status != "running"
64
- status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
65
- end
66
- puts status
67
- "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel)
68
- end
69
-
70
- end
71
-
72
- class Stack
73
- end
3
+ require 'ops_tasks/deployment'
4
+ require 'ops_tasks/rake_helper'
5
+ require 'ops_tasks/version'
74
6
  end
@@ -0,0 +1,63 @@
1
+ require 'say2slack'
2
+ require 'aws-sdk'
3
+
4
+ module OpsTasks
5
+ class Deployment
6
+ def initialize(args)
7
+ @client = AWS::OpsWorks::Client.new
8
+ @layer_id = args[:layer_id]
9
+ @recipe = args[:recipe]
10
+ @stack_id = args[:stack_id]
11
+ @slack_channel = args[:room]
12
+ @project = args[:project]
13
+ end
14
+
15
+ def instance_ids
16
+ client = AWS::OpsWorks::Client.new
17
+ instance_objects = client.describe_instances(:layer_id => @layer_id)
18
+ return instance_objects.instances.map{|i| i.instance_id}.to_a
19
+ end
20
+
21
+ def deploy
22
+ print "#{@project}: Preparing deployment... "
23
+ id = @client.create_deployment(
24
+ :stack_id => @stack_id,
25
+ :instance_ids => instance_ids,
26
+ :command => {
27
+ name: "execute_recipes",
28
+ args: {"recipes" => [@recipe]}
29
+ }
30
+ )[:deployment_id]
31
+ puts "successful"
32
+ return id
33
+ end
34
+
35
+ def update_cookbooks
36
+ print "#{@project}: Preparing cookbook update... "
37
+
38
+ id = @client.create_deployment(
39
+ :stack_id => @stack_id,
40
+ :instance_ids => instance_ids,
41
+ :command => {name: 'update_custom_cookbooks'}
42
+ )[:deployment_id]
43
+ puts "successful"
44
+ return id
45
+ end
46
+
47
+
48
+ def status(deployment_id)
49
+ @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
50
+ end
51
+
52
+ def wait_for_completion(deployment_id, task="deployment")
53
+ print "#{@project}: Running... "
54
+ status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
55
+ "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel)
56
+ until status != "running"
57
+ status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
58
+ end
59
+ puts status
60
+ "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,42 @@
1
+ require 'highline/import'
2
+
3
+ module OpsTasks
4
+ class RakeHelper
5
+ def self.servers
6
+ ENV.keys.select do |k|
7
+ k.match(/_stack_id/) && !k.match(/FIGARO/)
8
+ end.map{|k| k.match(/(.+)_stack_id/)[1]}
9
+ end
10
+
11
+ def self.check_for_env_vars
12
+ if servers.empty?
13
+ puts "You haven't setup your layers in your environment variables"
14
+ exit
15
+ end
16
+ end
17
+
18
+ def self.select_server_type
19
+ check_for_env_vars
20
+ @server_type = nil
21
+ say("\nSelect a server...")
22
+ choose do |menu|
23
+ servers.each do |server|
24
+ menu.choice server do @server_type = server end
25
+ end
26
+ menu.choice "quit" do exit end
27
+ end
28
+ return @server_type
29
+ end
30
+
31
+ def self.create_deployment
32
+ server_type = select_server_type
33
+ return OpsTasks::Deployment.new(
34
+ layer_id: ENV["#{server_type}_layer_id"],
35
+ stack_id: ENV["#{server_type}_stack_id"],
36
+ recipe: ENV["#{server_type}_deploy_recipe"],
37
+ project: ENV["#{server_type}_project_name"],
38
+ room: ENV["#{server_type}_slack_channel"]
39
+ )
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module OpsTasks
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,74 +3,18 @@
3
3
  # # Task goes here
4
4
  # end
5
5
 
6
- desc "Deploy to staging"
7
- namespace :staging do
8
- @staging_deployment = OpsTasks::Deployment.new(
9
- layer_id: ENV['staging_layer_id'],
10
- stack_id: ENV['staging_stack_id'],
11
- recipe: ENV['staging_deploy_recipe'],
12
- project: ENV['staging_project_name'],
13
- room: ENV['staging_slack_channel']
14
- )
15
- task :deploy => :environment do
16
- deploy_id = @staging_deployment.deploy
17
- @staging_deployment.wait_for_completion(deploy_id)
18
- end
19
-
20
- task :update_cookbooks => :environment do
21
- deploy_id = @staging_deployment.update_cookbooks
22
- @staging_deployment.wait_for_completion(deploy_id, "update cookbooks")
23
- end
24
-
25
- end
26
-
27
- namespace :production do
28
- @production_deployment = OpsTasks::Deployment.new(
29
- layer_id: ENV['production_layer_id'],
30
- stack_id: ENV['production_stack_id'],
31
- recipe: ENV['production_deploy_recipe'],
32
- project: ENV['production_project_name'],
33
- room: ENV['production_slack_channel']
34
- )
35
-
36
- task :deploy => :environment do
37
- deploy_id = @production_deployment.deploy
38
- @production_deployment.wait_for_completion(deploy_id)
39
- end
40
-
41
- task :update_cookbooks => :environment do
42
- deploy_id = @production_deployment.update_cookbooks
43
- @production_deployment.wait_for_completion(deploy_id, "update cookbooks")
44
- end
45
- end
46
-
47
6
  namespace :ops_tasks do
48
- servers = ENV.keys.select{|k| k.match(/_stack/) && !k.match(/FIGARO/)}.map{|k| k.match(/(.+)_stack_id/)[1]}
49
- if servers.empty?
50
- puts "You haven't setup your layers in your environment variables"
51
- exit
52
- end
53
- say("\nSelect a server...")
54
- choose do |menu|
55
- servers.each do |server|
56
- menu.choice server do @server_type = server end
57
- end
58
- menu.choice "quit" do exit end
59
- end
60
- @deployment = OpsTasks::Deployment.new(
61
- layer_id: ENV["#{@server_type}_layer_id"],
62
- stack_id: ENV["#{@server_type}_stack_id"],
63
- recipe: ENV["#{@server_type}_deploy_recipe"],
64
- project: ENV["#{@server_type}_project_name"],
65
- room: ENV["#{@server_type}_slack_channel"]
66
- )
7
+ desc "deploy with chef recipe"
67
8
  task :deploy => :environment do |t, args|
68
- deploy_id = @deployment.deploy
69
- @deployment.wait_for_completion(deploy_id)
9
+ deployment = OpsTasks::RakeHelper.create_deployment
10
+ deploy_id = deployment.deploy
11
+ deployment.wait_for_completion(deploy_id)
70
12
  end
71
13
 
14
+ desc "update custom cookbooks"
72
15
  task :update_cookbooks => :environment do
73
- deploy_id = @deployment.update_cookbooks
74
- @deployment.wait_for_completion(deploy_id, "update cookbooks")
16
+ deployment = OpsTasks::RakeHelper.create_deployment
17
+ deploy_id = deployment.update_cookbooks
18
+ deployment.wait_for_completion(deploy_id, "update cookbooks")
75
19
  end
76
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Prokesch
@@ -76,7 +76,9 @@ files:
76
76
  - MIT-LICENSE
77
77
  - Rakefile
78
78
  - lib/ops_tasks.rb
79
+ - lib/ops_tasks/deployment.rb
79
80
  - lib/ops_tasks/railtie.rb
81
+ - lib/ops_tasks/rake_helper.rb
80
82
  - lib/ops_tasks/version.rb
81
83
  - lib/tasks/ops_tasks.rake
82
84
  homepage: http://nick.prokes.ch