elastic_beans 0.11.0 → 0.12.0.alpha1

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: 898ac7c02cc660301cfce8d699f23b0fd3c161b7
4
- data.tar.gz: ee4f74a9d7d591faa9d3376451807e5dd619376c
3
+ metadata.gz: f7c0cd1ef593783f14539924dda68021f78c5fa0
4
+ data.tar.gz: 9d3f42eee3bff3cfa8e9af2c59fe0cf492661ed2
5
5
  SHA512:
6
- metadata.gz: 144633191d7abad8a541fc518f9f6331c5b2e77019ae757aa5317f3854c2194804d4dec47c691afb2da357df19ef90057a979f586ee22e9151690570c879b6b5
7
- data.tar.gz: 2c8dc693592e823cac5def085ed5a0405a78dfdb5b6050c19c6d2011d1065f8da868a2287dbc5d5e67284e221a768f4c87b881cd8b5426a5177f05fed4a8eea0
6
+ metadata.gz: 9764af5c4d6cf9637a21a6383bb52d04adbf37c0fdeeaa99ecb40155666b301368ff77e842a6b0e3fa615e6134f8c88289b444a305f5d29a43e92c71185a48ee
7
+ data.tar.gz: 7c144fa1983ea8de3dda5623892c94e625f05b2082fda65b758a1070462986d6f216b1e7a47fd274b58532943a9995fadf21c4c0662a615b09328596acd49c0d
data/README.md CHANGED
@@ -24,9 +24,11 @@ As the SDK documentation suggests, using environment variables is recommended.
24
24
 
25
25
  # Pre-configure the application before creating environments
26
26
  beans configure -n myapp-networking -a myapp \
27
- -b SECRET_KEY_BASE -d DATABASE_URL -k KEYPAIR \
28
- -p INTERNAL_PUBLIC_KEY -s SSL_CERTIFICATE_ARN \
29
- [-i IMAGE_ID] [-t INSTANCE_TYPE]
27
+ -p INTERNAL_PUBLIC_KEY -s SSL_CERTIFICATE_ARN -k KEYPAIR \
28
+ [-o 'OPTION_SETTING_NAMESPACE/OPTION_NAME=VALUE'...]
29
+ beans setenv -a myapp \
30
+ DATABASE_URL=mysql2://db.example.com:3306/myapp \
31
+ SECRET_KEY_BASE=abc123
30
32
 
31
33
  # Create a webserver environment with a pretty DNS name at myapp.TLD (managed by Route53)
32
34
  beans create -a myapp [-d myapp.TLD] [--tags=Environment:production Team:Unicorn] webserver
@@ -63,9 +65,8 @@ As the SDK documentation suggests, using environment variables is recommended.
63
65
 
64
66
  # Update all existing environments and configuration
65
67
  beans configure -n myapp-networking -a myapp \
66
- [-b SECRET_KEY_BASE] [-d DATABASE_URL] [-k KEYPAIR] \
67
- [-p INTERNAL_PUBLIC_KEY] [-s SSL_CERTIFICATE_ARN] \
68
- [-i IMAGE_ID] [-t INSTANCE_TYPE]
68
+ [-p INTERNAL_PUBLIC_KEY] [-s SSL_CERTIFICATE_ARN] [-k KEYPAIR] \
69
+ [-o 'OPTION_SETTING_NAMESPACE/OPTION_NAME=VALUE'...]
69
70
 
70
71
  ### API
71
72
 
data/exe/beans CHANGED
@@ -2,14 +2,18 @@
2
2
 
3
3
  Signal.trap("INT") do
4
4
  puts "\nInterrupting beans -- if an operation was in progress, it will still be running."
5
- exit 130
5
+ raise Interrupt
6
6
  end
7
7
 
8
8
  Signal.trap("TERM") do
9
9
  puts "Terminating beans -- if an operation was in progress, it will still be running."
10
- exit 143
10
+ raise SignalException.new("TERM")
11
11
  end
12
12
 
13
13
  require "elastic_beans/cli"
14
14
 
15
- ElasticBeans::CLI.start(ARGV)
15
+ begin
16
+ ElasticBeans::CLI.start(ARGV)
17
+ rescue SignalException => e
18
+ exit(128 + e.signo)
19
+ end
@@ -16,25 +16,21 @@ class ElasticBeans::CLI < Thor
16
16
  long_desc ElasticBeans::Command::Configure::LONG_DESC
17
17
  option :application, aliases: %w(-a), required: true, desc: APPLICATION_DESC
18
18
  option :network, aliases: %w(-n), required: true, desc: "The name of the CloudFormation stack that contains networking settings"
19
- option :database_url, aliases: %w(-d), desc: "The DATABASE_URL for the Rails application"
20
- option :image_id, aliases: %w(-i), desc: "A custom AMI to use instead of the default Ruby Elastic Beanstalk AMI"
21
- option :instance_type, aliases: %w(-t), desc: "A default instance type to use for all environments instead of c4.large"
22
19
  option :internal, type: :boolean, desc: "Configure the webserver to only be available for internal VPC access"
23
20
  option :keypair, aliases: %w(-k), desc: "Required on first run. The EC2 keypair to use for Elastic Beanstalk instances"
21
+ option :option_settings, aliases: %w(-o), type: :array, default: [], desc: "Option settings to configure, format is NAMESPACE/OPTION_NAME=VALUE, e.g. aws:ec2:vpc/ELBScheme=internal"
22
+ option :option_settings_to_remove, aliases: %w(-r), type: :array, default: [], desc: "Option settings to remove, format is NAMESPACE/OPTION_NAME, e.g. aws:ec2:vpc/ELBScheme"
24
23
  option :public_key, aliases: %w(-p), desc: "For end-to-end encryption. The public key of the SSL certificate the ELB will verify to communicate with your Rails app"
25
- option :secret_key_base, aliases: %w(-b), desc: "The SECRET_KEY_BASE for the Rails application"
26
24
  option :ssl_certificate_arn, aliases: %w(-s), desc: "The ARN of the SSL server certificate stored in IAM to attach to the ELB"
27
25
  def configure
28
26
  @verbose = options[:verbose]
29
27
  ElasticBeans::Command::Configure.new(
30
- database_url: options[:database_url],
31
- image_id: options[:image_id],
32
- instance_type: options[:instance_type],
33
28
  internal: options[:internal],
34
29
  keypair: options[:keypair],
35
30
  public_key: options[:public_key],
36
- secret_key_base: options[:secret_key_base],
37
31
  ssl_certificate_arn: options[:ssl_certificate_arn],
32
+ option_settings: options[:option_settings],
33
+ option_settings_to_remove: options[:option_settings_to_remove],
38
34
  application: application(name: options[:application]),
39
35
  network: network(stack_name: options[:network]),
40
36
  elastic_beanstalk: elastic_beanstalk_client,
@@ -16,28 +16,24 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
16
16
  LONG_DESC
17
17
 
18
18
  def initialize(
19
- database_url:,
20
- image_id:,
21
- instance_type:,
22
19
  internal:,
23
20
  keypair:,
24
21
  public_key:,
25
- secret_key_base:,
26
22
  ssl_certificate_arn:,
23
+ option_settings:,
24
+ option_settings_to_remove:,
27
25
  application:,
28
26
  network:,
29
27
  elastic_beanstalk:,
30
28
  iam:,
31
29
  ui:
32
30
  )
33
- @database_url = database_url
34
- @image_id = image_id
35
- @instance_type = instance_type
36
31
  @internal = internal
37
32
  @keypair = keypair
38
33
  @public_key = public_key
39
- @secret_key_base = secret_key_base
40
34
  @ssl_certificate_arn = ssl_certificate_arn
35
+ @option_setting_strings = option_settings
36
+ @option_strings_to_remove = option_settings_to_remove
41
37
  @application = application
42
38
  @network = network
43
39
  @elastic_beanstalk = elastic_beanstalk
@@ -64,11 +60,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
64
60
  )
65
61
  base_config.upsert(
66
62
  network: network,
67
- database_url: database_url,
68
- secret_key_base: secret_key_base,
69
- image_id: image_id,
70
- instance_type: instance_type,
71
63
  keypair: keypair,
64
+ option_settings: option_settings,
65
+ options_to_remove: options_to_remove,
72
66
  iam: iam,
73
67
  )
74
68
  progressbar.increment
@@ -80,12 +74,10 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
80
74
  )
81
75
  webserver_config.upsert(
82
76
  network: network,
83
- database_url: database_url,
84
- secret_key_base: secret_key_base,
85
- image_id: image_id,
86
- instance_type: instance_type,
87
77
  internal: internal,
88
78
  keypair: keypair,
79
+ option_settings: option_settings,
80
+ options_to_remove: options_to_remove,
89
81
  iam: iam,
90
82
  public_key: public_key,
91
83
  ssl_certificate_arn: ssl_certificate_arn,
@@ -106,11 +98,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
106
98
  )
107
99
  exec_config.upsert(
108
100
  network: network,
109
- database_url: database_url,
110
- secret_key_base: secret_key_base,
111
- image_id: image_id,
112
- instance_type: instance_type,
113
101
  keypair: keypair,
102
+ option_settings: option_settings,
103
+ options_to_remove: options_to_remove,
114
104
  iam: iam,
115
105
  )
116
106
  exec_environment = exec_config.environment
@@ -129,11 +119,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
129
119
  )
130
120
  scheduler_config.upsert(
131
121
  network: network,
132
- database_url: database_url,
133
- secret_key_base: secret_key_base,
134
- image_id: image_id,
135
- instance_type: instance_type,
136
122
  keypair: keypair,
123
+ option_settings: option_settings,
124
+ options_to_remove: options_to_remove,
137
125
  iam: iam,
138
126
  )
139
127
  scheduler_environment = scheduler_config.environment
@@ -154,11 +142,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
154
142
  )
155
143
  worker_config.upsert(
156
144
  network: network,
157
- database_url: database_url,
158
- secret_key_base: secret_key_base,
159
- image_id: image_id,
160
- instance_type: instance_type,
161
145
  keypair: keypair,
146
+ option_settings: option_settings,
147
+ options_to_remove: options_to_remove,
162
148
  iam: iam,
163
149
  )
164
150
  worker_environment = worker_config.environment
@@ -178,19 +164,75 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
178
164
 
179
165
  attr_reader(
180
166
  :application,
181
- :database_url,
182
- :image_id,
183
- :instance_type,
184
167
  :internal,
185
168
  :keypair,
186
169
  :network,
187
170
  :public_key,
188
- :secret_key_base,
189
171
  :ssl_certificate_arn,
190
172
  :elastic_beanstalk,
191
173
  :iam,
192
174
  :ui,
193
175
  )
176
+
177
+ # Coerces +@option_setting_strings+ into object format.
178
+ def option_settings
179
+ @option_settings ||= @option_setting_strings.map { |option_setting_string|
180
+ setting, value = option_setting_string.split('=', 2)
181
+ if !setting || setting.empty? || !value || value.empty?
182
+ raise InvalidOptionSettingFormatError
183
+ end
184
+ namespace, option_name = setting.split('/', 2)
185
+ if !namespace || namespace.empty? || !option_name || option_name.empty?
186
+ raise InvalidOptionSettingFormatError
187
+ end
188
+ {namespace: namespace, option_name: option_name, value: value}
189
+ }
190
+ end
191
+
192
+ # Coerces +@option_strings_to_remove+ into object format.
193
+ def options_to_remove
194
+ @options_to_remove ||= @option_strings_to_remove.map { |option_setting_string|
195
+ namespace, option_name = option_setting_string.split('/', 2)
196
+ if !namespace || namespace.empty? || !option_name || option_name.empty? || option_name.include?('=')
197
+ raise InvalidOptionSettingFormatError
198
+ end
199
+ {namespace: namespace, option_name: option_name}
200
+ }
201
+ end
202
+
203
+ # :nodoc: all
204
+ # @!visibility private
205
+ class InvalidOptionSettingFormatError < ElasticBeans::Error
206
+ def message
207
+ require "elastic_beans/cli"
208
+ require "elastic_beans/cli/string_shell"
209
+ <<-MESSAGE
210
+ Invalid format for --option-settings.
211
+ Option settings should in the format 'NAMESPACE/OPTION_NAME=VALUE', e.g. 'aws:autoscaling:asg/Cooldown=180'.
212
+ If you'd like to *remove* option settings, use --option-settings-to-remove 'NAMESPACE/OPTION_NAME'.
213
+ Please re-run `#{command_as_string "configure"}` with updated syntax.
214
+
215
+ #{command_help "configure"}
216
+ MESSAGE
217
+ end
218
+ end
219
+
220
+ # :nodoc: all
221
+ # @!visibility private
222
+ class InvalidOptionSettingsToRemoveFormatError < ElasticBeans::Error
223
+ def message
224
+ require "elastic_beans/cli"
225
+ require "elastic_beans/cli/string_shell"
226
+ <<-MESSAGE
227
+ Invalid format for --option-settings-to-remove.
228
+ Option settings to remove should in the format 'NAMESPACE/OPTION_NAME', e.g. 'aws:autoscaling:asg/Cooldown'.
229
+ If you'd like to *set* option settings, use --option-settings 'NAMESPACE/OPTION_NAME=VALUE'.
230
+ Please re-run `#{command_as_string "configure"}` with updated syntax.
231
+
232
+ #{command_help "configure"}
233
+ MESSAGE
234
+ end
235
+ end
194
236
  end
195
237
  end
196
238
  end
@@ -109,9 +109,13 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
109
109
  rescue ElasticBeans::SSH::BastionAuthenticationError => e
110
110
  raise BastionAuthenticationError.new(cause: e)
111
111
  ensure
112
- ui.info("Cleaning up, please do not interrupt!")
113
- application.kill_command(freeze_command)
114
- application.deregister_command(command)
112
+ begin
113
+ ui.info("Cleaning up, please do not interrupt!")
114
+ application.kill_command(freeze_command)
115
+ application.deregister_command(command)
116
+ rescue Interrupt
117
+ retry
118
+ end
115
119
  end
116
120
  else
117
121
  application.enqueue_command(command)
@@ -13,66 +13,56 @@ module ElasticBeans
13
13
  protected
14
14
 
15
15
  # Constructs the common configuration for all environments.
16
- # +network+, +database_url+, +secret_key_base+, +keypair+, and +iam+ are all required on first run.
16
+ # +network+, +keypair+, and +iam+ are all required on first run.
17
17
  def build_option_settings(
18
18
  network: nil,
19
- database_url: nil,
20
- secret_key_base: nil,
21
19
  keypair: nil,
22
20
  iam: nil,
23
- image_id: nil,
24
- instance_type: nil,
25
21
  min_size: nil,
26
22
  max_size: nil,
23
+ option_settings: [],
27
24
  **_
28
25
  )
29
26
  template = configuration_settings_description("base")
30
27
 
31
- instance_profile_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam))
28
+ instance_profile_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam), new_settings: option_settings)
32
29
  if instance_profile_setting[:value].nil?
33
30
  raise MissingInstanceProfileError
34
31
  end
35
32
 
36
- keypair_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair)
37
- database_url_setting = template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DATABASE_URL", override: database_url)
38
- secret_key_base_setting = template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "SECRET_KEY_BASE", override: secret_key_base)
39
- if database_url_setting[:value].nil? || secret_key_base_setting[:value].nil? || keypair_setting[:value].nil?
33
+ keypair_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair, new_settings: option_settings)
34
+ if keypair_setting[:value].nil?
40
35
  raise MissingOptionsError.new(
41
- database_url: database_url_setting[:value],
42
- secret_key_base: secret_key_base_setting[:value],
43
36
  keypair: keypair_setting[:value],
44
37
  )
45
38
  end
46
39
 
47
40
  config_path = "#{application.bucket_name}/#{application.env_vars.s3_key}"
48
- settings = [
49
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1"),
50
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed"),
51
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling"),
52
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true"),
53
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path),
54
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role"),
55
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced"),
56
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false"),
57
- template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size),
58
- template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size),
59
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "InstanceType", default: "c4.large", override: instance_type),
60
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32"),
61
- template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health"),
62
- template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true"),
63
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network)),
64
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network)),
65
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network)),
66
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network)),
41
+ super + [
42
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1", new_settings: option_settings),
43
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed", new_settings: option_settings),
44
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling", new_settings: option_settings),
45
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true", new_settings: option_settings),
46
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path, new_settings: option_settings),
47
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role", new_settings: option_settings),
48
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced", new_settings: option_settings),
49
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false", new_settings: option_settings),
50
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size, new_settings: option_settings),
51
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size, new_settings: option_settings),
52
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32", new_settings: option_settings),
53
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health", new_settings: option_settings),
54
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true", new_settings: option_settings),
55
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network), new_settings: option_settings),
56
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network), new_settings: option_settings),
57
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network), new_settings: option_settings),
58
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network), new_settings: option_settings),
67
59
  instance_profile_setting,
68
60
  keypair_setting,
69
- database_url_setting,
70
- secret_key_base_setting,
71
61
  ]
72
- if image_id
73
- settings << template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "ImageId", override: image_id)
74
- end
75
- settings
62
+ end
63
+
64
+ def source_configuration
65
+ nil
76
66
  end
77
67
 
78
68
  private
@@ -127,9 +117,7 @@ module ElasticBeans
127
117
  # :nodoc: all
128
118
  # @!visibility private
129
119
  class MissingOptionsError < ElasticBeans::Error
130
- def initialize(database_url:, secret_key_base:, keypair:)
131
- @database_url = database_url
132
- @secret_key_base = secret_key_base
120
+ def initialize(keypair:)
133
121
  @keypair = keypair
134
122
  end
135
123
 
@@ -137,15 +125,9 @@ module ElasticBeans
137
125
  require "elastic_beans/cli"
138
126
  require "elastic_beans/cli/string_shell"
139
127
  msg = "Some required options are missing and must be set when configuring an application:\n\n"
140
- if @database_url.nil?
141
- msg << "--database-url DATABASE_URL must point to a valid database, and is required for running a Rails application\n"
142
- end
143
128
  if @keypair.nil?
144
129
  msg << "--keypair KEYPAIR must be a valid EC2 key pair, and will be used on Elastic Beanstalk instances\n"
145
130
  end
146
- if @secret_key_base.nil?
147
- msg << "--secret-key-base SECRET_KEY_BASE can be any value, and is required for running a Rails application\n"
148
- end
149
131
  msg << <<-MESSAGE
150
132
 
151
133
  Please re-run `#{command_as_string "configure"}` with these options.
@@ -12,14 +12,18 @@ module ElasticBeans
12
12
  protected
13
13
 
14
14
  # Constructs the configuration for the exec environment.
15
- def build_option_settings(**_)
15
+ def build_option_settings(option_settings: [], **_)
16
16
  super + [
17
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
18
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
19
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_EXEC_QUEUE_URL", override: application.exec_queue_url),
20
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
17
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
18
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
19
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_EXEC_QUEUE_URL", override: application.exec_queue_url, new_settings: option_settings),
20
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
21
21
  ]
22
22
  end
23
+
24
+ def source_configuration
25
+ SOURCE_CONFIGURATION
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -11,13 +11,17 @@ module ElasticBeans
11
11
 
12
12
  # Constructs the configuration for the scheduler environment.
13
13
  # No special options here!
14
- def build_option_settings(**_)
14
+ def build_option_settings(option_settings: [], **_)
15
15
  super + [
16
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
17
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
18
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
16
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
17
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
18
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
19
19
  ]
20
20
  end
21
+
22
+ def source_configuration
23
+ SOURCE_CONFIGURATION
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -13,35 +13,35 @@ module ElasticBeans
13
13
 
14
14
  # Constructs the configuration for the webserver environment.
15
15
  # All arguments are required on first run.
16
- def build_option_settings(network: nil, public_key: nil, ssl_certificate_arn: nil, internal: nil, **_)
17
- public_key_policy_names_setting = template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "PublicKeyPolicyNames", default: "backendkey")
18
- public_key_setting = template_option_setting(namespace: "aws:elb:policies:#{public_key_policy_names_setting[:value]}", option_name: "PublicKey", override: public_key)
19
- ssl_certificate_setting = template_option_setting(namespace: "aws:elb:listener:443", option_name: "SSLCertificateId", override: ssl_certificate_arn)
16
+ def build_option_settings(network: nil, public_key: nil, ssl_certificate_arn: nil, internal: nil, option_settings: [], **_)
17
+ public_key_policy_names_setting = template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "PublicKeyPolicyNames", default: "backendkey", new_settings: option_settings)
18
+ public_key_setting = template_option_setting(namespace: "aws:elb:policies:#{public_key_policy_names_setting[:value]}", option_name: "PublicKey", override: public_key, new_settings: option_settings)
19
+ ssl_certificate_setting = template_option_setting(namespace: "aws:elb:listener:443", option_name: "SSLCertificateId", override: ssl_certificate_arn, new_settings: option_settings)
20
20
  if public_key_setting[:value].nil? || ssl_certificate_setting[:value].nil?
21
21
  raise NoEncryptionSettingsError
22
22
  end
23
23
 
24
- option_settings = [
25
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTPS:443/", allow_blank: false),
26
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "false"),
27
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "false"),
28
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstancePort", default: "443"),
29
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstanceProtocol", default: "HTTPS"),
30
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "ListenerProtocol", default: "HTTPS"),
31
- template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "ManagedSecurityGroup", override: managed_security_group(network)),
32
- template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "SecurityGroups", override: elb_security_groups(network)),
33
- template_option_setting(namespace: "aws:elb:policies", option_name: "ConnectionDrainingEnabled", default: "true"),
34
- template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "InstancePorts", default: "443"),
24
+ settings = [
25
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTPS:443/", allow_blank: false, new_settings: option_settings),
26
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "false", new_settings: option_settings),
27
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "false", new_settings: option_settings),
28
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstancePort", default: "443", new_settings: option_settings),
29
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstanceProtocol", default: "HTTPS", new_settings: option_settings),
30
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "ListenerProtocol", default: "HTTPS", new_settings: option_settings),
31
+ template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "ManagedSecurityGroup", override: managed_security_group(network), new_settings: option_settings),
32
+ template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "SecurityGroups", override: elb_security_groups(network), new_settings: option_settings),
33
+ template_option_setting(namespace: "aws:elb:policies", option_name: "ConnectionDrainingEnabled", default: "true", new_settings: option_settings),
34
+ template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "InstancePorts", default: "443", new_settings: option_settings),
35
35
  public_key_policy_names_setting,
36
36
  public_key_setting,
37
37
  ssl_certificate_setting,
38
38
  ]
39
39
  if internal
40
- internal_setting = template_option_setting(namespace: "aws:ec2:vpc", option_name: "ELBScheme", override: "internal")
41
- option_settings << internal_setting
40
+ internal_setting = template_option_setting(namespace: "aws:ec2:vpc", option_name: "ELBScheme", override: "internal", new_settings: option_settings)
41
+ settings << internal_setting
42
42
  end
43
43
 
44
- super + option_settings
44
+ super + settings
45
45
  end
46
46
 
47
47
  # Removes the "internal" ELB scheme if explicitly disabled with --no-internal.
@@ -64,6 +64,10 @@ module ElasticBeans
64
64
  network.elb_security_groups[0] if network
65
65
  end
66
66
 
67
+ def source_configuration
68
+ SOURCE_CONFIGURATION
69
+ end
70
+
67
71
  # :nodoc: all
68
72
  # @!visibility private
69
73
  class NoEncryptionSettingsError < ElasticBeans::Error
@@ -24,17 +24,21 @@ module ElasticBeans
24
24
  # Constructs the configuration for the worker environments.
25
25
  # No special arguments, the +queue+ name is stored from the initializer and is used to look up the appropriate
26
26
  # URL.
27
- def build_option_settings(**_)
27
+ def build_option_settings(option_settings: [], **_)
28
28
  super + [
29
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
30
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
31
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
32
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "InactivityTimeout", default: "1800"),
33
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "MaxRetries", default: "10"),
34
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "VisibilityTimeout", default: "1800"),
35
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "WorkerQueueURL", override: application.worker_queue_url(queue)),
29
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
30
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
31
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
32
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "InactivityTimeout", default: "1800", new_settings: option_settings),
33
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "MaxRetries", default: "10", new_settings: option_settings),
34
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "VisibilityTimeout", default: "1800", new_settings: option_settings),
35
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "WorkerQueueURL", override: application.worker_queue_url(queue), new_settings: option_settings),
36
36
  ]
37
37
  end
38
+
39
+ def source_configuration
40
+ SOURCE_CONFIGURATION
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -11,7 +11,10 @@ module ElasticBeans
11
11
  # namespace) directly.
12
12
  class ConfigurationTemplate
13
13
  # The solution stack used for a new application. Should not be hardcoded, but here we are.
14
- SOLUTION_STACK_NAME = "64bit Amazon Linux 2016.09 v2.2.0 running Ruby 2.3 (Puma)"
14
+ SOLUTION_STACK_NAME = "64bit Amazon Linux 2016.09 v2.3.3 running Ruby 2.3 (Puma)"
15
+ # The source configuration for new configuration templates.
16
+ # Set to ElasticBeans::ConfigurationTemplate::Base to include all custom configuration that has already been performed.
17
+ SOURCE_CONFIGURATION = {template_name: "base"}
15
18
  # :category: Internal
16
19
  WORKER_TEMPLATE_NAME_PATTERN = /\Aworker-(?<queue>\w+)\z/
17
20
 
@@ -120,6 +123,7 @@ module ElasticBeans
120
123
  application_name: application.name,
121
124
  template_name: name,
122
125
  solution_stack_name: SOLUTION_STACK_NAME,
126
+ source_configuration: source_configuration,
123
127
  option_settings: option_settings,
124
128
  )
125
129
  end
@@ -135,12 +139,17 @@ module ElasticBeans
135
139
  # :category: Internal
136
140
  attr_reader :elastic_beanstalk
137
141
 
138
- def build_option_settings(**_)
139
- []
142
+ # Returns option settings that should be set on the template.
143
+ def build_option_settings(option_settings: [], **_)
144
+ option_settings
140
145
  end
141
146
 
142
- def build_options_to_remove(**_)
143
- []
147
+ # Returns option settings that should be removed from the template.
148
+ # Will not remove settings that beans has defaults for, even if they aren't being changed right now.
149
+ def build_options_to_remove(options_to_remove: [], **_)
150
+ options_to_remove.reject { |setting|
151
+ option_settings.any? { |new_setting| new_setting[:namespace] == setting[:namespace] && new_setting[:option_name] == setting[:option_name] }
152
+ }
144
153
  end
145
154
 
146
155
  def configuration_settings_description(template_name = name)
@@ -181,6 +190,10 @@ module ElasticBeans
181
190
  retry
182
191
  end
183
192
 
193
+ def source_configuration
194
+ SOURCE_CONFIGURATION
195
+ end
196
+
184
197
  def template_option_setting(
185
198
  template: configuration_settings_description,
186
199
  environment: environment_configuration_settings_description,
@@ -188,13 +201,21 @@ module ElasticBeans
188
201
  option_name:,
189
202
  default: nil,
190
203
  override: nil,
191
- allow_blank: true
204
+ allow_blank: true,
205
+ new_settings:
192
206
  )
193
207
  option_setting = {namespace: namespace, option_name: option_name, value: default}
194
208
  if override
195
209
  return option_setting.merge!(value: override)
196
210
  end
197
211
 
212
+ new_setting = new_settings.find { |setting|
213
+ setting[:namespace] == namespace && setting[:option_name] == option_name
214
+ }
215
+ if new_setting
216
+ return new_setting
217
+ end
218
+
198
219
  existing_settings = []
199
220
  if environment
200
221
  # Persist changes made directly to the environment from the AWS console UI
@@ -1,3 +1,3 @@
1
1
  module ElasticBeans
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0.alpha1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_beans
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stegman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -250,9 +250,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  requirements:
253
- - - ">="
253
+ - - ">"
254
254
  - !ruby/object:Gem::Version
255
- version: '0'
255
+ version: 1.3.1
256
256
  requirements: []
257
257
  rubyforge_project:
258
258
  rubygems_version: 2.6.11