stax 0.1.3 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 977f337dd555b2e8941cb23a8493af6ada396a3eeba4af49264a26ca7a022d4c
4
- data.tar.gz: cb54eca3f8cad6131164e33b6704c69d48b4ca3b089e07ec27e978beca853ad0
3
+ metadata.gz: 2f2aca89588152ddee959060e8fc3c1dc1bef1c2abb3a57839ab0a35de9aa208
4
+ data.tar.gz: b9bcf76bba2aa8a472c07291596142b6d4338a566abd42636fb9cf8b05b6b7be
5
5
  SHA512:
6
- metadata.gz: f44ff1358eef0fb11b44bdcee1f040757506c5792178b1e895b8e7ebf1f38d6ac43edd39c88effe79e9c257ccf44c6a0db84627e331047ddfdeeb9675b7c2bfb
7
- data.tar.gz: b9d0c14a3b6a99354ecce5f32a8bdf31482abcaffe730d1a76919daa34d0396edb09fc2bf281360613b8abcf2f6f6575795dfdab4d7004dbe600930d93d17296
6
+ metadata.gz: b4f6c035f4c10239132e339ef964be95ac86069a47b6bf0f7f1cf7f25a5b1661d3b0d57a518cde8d4ef018d8dd333cc5bfc6b6db6f71e64846b77839bf037958
7
+ data.tar.gz: 651280004b99781f0d209b9c91179560b75b238dd0faa1431a6f418f94dc1283e9c06e0a6bb9c9636b847898812f9fa8648f052f47aefbe8230d3cc2c3a33074
data/lib/stax/base.rb CHANGED
@@ -132,6 +132,12 @@ module Stax
132
132
  end
133
133
  end
134
134
 
135
+ ## run desktop open command
136
+ def os_open(*args)
137
+ cmd = RUBY_PLATFORM.end_with?('linux') ? 'xdg-open' : 'open'
138
+ system(cmd, *args)
139
+ end
140
+
135
141
  end
136
142
  end
137
- end
143
+ end
data/lib/stax/cli/crud.rb CHANGED
@@ -56,10 +56,11 @@ module Stax
56
56
  end
57
57
 
58
58
  desc 'delete', 'meta delete task'
59
+ method_option :notail, aliases: '-n', type: :boolean, default: false, description: 'do not tail stack events'
59
60
  def delete
60
61
  stack_objects.reverse.each do |s|
61
62
  if s.exists?
62
- s.delete
63
+ s.invoke(:delete, [], options)
63
64
  else
64
65
  say("#{s.stack_name} does not exist", :green)
65
66
  end
@@ -67,4 +68,4 @@ module Stax
67
68
  end
68
69
 
69
70
  end
70
- end
71
+ end
data/lib/stax/docker.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'stax/aws/sts'
2
1
  require 'stax/aws/ecr'
3
2
 
4
3
  module Stax
@@ -7,7 +6,7 @@ module Stax
7
6
  no_commands do
8
7
  ## default to ECR registry for this account
9
8
  def docker_registry
10
- @_docker_registry ||= "#{Aws::Sts.id.account}.dkr.ecr.#{ENV['AWS_REGION']}.amazonaws.com"
9
+ @_docker_registry ||= "#{aws_account_id}.dkr.ecr.#{aws_region}.amazonaws.com"
11
10
  end
12
11
 
13
12
  ## name the docker repo after the git repo
@@ -21,7 +20,7 @@ module Stax
21
20
  end
22
21
 
23
22
  ## build a docker image locally
24
- def docker_local_build
23
+ def docker_build
25
24
  debug("Docker build #{docker_image}")
26
25
  system "docker build -t #{docker_image} #{Git.toplevel}"
27
26
  end
@@ -31,28 +30,6 @@ module Stax
31
30
  debug("Docker push #{docker_image}")
32
31
  system "docker push #{docker_image}"
33
32
  end
34
-
35
- ## override this for your argus setup
36
- def docker_argus_queue
37
- @_docker_argus_queue ||= Aws::Sqs.queue_url('argus.fifo')
38
- end
39
-
40
- def docker_argus_build
41
- debug("Sending to argus #{Git.branch}:#{Git.sha}")
42
- org, repo = Git.repo.split('/')
43
- Aws::Sqs.send(
44
- queue_url: docker_argus_queue,
45
- message_group_id: repo,
46
- message_body: {
47
- org: org,
48
- repo: repo,
49
- branch: Git.branch,
50
- sha: Git.sha,
51
- }.to_json
52
- ).tap do |r|
53
- puts r&.message_id
54
- end
55
- end
56
33
  end
57
34
 
58
35
  desc 'registry', 'show registry name'
@@ -73,8 +50,7 @@ module Stax
73
50
  ## override this method with the desired builder
74
51
  desc 'build', 'build docker image'
75
52
  def build
76
- docker_local_build
77
- # docker_argus_build
53
+ docker_build
78
54
  end
79
55
 
80
56
  desc 'login', 'login to registry'
@@ -103,4 +79,4 @@ module Stax
103
79
  end
104
80
 
105
81
  end
106
- end
82
+ end
@@ -14,6 +14,7 @@ module Stax
14
14
  def stack_project_names
15
15
  @_stack_project_names ||= stack_projects.map(&:physical_resource_id)
16
16
  end
17
+
17
18
  end
18
19
 
19
20
  module Cmd
@@ -34,6 +35,17 @@ module Stax
34
35
  status = p.phase_status || (p.phase_type == 'COMPLETED' ? '' : 'in progress')
35
36
  puts "%-16s %-12s %4s %s" % [p.phase_type, color(status, COLORS), duration, p.end_time]
36
37
  end
38
+
39
+ ## latest run id for a build project
40
+ def latest_run(name)
41
+ Aws::Codebuild.builds_for_project(name, 1).first
42
+ end
43
+
44
+ ## aws console link to latest project run
45
+ def latest_run_link(name)
46
+ id = latest_run(name)
47
+ "https://console.aws.amazon.com/codesuite/codebuild/#{aws_account_id}/projects/#{name}/build/#{id}/?region=#{aws_region}"
48
+ end
37
49
  end
38
50
 
39
51
  desc 'projects', 'list projects'
@@ -118,6 +130,20 @@ module Stax
118
130
  tail build.id
119
131
  end
120
132
 
133
+ desc 'link', 'link to latest run for builds'
134
+ def link
135
+ my.stack_project_names.map do |name|
136
+ puts latest_run_link(name)
137
+ end
138
+ end
139
+
140
+ desc 'open', 'open latest run in aws console'
141
+ def open
142
+ my.stack_project_names.map do |name|
143
+ os_open(latest_run_link(name))
144
+ end
145
+ end
146
+
121
147
  end
122
148
  end
123
- end
149
+ end
@@ -14,6 +14,12 @@ module Stax
14
14
  def stack_pipeline_names
15
15
  @_stack_pipeline_names ||= stack_pipelines.map(&:physical_resource_id)
16
16
  end
17
+
18
+ ## get status string for n-th pipeline
19
+ def stack_pipeline_status(n = 0)
20
+ name = stack_pipeline_names[n]
21
+ Aws::Codepipeline.executions(name, 1)&.first&.status
22
+ end
17
23
  end
18
24
 
19
25
  module Cmd
@@ -29,6 +35,12 @@ module Stax
29
35
  disabled: :red,
30
36
  }
31
37
 
38
+ no_commands do
39
+ def pipeline_link(name)
40
+ "https://console.aws.amazon.com/codesuite/codepipeline/pipelines/#{name}/view?region=#{aws_region}"
41
+ end
42
+ end
43
+
32
44
  desc 'stages', 'list pipeline stages'
33
45
  def stages
34
46
  my.stack_pipeline_names.each do |name|
@@ -54,6 +66,14 @@ module Stax
54
66
  end
55
67
  end
56
68
 
69
+ ## print status as one of InProgress, Stopped, Stopping, Succeeded, Superseded, Failed
70
+ desc 'status', 'pipeline execution status'
71
+ def status
72
+ s = my.stack_pipeline_status
73
+ puts(s)
74
+ exit(1) if s == 'Failed'
75
+ end
76
+
57
77
  desc 'state', 'pipeline state'
58
78
  def state
59
79
  my.stack_pipeline_names.each do |name|
@@ -187,6 +207,20 @@ module Stax
187
207
  end
188
208
  end
189
209
 
210
+ desc 'link', 'link to pipelines in aws console'
211
+ def link
212
+ my.stack_pipeline_names.each do |name|
213
+ puts pipeline_link(name)
214
+ end
215
+ end
216
+
217
+ desc 'open', 'open pipelines in aws console'
218
+ def open
219
+ my.stack_pipeline_names.each do |name|
220
+ os_open(pipeline_link(name))
221
+ end
222
+ end
223
+
190
224
  end
191
225
  end
192
226
  end
@@ -71,11 +71,15 @@ module Stax
71
71
  end
72
72
 
73
73
  def change_set_unlock
74
- Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy_during_update)
74
+ unless stack_policy_during_update.nil?
75
+ Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy_during_update)
76
+ end
75
77
  end
76
78
 
77
79
  def change_set_lock
78
- Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy)
80
+ unless stack_policy.nil?
81
+ Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy)
82
+ end
79
83
  end
80
84
  end
81
85
 
@@ -91,4 +95,4 @@ module Stax
91
95
  end
92
96
 
93
97
  end
94
- end
98
+ end
@@ -24,28 +24,31 @@ module Stax
24
24
  }
25
25
  end
26
26
 
27
- ## policy to lock the stack to all updates
27
+ ## policy to lock the stack to all updates, for example:
28
+ ## {
29
+ ## Statement: [
30
+ ## Effect: 'Deny',
31
+ ## Action: 'Update:*',
32
+ ## Principal: '*',
33
+ ## Resource: '*'
34
+ ## ]
35
+ ## }.to_json
28
36
  def stack_policy
29
- {
30
- Statement: [
31
- Effect: 'Deny',
32
- Action: 'Update:*',
33
- Principal: '*',
34
- Resource: '*'
35
- ]
36
- }.to_json
37
+ nil
37
38
  end
38
39
 
39
- ## temporary policy during updates; modify this to restrict resources
40
+ ## tmp policy during updates, in case a deny was set in stack_policy()
41
+ ## for example:
42
+ ## {
43
+ ## Statement: [
44
+ ## Effect: 'Allow',
45
+ ## Action: 'Update:*',
46
+ ## Principal: '*',
47
+ ## Resource: '*'
48
+ ## ]
49
+ ## }.to_json
40
50
  def stack_policy_during_update
41
- {
42
- Statement: [
43
- Effect: 'Allow',
44
- Action: 'Update:*',
45
- Principal: '*',
46
- Resource: '*'
47
- ]
48
- }.to_json
51
+ nil
49
52
  end
50
53
 
51
54
  ## cleanup sometimes needs to wait
@@ -206,11 +209,12 @@ module Stax
206
209
  end
207
210
 
208
211
  desc 'delete', 'delete stack'
212
+ method_option :notail, aliases: '-n', type: :boolean, default: false, description: 'do not tail stack events'
209
213
  def delete
210
214
  delete_warn_imports
211
215
  if yes? "Really delete stack #{stack_name}?", :yellow
212
216
  Aws::Cfn.delete(stack_name)
213
- tail
217
+ tail unless options[:notail]
214
218
  end
215
219
  rescue ::Aws::CloudFormation::Errors::ValidationError => e
216
220
  fail_task(e.message)
data/lib/stax/staxfile.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Stax
2
2
  @@_root_path = nil
3
3
  @@_stack_list = []
4
+ @@_command_list = []
4
5
 
5
6
  ## the stax root is defined as location of Staxfile
6
7
  def self.root_path
@@ -12,6 +13,11 @@ module Stax
12
13
  @@_stack_list
13
14
  end
14
15
 
16
+ ## list of commands defined in Staxfile
17
+ def self.command_list
18
+ @@_command_list
19
+ end
20
+
15
21
  ## search up the dir tree for nearest Staxfile
16
22
  def self.find_staxfile
17
23
  Pathname.pwd.ascend do |path|
@@ -24,6 +30,7 @@ module Stax
24
30
  if root_path
25
31
  load(root_path.join('Staxfile'))
26
32
  require_stacks
33
+ require_commands
27
34
  end
28
35
  end
29
36
 
@@ -35,6 +42,14 @@ module Stax
35
42
  end
36
43
  end
37
44
 
45
+ ## auto-require any command lib files
46
+ def self.require_commands
47
+ command_list.each do |command|
48
+ f = root_path.join('lib', "#{command}.rb")
49
+ require(f) if File.exist?(f)
50
+ end
51
+ end
52
+
38
53
  ## add a stack by name, creates class as needed
39
54
  def self.add_stack(name, opt = {})
40
55
  @@_stack_list << name
@@ -64,9 +79,14 @@ module Stax
64
79
  end
65
80
 
66
81
  ## add a non-stack command at top level
67
- def self.add_command(name, klass)
82
+ def self.add_command(name, klass = nil)
83
+ @@_command_list << name
84
+
85
+ ## class defaults to eg Stax::Name::Cmd
86
+ klass ||= self.const_get(name.to_s.split(/[_-]/).map(&:capitalize).join + '::Cmd')
87
+
68
88
  Cli.desc(name, "#{name} commands")
69
89
  Cli.subcommand(name, klass)
70
90
  end
71
91
 
72
- end
92
+ end
data/lib/stax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stax
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.7'
3
3
  end
data/stax.gemspec CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "docile", "1.2.0"
27
26
  spec.add_development_dependency "stax-examples"
28
27
 
29
28
  spec.add_dependency('aws-sdk-cloudformation')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: docile
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 1.2.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 1.2.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: stax-examples
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -624,7 +610,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
624
610
  - !ruby/object:Gem::Version
625
611
  version: '0'
626
612
  requirements: []
627
- rubygems_version: 3.1.2
613
+ rubygems_version: 3.1.4
628
614
  signing_key:
629
615
  specification_version: 4
630
616
  summary: Control Cloudformation stack and other stuff.