cody 1.0.4 → 1.1.0

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: a118fa82eafeb143c7566480627541b108c910a45147bb7d3211ea1bccae158e
4
- data.tar.gz: e1505f9f0813a481eccdf1220b44b77879ff3720de6ee5ad8903056853d8568c
3
+ metadata.gz: fd70b6f28e07b8c790325ac4a3c0e7703f60c91bf787d757e2827a61b2eaed48
4
+ data.tar.gz: 353f4fe4eec6dc7b4e0d473f29cc9389a6e907ecfef2a3552b8e4b960873784f
5
5
  SHA512:
6
- metadata.gz: 91a9d29d494a3b75f0f0752924baa5f06236c4d93017f1f02cf0f9059d167de10600fae3f62d5cf7db543c733a7fe4c53dc39ef522329ad0c2cc8df3f2e1606c
7
- data.tar.gz: bad64d35ea10286323bd76d735f8b71e10d81b7b37e327a81137c3e1a2d17735fdc73f260277cf577cd1bb072f10aedd0d93410e3250d1a3f3da62460e250334
6
+ metadata.gz: 1d17eed03ad6069022ca100899bb10739acf31804a7743beed5deb2e9ed17c9dac3967a8e6ae51c6dd268c586e7d86f9f5db21de8763cefe7be1c883da8765bd
7
+ data.tar.gz: 91dfd9d4df7923fb6cb26081a53ec5eb8b6c8d1eda2dddb9882095cab80f9bc253aef38dd694e3ddc1b14eebc824b42885a4f4763a5c8c1da34076ba5d719718
data/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.1.0] - 2022-03-03
7
+ - [#33](https://github.com/tongueroo/cody/pull/33) fix cfn status when auto deleting rollback completed stack
8
+ - [#34](https://github.com/tongueroo/cody/pull/34) iam roles: support multiple calls
9
+ - update iam role docs
10
+
11
+ ## [1.0.6] - 2021-12-17
12
+ - [#32](https://github.com/tongueroo/cody/pull/32) fix activesupport require
13
+ - fix warn not found ssm param message
14
+
15
+ ## [1.0.5] - 2021-08-28
16
+ - add params overrides option
17
+ - docs: fix ecs permission, add iam:GetRole
18
+ - edge case: yaml has nothing but comments
19
+ - improve settings merge
20
+ - update vpc config exmaple with camelcase
21
+
6
22
  ## [1.0.4] - 2021-01-08
7
23
  - loosen activesupport version pin
8
24
 
data/README.md CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
11
11
 
12
+ Please **watch/star** this repo to help grow and support the project.
13
+
12
14
  Cody is an AWS CodeBuild Management Tool. Cody lets you create AWS CodeBuild projects with a beautiful DSL. The documentation site is at: [cody.run](https://cody.run/)
13
15
 
14
16
  ## Quick Start
data/cody.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "cfn-status"
33
33
  spec.add_dependency "cfn_camelizer"
34
34
  spec.add_dependency "cli-format"
35
+ spec.add_dependency "dsl_evaluator"
35
36
  spec.add_dependency "memoist"
36
37
  spec.add_dependency "rainbow"
37
38
  spec.add_dependency "render_me_pretty"
@@ -41,6 +42,7 @@ Gem::Specification.new do |spec|
41
42
  spec.add_development_dependency "bundler"
42
43
  spec.add_development_dependency "byebug"
43
44
  spec.add_development_dependency "cli_markdown"
45
+ spec.add_development_dependency "nokogiri"
44
46
  spec.add_development_dependency "rake"
45
47
  spec.add_development_dependency "rspec"
46
48
  end
@@ -15,6 +15,7 @@ class Cody::CLI
15
15
  source_version: source_version
16
16
  }
17
17
  params[:environment_variables_override] = environment_variables_override if @options[:env_vars]
18
+ params.merge!(@options[:overrides]) if @options[:overrides]
18
19
  resp = codebuild.start_build(params)
19
20
 
20
21
  puts "Build started for project: #{project_name}"
data/lib/cody/cli.rb CHANGED
@@ -37,7 +37,7 @@ module Cody
37
37
  long_desc Help.text(:start)
38
38
  option :source_version, default: "master", desc: "git branch"
39
39
  option :branch, aliases: "b", default: "master", desc: "git branch"
40
- option :env_vars, type: :array, desc: "env var overrides. IE: KEY1=VALUE1 KEY2=VALUE2"
40
+ option :env_vars, aliases: "e", type: :array, desc: "env var overrides. IE: KEY1=VALUE1 KEY2=VALUE2"
41
41
  common_options.call
42
42
  def start(project_name=nil)
43
43
  Start.new(options.merge(project_name: project_name)).run
data/lib/cody/core.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'pathname'
2
2
  require 'yaml'
3
- require 'active_support/core_ext/string'
4
3
 
5
4
  module Cody
6
5
  module Core
data/lib/cody/dsl/base.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Cody::Dsl
2
2
  class Base
3
- attr_reader :project_name, :full_project_name
3
+ attr_reader :options, :project_name, :full_project_name, :type
4
4
  def initialize(options={})
5
5
  @options = options
6
6
  @project_name = options[:project_name]
7
+ @type = options[:type]
7
8
  @full_project_name = options[:full_project_name] # includes -development at the end
8
9
  @properties = default_properties # defaults make project.rb simpler
9
10
  end
@@ -12,7 +12,7 @@ module Cody::Dsl::Project
12
12
 
13
13
  resp.parameter.value
14
14
  rescue Aws::SSM::Errors::ParameterNotFound
15
- puts "WARN: #{name} found on AWS SSM.".color(:yellow)
15
+ puts "WARN: #{name} not found on AWS SSM.".color(:yellow)
16
16
  end
17
17
 
18
18
  def ssm_client
@@ -0,0 +1,25 @@
1
+ require "set"
2
+
3
+ module Cody::Dsl::Role
4
+ class Registry
5
+ class_attribute :iam_statements
6
+ self.iam_statements = nil # nil to allow fallback to default_iam_statements in cody/role.rb
7
+ class_attribute :managed_policy_arns
8
+ self.managed_policy_arns = nil # nil to allow fallback to default_managed_policy_arns in cody/role.rb
9
+
10
+ class << self
11
+ def register_policy(*statements)
12
+ statements.flatten!
13
+ self.iam_statements ||= []
14
+ self.iam_statements += statements # using set so DSL can safely be evaluated multiple times
15
+ end
16
+
17
+ def register_managed_policy(*policies)
18
+ policies.flatten!
19
+ self.managed_policy_arns ||= []
20
+ self.managed_policy_arns += policies # using set so DSL can safely be evaluated multiple times
21
+ self.managed_policy_arns.uniq!
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/cody/dsl/role.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Cody::Dsl
2
2
  module Role
3
+ extend Memoist
4
+
3
5
  PROPERTIES = %w[
4
6
  AssumeRolePolicyDocument
5
7
  ManagedPolicyArns
@@ -17,7 +19,13 @@ module Cody::Dsl
17
19
 
18
20
  # convenience wrapper methods
19
21
  def iam_policy(*definitions)
20
- @iam_statements = definitions.map { |definition| standardize_iam_policy(definition) }
22
+ statements = definitions.map { |definition| standardize_iam_policy(definition) }
23
+ Registry.register_policy(statements)
24
+ end
25
+
26
+ def managed_iam_policy(*definitions)
27
+ managed_policy_arns = definitions.map { |definition| standardize_managed_iam_policy(definition) }
28
+ Registry.register_managed_policy(managed_policy_arns)
21
29
  end
22
30
 
23
31
  # Returns standarized IAM statement
@@ -36,15 +44,15 @@ module Cody::Dsl
36
44
  end
37
45
  end
38
46
 
39
- def managed_iam_policy(*definitions)
40
- @managed_policy_arns = definitions.map { |definition| standardize_managed_iam_policy(definition) }
41
- end
42
-
43
47
  # AmazonEC2ReadOnlyAccess => arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
44
48
  def standardize_managed_iam_policy(definition)
45
49
  return definition if definition.include?('iam::aws:policy')
46
-
47
50
  "arn:aws:iam::aws:policy/#{definition}"
48
51
  end
52
+
53
+ def aws
54
+ AwsData.new
55
+ end
56
+ memoize :aws
49
57
  end
50
58
  end
data/lib/cody/evaluate.rb CHANGED
@@ -1,47 +1,8 @@
1
1
  module Cody
2
2
  module Evaluate
3
+ include DslEvaluator
3
4
  include Interface
4
5
 
5
- def evaluate(path)
6
- source_code = IO.read(path)
7
- begin
8
- instance_eval(source_code, path)
9
- rescue Exception => e
10
- if e.class == SystemExit # allow exit to happen normally
11
- raise
12
- else
13
- task_definition_error(e)
14
- puts "\nFull error:"
15
- raise
16
- end
17
- end
18
- end
19
-
20
- private
21
- # Prints out a user friendly task_definition error message
22
- def task_definition_error(e)
23
- error_info = e.backtrace.first
24
- path, line_no, _ = error_info.split(':')
25
- line_no = line_no.to_i
26
- puts "Error evaluating #{path}:".color(:red)
27
- puts e.message
28
- puts "Here's the line in #{path} with the error:\n\n"
29
-
30
- contents = IO.read(path)
31
- content_lines = contents.split("\n")
32
- context = 5 # lines of context
33
- top, bottom = [line_no-context-1, 0].max, line_no+context-1
34
- spacing = content_lines.size.to_s.size
35
- content_lines[top..bottom].each_with_index do |line_content, index|
36
- line_number = top+index+1
37
- if line_number == line_no
38
- printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
39
- else
40
- printf("%#{spacing}d %s\n", line_number, line_content)
41
- end
42
- end
43
- end
44
-
45
6
  def lookup_cody_file(name)
46
7
  [".cody", @options[:type], name].compact.join("/")
47
8
  end
data/lib/cody/project.rb CHANGED
@@ -18,7 +18,7 @@ module Cody
18
18
 
19
19
  def run
20
20
  load_variables
21
- evaluate(@project_path)
21
+ evaluate_file(@project_path)
22
22
  resource = {
23
23
  CodeBuild: {
24
24
  Type: "AWS::CodeBuild::Project",
data/lib/cody/role.rb CHANGED
@@ -2,9 +2,9 @@ require "yaml"
2
2
 
3
3
  module Cody
4
4
  class Role < Dsl::Base
5
- include Cody::Dsl::Role
6
5
  include Evaluate
7
6
  include Variables
7
+ include Dsl::Role
8
8
 
9
9
  def initialize(options={})
10
10
  super
@@ -14,7 +14,8 @@ module Cody
14
14
 
15
15
  def run
16
16
  load_variables
17
- evaluate(@role_path) if File.exist?(@role_path)
17
+ evaluate_file(@role_path) if File.exist?(@role_path) # registers definitions to registry
18
+ build # build definitions from registry. can set: @iam_statements and @managed_policy_arns
18
19
  @properties[:Policies] = [{
19
20
  PolicyName: "CodeBuildAccess",
20
21
  PolicyDocument: {
@@ -35,6 +36,12 @@ module Cody
35
36
  end
36
37
 
37
38
  private
39
+ Registry = Cody::Dsl::Role::Registry
40
+ def build
41
+ @iam_statements = Registry.iam_statements if Registry.iam_statements
42
+ @managed_policy_arns = Registry.managed_policy_arns if Registry.managed_policy_arns
43
+ end
44
+
38
45
  def get_role_path
39
46
  lookup_cody_file("role.rb")
40
47
  end
data/lib/cody/schedule.rb CHANGED
@@ -15,7 +15,7 @@ module Cody
15
15
 
16
16
  old_properties = @properties.clone
17
17
  load_variables
18
- evaluate(@schedule_path)
18
+ evaluate_file(@schedule_path)
19
19
 
20
20
  @properties[:ScheduleExpression] = @schedule_expression if @schedule_expression
21
21
  set_rule_event! if @rule_event_props
data/lib/cody/setting.rb CHANGED
@@ -25,7 +25,10 @@ module Cody
25
25
 
26
26
  all_envs = default.deep_merge(user.deep_merge(project))
27
27
  all_envs = merge_base(all_envs)
28
- data = all_envs[cb_env] || all_envs["base"] || {}
28
+
29
+ env_data = all_envs[cb_env] || {}
30
+ base_data = all_envs["base"] || {}
31
+ data = base_data.merge(env_data)
29
32
  data.deep_symbolize_keys
30
33
  end
31
34
  memoize :data
@@ -37,6 +40,7 @@ module Cody
37
40
  path = "#{cb_root}/.cody/settings.yml"
38
41
  if File.exist?(path)
39
42
  settings = YAML.load_file(path)
43
+ settings = {} unless settings.is_a?(Hash) # in case YAML has nothing but comments
40
44
  env = settings.find do |_env, section|
41
45
  section ||= {}
42
46
  ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile']
@@ -54,6 +58,7 @@ module Cody
54
58
 
55
59
  content = RenderMePretty.result(path)
56
60
  data = YAML.load(content)
61
+ data = {} unless data.is_a?(Hash) # in case YAML has nothing but comments
57
62
  # If key is is accidentally set to nil it screws up the merge_base later.
58
63
  # So ensure that all keys with nil value are set to {}
59
64
  data.each do |env, _setting|
@@ -1,6 +1,7 @@
1
1
  class Cody::Stack
2
2
  class Base
3
3
  include Cody::AwsServices
4
+ include Status
4
5
 
5
6
  def initialize(options)
6
7
  @options = options
@@ -40,6 +41,7 @@ class Cody::Stack
40
41
  FileUtils.mkdir_p(File.dirname(template_path))
41
42
  IO.write(template_path, YAML.dump(@template))
42
43
  puts "Generated CloudFormation template at #{template_path.color(:green)}"
44
+
43
45
  return if @options[:noop]
44
46
  puts "Deploying stack #{@stack_name.color(:green)} with CodeBuild project #{@full_project_name.color(:green)}"
45
47
 
@@ -68,10 +70,6 @@ class Cody::Stack
68
70
  puts "Here's the CloudFormation url to check for more details #{url}"
69
71
  end
70
72
 
71
- def status
72
- @status ||= CfnStatus.new(@stack_name)
73
- end
74
-
75
73
  def rollback_complete?(stack)
76
74
  stack.stack_status == 'ROLLBACK_COMPLETE'
77
75
  end
@@ -0,0 +1,7 @@
1
+ class Cody::Stack
2
+ module Status
3
+ def status
4
+ @status ||= CfnStatus.new(@stack_name)
5
+ end
6
+ end
7
+ end
data/lib/cody/stack.rb CHANGED
@@ -3,6 +3,7 @@ require "aws-sdk-cloudformation"
3
3
  module Cody
4
4
  class Stack
5
5
  include Cody::AwsServices
6
+ include Status
6
7
 
7
8
  def initialize(options)
8
9
  @options = options
data/lib/cody/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cody
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/cody.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  $:.unshift(File.expand_path("../", __FILE__))
2
+ require "active_support"
3
+ require "active_support/core_ext/string"
2
4
  require "aws_data"
3
5
  require "cfn_camelizer"
4
6
  require "cfn_status"
5
7
  require "cody/version"
8
+ require "dsl_evaluator"
6
9
  require "memoist"
7
10
  require "rainbow/ext/string"
8
11
  require "yaml"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cody
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dsl_evaluator
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: memoist
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +276,20 @@ dependencies:
262
276
  - - ">="
263
277
  - !ruby/object:Gem::Version
264
278
  version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: nokogiri
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
265
293
  - !ruby/object:Gem::Dependency
266
294
  name: rake
267
295
  requirement: !ruby/object:Gem::Requirement
@@ -343,6 +371,7 @@ files:
343
371
  - lib/cody/dsl/project.rb
344
372
  - lib/cody/dsl/project/ssm.rb
345
373
  - lib/cody/dsl/role.rb
374
+ - lib/cody/dsl/role/registry.rb
346
375
  - lib/cody/dsl/schedule.rb
347
376
  - lib/cody/evaluate.rb
348
377
  - lib/cody/evaluate/interface.rb
@@ -355,6 +384,7 @@ files:
355
384
  - lib/cody/stack.rb
356
385
  - lib/cody/stack/base.rb
357
386
  - lib/cody/stack/create.rb
387
+ - lib/cody/stack/status.rb
358
388
  - lib/cody/stack/update.rb
359
389
  - lib/cody/tailer.rb
360
390
  - lib/cody/variables.rb
@@ -387,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
387
417
  - !ruby/object:Gem::Version
388
418
  version: '0'
389
419
  requirements: []
390
- rubygems_version: 3.1.4
420
+ rubygems_version: 3.2.32
391
421
  signing_key:
392
422
  specification_version: 4
393
423
  summary: Cody provides a beautiful DSL to create and manage AWS CodeBuild projects