jets 1.0.15 → 1.0.16

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: 323e6d497caeffa2111a48c2ab940cd8cad422cc41fb079a99ad1f6071bc795d
4
- data.tar.gz: 19f7bfea35f8da3718968ce3792f536abddc895e4ab0678c0365d1f4f4dde569
3
+ metadata.gz: 705c645de879c7e521d0dcb66b90b37e4360c67510ab8ffb8ad16e8755093704
4
+ data.tar.gz: 3a50bef872e5c8851d95fc4ece586ab3b3b006bfaafc752e959d01a58d32674f
5
5
  SHA512:
6
- metadata.gz: 7563eb1344fe0444ec889ddb88c8479bbbf0242bb65a1e2084e670e6baa1585d121ac045a51507981e6c7c8ad416174ebe2a90fffd72d937495b84e58a470e3b
7
- data.tar.gz: d108d1a3b0b1411da955e6c75e8d9d2d74c191cf8cb2e2a880f88d5b6e54d289e9f3a1a5630e1087f160f4419879ee6d4f8f834f5fcd8a23635ec96e8befcc24
6
+ metadata.gz: 34a5e03a72d87f5cab1a02a555e5c9c30c026cc535c1bb4a1c609171201e1c9c9ff8f07f460ef90431a47fd2ed6afac4de9f663fb06ee16747ad1b10f0722b91
7
+ data.tar.gz: 412567cb2846d8d9e0c00c4e9ea8a7e87c775b6ad2220f3e0d0c7d0723a4203bc7730afef6a67a1474caaa0d66a4d7d47af15f7caad2fd1aecac0adf48a36f5a
@@ -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/), even before v1.0.
5
5
 
6
+ ## [1.0.16]
7
+ - fix application iam policy when Jets::Application.default_iam_policy is used in config/application.rb
8
+ - #69 from tongueroo/fix-app-iam-policy
9
+
6
10
  ## [1.0.15]
7
11
  - Fix polymorphic support: #67 from tongueroo/poly-fixes
8
12
  - update .env.development example
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.0.15)
14
+ jets (1.0.16)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
@@ -1,6 +1,8 @@
1
1
  require "active_support/ordered_options"
2
+ require "singleton"
2
3
 
3
4
  class Jets::Application
5
+ include Singleton
4
6
  extend Memoist
5
7
  # Middleware used for development only
6
8
  autoload :Middleware, "jets/application/middleware"
@@ -73,17 +75,31 @@ class Jets::Application
73
75
 
74
76
  def load_configs
75
77
  # The Jets default/application.rb is loaded.
76
- require File.expand_path("../default/application.rb", __FILE__)
78
+ load File.expand_path("../default/application.rb", __FILE__)
77
79
  # Then project config/application.rb is loaded.
78
- app_config = "#{Jets.root}config/application.rb"
79
- require app_config if File.exist?(app_config)
80
- # Normalize config and setup some shortcuts
81
- set_aliases!
82
- normalize_env_vars!
80
+ load_app_config
83
81
  load_db_config
84
82
  load_environments_config
85
83
  end
86
84
 
85
+ # First time loading this might not have all the values. Some values like
86
+ # project_namespace depend on project_name. Loading the config twice
87
+ # resolves the chicken and egg problem here.
88
+ def load_app_config
89
+ eval_app_config
90
+ # Normalize config and setup some shortcuts
91
+ set_dependent_configs! # things like project_namespace that need project_name
92
+ eval_app_config # twice to fix values that rely on the dependent configs
93
+
94
+ set_iam_policy # relies on dependent values, must be called late
95
+ normalize_env_vars!
96
+ end
97
+
98
+ def eval_app_config
99
+ app_config = "#{Jets.root}config/application.rb"
100
+ load app_config if File.exist?(app_config)
101
+ end
102
+
87
103
  def load_environments_config
88
104
  env_file = "#{Jets.root}config/environments/#{Jets.env}.rb"
89
105
  if File.exist?(env_file)
@@ -104,7 +120,7 @@ class Jets::Application
104
120
  production: 'prod',
105
121
  staging: 'stag',
106
122
  }
107
- def set_aliases!
123
+ def set_dependent_configs!
108
124
  # env_extra can be also be set with JETS_ENV_EXTRA.
109
125
  # JETS_ENV_EXTRA higher precedence than config.env_extra
110
126
  config.env_extra = ENV['JETS_ENV_EXTRA'] if ENV['JETS_ENV_EXTRA']
@@ -115,10 +131,6 @@ class Jets::Application
115
131
  config.table_namespace = [config.project_name, config.short_env].compact.join('-')
116
132
 
117
133
  config.project_namespace = Jets.project_namespace
118
-
119
- # Must set default iam_policy here instead of `def config` because we project_namespace
120
- # must have been set and if we call it from `def config` we get an infinite loop
121
- set_iam_policy
122
134
  end
123
135
 
124
136
  def set_iam_policy
@@ -127,12 +139,10 @@ class Jets::Application
127
139
  end
128
140
 
129
141
  # After the mimimal template gets build, we need to reload it for the full stack
130
- # creation. This is confusing to follow. Think we need to clean up the Jets.application
131
- # singleton and make it more explicit?
132
- def reload_iam_policy!
133
- config.iam_policy = nil
134
- config.managed_policy_definitions = nil
135
- set_iam_policy
142
+ # creation. This allows us to reference IAM policies configs that depend on the
143
+ # creation of the s3 bucket.
144
+ def reload_configs!
145
+ load_configs
136
146
  end
137
147
 
138
148
  def self.default_iam_policy
@@ -73,8 +73,15 @@ module Jets
73
73
  stack = resp.stacks.first
74
74
  output = stack["outputs"].find { |o| o["output_key"] == "S3Bucket" }
75
75
  @@s3_bucket = output["output_value"] # s3_bucket
76
- rescue
77
- # rescuing all exceptions in case here
76
+ rescue Exception => e
77
+ # When user uses Jets::Application.default_iam_policy in their config/application.rb
78
+ # it looks up the s3 bucket for the iam policy, but the project name has
79
+ # not been loaded in the config yet. We do some trickery with loading
80
+ # the config twice in Application#load_app_config
81
+ # The first load will result in a Aws::CloudFormation::Errors::ValidationError
82
+ # since the Jets::Naming.parent_stack_name has not been properly set yet.
83
+ #
84
+ # Rescuing all exceptions in case there are other exceptions dont know about yet
78
85
  # Here are the known ones: Aws::CloudFormation::Errors::ValidationError, Aws::CloudFormation::Errors::InvalidClientTokenId
79
86
  BUCKET_DOES_NOT_YET_EXIST
80
87
  end
@@ -19,9 +19,11 @@ module Jets::Commands
19
19
  # Delete existing rollback stack from previous bad minimal deploy
20
20
  delete_minimal_stack if minimal_rollback_complete?
21
21
  exit_unless_updateable! # Stack could be in a weird rollback state or in progress state
22
- ship(stack_type: :minimal) if first_run?
23
22
 
24
- Jets.application.reload_iam_policy!
23
+ if first_run?
24
+ ship(stack_type: :minimal)
25
+ Jets.application.reload_configs!
26
+ end
25
27
 
26
28
  # Build code after the minimal stack because need s3 bucket for assets
27
29
  # on_aws? and s3_base_url logic
@@ -11,7 +11,7 @@ module Jets::Core
11
11
  def application
12
12
  return @@application if @@application
13
13
 
14
- @@application = Jets::Application.new
14
+ @@application = Jets::Application.instance
15
15
  @@application.setup!
16
16
  @@application
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.0.15"
2
+ VERSION = "1.0.16"
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: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-10 00:00:00.000000000 Z
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack