jets 2.1.5 → 2.1.6

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: 8c88605b05a1cab1ca62e2c64ccb6a626cf292d2c7a033dba435754c8448f695
4
- data.tar.gz: 6294de6054d3a1cd06cc865439eba6c83467f464ceeb116f6c5af83423d3868a
3
+ metadata.gz: b18d400a2d0e0f2133d5c6989b979bde0b1ad9e62f3d58256153d0f303b248a8
4
+ data.tar.gz: 24bb4977a7a3ae19a0c10db1e47597d8d5718fb613cb9e9b417ddf15a5aeafea
5
5
  SHA512:
6
- metadata.gz: 27c9b31e58672f9d82eeaca489b2e1fce6c0f2e2cc24fa973d5deb6c06908d137148c41bc38b06bc43c02819548de96151a61638ac4fa1ae4464889207ec9d15
7
- data.tar.gz: cd7d124386d22ee30de783c64ee361a86b44b0a683bc2b5eefd70bb727d194a1bf6e17cc8ec55dadd44e5f47a6c763b719c2808feade605266d18c25b346aaab
6
+ metadata.gz: f6adb65c04917a41ddfbb39d37baac2e5aa49052858a69b45abc6a751d516b7304dd42d5159c7108a0d168fe8776f859182d82070a869ad3100ff9d343fccc96
7
+ data.tar.gz: 370233f6def4284f6d0c26f6e4c48bbe217c40316733628ee71fedcf80b3b1e3e8a33291ad993450cf340244a246796d2bd9e7c69e4b79314c54d76f25aa6072
@@ -7,6 +7,9 @@
7
7
  # cb start:
8
8
  # CODEBUILD_SOURCE_VERSION=codebuild
9
9
 
10
+ git config --global user.email "tongueroo@gmail.com"
11
+ git config --global user.name "Tung Nguyen"
12
+
10
13
  set +u # cb start will not have CODEBUILD_WEBHOOK_TRIGGER set
11
14
  if [ -n "$CODEBUILD_WEBHOOK_TRIGGER" ]; then # git push
12
15
  BRANCH=$(echo $CODEBUILD_WEBHOOK_TRIGGER | sed "s/.*\///")
@@ -16,4 +19,3 @@ else
16
19
  BRANCH=UNKNOWN-BRANCH
17
20
  fi
18
21
  git checkout $BRANCH
19
- set -u
@@ -3,6 +3,8 @@ version: 0.2
3
3
  phases:
4
4
  build:
5
5
  commands:
6
- - git config --global user.email "tongueroo@gmail.com"
7
- - git config --global user.name "Tung Nguyen"
8
6
  - .codebuild/docs/bin/build.sh
7
+ cache:
8
+ paths:
9
+ - /usr/local/bundle
10
+ - /usr/local/lib/ruby/gems/2.5.0
@@ -4,7 +4,7 @@ triggers(
4
4
  webhook: true,
5
5
  filter_groups: [[{type: "HEAD_REF", pattern: "master"}, {type: "EVENT", pattern: "PUSH"}]]
6
6
  )
7
-
8
7
  environment_variables(
9
8
  SSH_KEY_S3_PATH: "ssm:/codebuild/jets/ssh_key_s3_path"
10
9
  )
10
+ local_cache(true)
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [2.1.6]
7
+ - #364 Add stagger deploy option: https://rubyonjets.com/docs/extras/deploy-stagger/
8
+ - codebuild: add caching to speed up build
9
+
6
10
  ## [2.1.5]
7
11
  - perform_later calls perform_now in local mode when not on lambda
8
12
  - fix: clear view cache in development mode
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Ruby and Lambda splat out a baby and that child's name is [Jets](http://rubyonjets.com/).
6
6
 
7
- ![Build Status](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiUE12K3ljQTFQUjVpRW0reGhGVHVQdkplTHlOdUtENnBya2JhVWVXaFIvTU92MlBtV3hIUE9pb25jWGw0MS9jN2RXMERKRHh5Nzhvd01Za0NyeUs5SCtzPSIsIml2UGFyYW1ldGVyU3BlYyI6IkMybEJFaXdzejJEaHNWVmEiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
7
+ ![Build Status](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiRXY0bzFlZS93TUF0cXhDaGdEY2FIbTVtdW43YjB0andmbnRTL3VvbWJOcTBOM3IxWDZPSFh2OHpvczBmdU5QcHpjUThvd084RERORFlvZVI4QWVKcis0PSIsIml2UGFyYW1ldGVyU3BlYyI6IllBZk0xTmVWZ3c2K3VWdTYiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
8
8
  [![CircleCI](https://circleci.com/gh/tongueroo/jets.svg?style=svg)](https://circleci.com/gh/tongueroo/jets)
9
9
  [![Gem Version](https://badge.fury.io/rb/jets.svg)](https://badge.fury.io/rb/jets)
10
10
  [![Support](https://img.shields.io/badge/Support-Help-blue.svg)](http://rubyonjets.com/support/)
@@ -147,6 +147,11 @@ class Jets::Application
147
147
  config.controllers = ActiveSupport::OrderedOptions.new
148
148
  config.controllers.default_protect_from_forgery = nil
149
149
 
150
+ config.deploy = ActiveSupport::OrderedOptions.new
151
+ config.deploy.stagger = ActiveSupport::OrderedOptions.new
152
+ config.deploy.stagger.enabled = false
153
+ config.deploy.stagger.batch_size = 10
154
+
150
155
  config
151
156
  end
152
157
 
@@ -55,7 +55,7 @@ module Jets
55
55
  ENV['AWS_REGION'] ||= region
56
56
  begin
57
57
  sts.get_caller_identity.account
58
- rescue Aws::Errors::MissingCredentialsError
58
+ rescue Aws::Errors::MissingCredentialsError, Aws::Errors::NoSuchEndpointError
59
59
  puts "INFO: You're missing AWS credentials. Only local services are currently available"
60
60
  end
61
61
  end
@@ -35,7 +35,6 @@ module Jets::Cfn::Builders
35
35
 
36
36
  def depends_on_params
37
37
  return {} unless @app_class.depends_on
38
-
39
38
  depends = Jets::Stack::Depends.new(@app_class.depends_on)
40
39
  depends.params
41
40
  end
@@ -4,6 +4,7 @@ module Jets::Cfn::Builders
4
4
  class ParentBuilder
5
5
  include Interface
6
6
  include Jets::AwsServices
7
+ include Stagger
7
8
 
8
9
  def initialize(options={})
9
10
  @options = options
@@ -68,6 +69,7 @@ module Jets::Cfn::Builders
68
69
 
69
70
  def add_app_class_stack(path)
70
71
  resource = Jets::Resource::ChildStack::AppClass.new(@options[:s3_bucket], path: path)
72
+ add_stagger(resource)
71
73
  add_child_resources(resource)
72
74
  end
73
75
 
@@ -0,0 +1,34 @@
1
+ class Jets::Cfn::Builders::ParentBuilder
2
+ module Stagger
3
+ def add_stagger(resource)
4
+ batch_size = stagger_batch_size # shorter convenience variable
5
+ return if !stagger_enabled || batch_size.nil? || batch_size == 0
6
+
7
+ # initialize all here to keep logic together
8
+ @previous_stacks ||= []
9
+ @added_count ||= 0
10
+
11
+ if @previous_stacks.size >= batch_size
12
+ at_boundary = @added_count % batch_size == 0
13
+ if at_boundary
14
+ @left = @added_count - batch_size
15
+ @right = @left + batch_size - 1
16
+ end
17
+ previous_stack_batch = @previous_stacks[@left..@right]
18
+ resource.add_stagger_depends_on(previous_stack_batch)
19
+ end
20
+
21
+ @added_count += 1
22
+ @previous_stacks << resource
23
+ end
24
+
25
+ def stagger_batch_size
26
+ Jets.config.deploy.stagger.batch_size
27
+ end
28
+
29
+ # for spec-ing
30
+ def stagger_enabled
31
+ Jets.config.deploy.stagger.enabled
32
+ end
33
+ end
34
+ end
@@ -29,6 +29,11 @@ module Jets::Lambda
29
29
  super
30
30
  self.subclasses << base if base.name
31
31
  end
32
+
33
+ # Needed for depends_on. Got added due to stagger logic.
34
+ def output_keys
35
+ []
36
+ end
32
37
  end
33
38
  end
34
39
  end
@@ -21,29 +21,40 @@ module Jets::Resource::ChildStack
21
21
  }
22
22
  }
23
23
  }
24
- defintion[logical_id][:depends_on] = depends_on if depends_on
24
+ defintion[logical_id][:depends_on] = depends.stack_list if depends
25
25
  defintion
26
26
  end
27
27
 
28
- def depends_on
29
- klass = current_app_class.constantize
30
- return unless klass.depends_on
28
+ def depends
29
+ return if all_depends_on.empty?
30
+ Jets::Stack::Depends.new(all_depends_on)
31
+ end
32
+ memoize :depends
31
33
 
32
- depends = Jets::Stack::Depends.new(klass.depends_on)
33
- depends.stack_list
34
+ # Always returns an Array, could be empty
35
+ def all_depends_on
36
+ depends_on = current_app_class.depends_on || [] # contains Depends::Items
37
+ stagger_depends_on = @stagger_depends_on || [] # contains Depends::Items
38
+ depends_on + stagger_depends_on
34
39
  end
35
40
 
36
- def depends_on_params
37
- klass = current_app_class.constantize
38
- return unless klass.depends_on
39
- depends = Jets::Stack::Depends.new(klass.depends_on)
40
- depends.params
41
+ # For staggering. We're abusing depends_on to slow down the update rate.
42
+ #
43
+ # For this type of depends_on, there are no template parameters or outputs. To use the normal depends at we would
44
+ # have to make app classes adhere to what Jets::Stack::Depends requires. This is mainly dependency_outputs and
45
+ # output_keys for each class right now. It would not be that difficult but is not needed. So we create the
46
+ # Jets::Stack::Depends::Item objects directly.
47
+ def add_stagger_depends_on(stacks)
48
+ stack_names = stacks.map { |s| s.current_app_class.to_s.underscore }
49
+ items = stack_names.map { |name| Jets::Stack::Depends::Item.new(name) }
50
+ @stagger_depends_on ||= []
51
+ @stagger_depends_on += items.flatten
41
52
  end
42
53
 
43
54
  def parameters
44
55
  common = self.class.common_parameters
45
56
  common.merge!(controller_params) if controller?
46
- common.merge!(depends_on_params) if depends_on
57
+ common.merge!(depends.params) if depends
47
58
  common
48
59
  end
49
60
 
@@ -86,7 +97,7 @@ module Jets::Resource::ChildStack
86
97
 
87
98
  def scoped_routes
88
99
  @routes ||= Jets::Router.routes.select do |route|
89
- route.controller_name == current_app_class
100
+ route.controller_name == current_app_class.to_s
90
101
  end
91
102
  end
92
103
 
@@ -96,6 +107,7 @@ module Jets::Resource::ChildStack
96
107
  .sub(/\.yml$/,'')
97
108
  .gsub('-','/')
98
109
  .camelize
110
+ .constantize
99
111
  end
100
112
 
101
113
  # map the path to a camelized logical_id. Example:
@@ -1,15 +1,15 @@
1
1
  class Jets::Stack
2
2
  class Depends
3
3
  def initialize(items)
4
- @items = items
4
+ @items = items # Jets::Stack::Depends::Item - has stack and options properties
5
5
  end
6
6
 
7
7
  def params
8
8
  result = {}
9
9
  @items.each do |item|
10
- logical_id = item.stack.to_s.camelize # logical_id
11
- dependency_outputs(logical_id).each do |output|
12
- dependency_class = logical_id.to_s.camelize
10
+ class_name = item.class_name
11
+ dependency_outputs(class_name).each do |output|
12
+ dependency_class = class_name.to_s.camelize
13
13
  output_key = item.options[:class_prefix] ?
14
14
  "#{dependency_class}#{output}" : # already camelized
15
15
  output
@@ -21,14 +21,14 @@ class Jets::Stack
21
21
  result
22
22
  end
23
23
 
24
+ # Returns CloudFormation template logical ids
24
25
  def stack_list
25
- @items.map do |item|
26
- item.stack.to_s.camelize # logical_id # logical_id
27
- end
26
+ @items.map(&:logical_id)
28
27
  end
29
28
 
30
- def dependency_outputs(logical_id)
31
- logical_id.to_s.camelize.constantize.output_keys
29
+ private
30
+ def dependency_outputs(class_name)
31
+ class_name.to_s.camelize.constantize.output_keys
32
32
  end
33
33
  end
34
- end
34
+ end
@@ -1,9 +1,26 @@
1
+ # Usage examples:
2
+ #
3
+ # Jets::Stack::Depends::Item.new(:custom)
4
+ # Jets::Stack::Depends::Item.new(:custom, :alert)
5
+ # Jets::Stack::Depends::Item.new(:custom, class_prefix: true)
6
+ # Jets::Stack::Depends::Item.new(:custom, :alert, class_prefix: true)
7
+ #
8
+ # The Jets::Stack::Depends#params uses the options to determine if the class prefix should be added.
9
+ #
1
10
  class Jets::Stack::Depends
2
11
  class Item
3
12
  attr_reader :stack, :options
4
13
  def initialize(stack, options={})
5
- @stack = stack
14
+ @stack = stack # should be underscore format. IE: admin/posts_controller
6
15
  @options = options
7
16
  end
17
+
18
+ def logical_id
19
+ @stack.to_s.gsub('::','').gsub('/','_').camelize
20
+ end
21
+
22
+ def class_name
23
+ @stack.to_s.camelize
24
+ end
8
25
  end
9
26
  end
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "2.1.5"
2
+ VERSION = "2.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-04 00:00:00.000000000 Z
11
+ date: 2019-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -614,6 +614,7 @@ files:
614
614
  - lib/jets/cfn/builders/interface.rb
615
615
  - lib/jets/cfn/builders/job_builder.rb
616
616
  - lib/jets/cfn/builders/parent_builder.rb
617
+ - lib/jets/cfn/builders/parent_builder/stagger.rb
617
618
  - lib/jets/cfn/builders/rule_builder.rb
618
619
  - lib/jets/cfn/builders/shared_builder.rb
619
620
  - lib/jets/cfn/built_template.rb