ufo 3.3.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/Gemfile.lock +9 -7
  4. data/docs/README.md +1 -2
  5. data/docs/_docs/params.md +72 -0
  6. data/docs/_docs/settings.md +1 -6
  7. data/docs/_docs/tutorial-ufo-init.md +0 -5
  8. data/docs/_docs/ufo-env.md +1 -1
  9. data/docs/_includes/subnav.html +1 -0
  10. data/docs/_reference/ufo-deploy.md +9 -1
  11. data/docs/_reference/ufo-init.md +30 -9
  12. data/docs/_reference/ufo-task.md +11 -12
  13. data/docs/_reference/ufo-upgrade3_3_to_3_4.md +23 -0
  14. data/docs/reference.md +1 -0
  15. data/lib/template/.ufo/params.yml.tt +65 -0
  16. data/lib/template/.ufo/settings.yml.tt +0 -4
  17. data/lib/template/.ufo/templates/fargate.json.erb +37 -0
  18. data/lib/template/.ufo/variables/base.rb.tt +15 -0
  19. data/lib/template/.ufo/variables/development.rb +1 -1
  20. data/lib/ufo.rb +3 -1
  21. data/lib/ufo/cli.rb +7 -3
  22. data/lib/ufo/default/settings.yml +0 -4
  23. data/lib/ufo/destroy.rb +1 -1
  24. data/lib/ufo/docker/builder.rb +1 -5
  25. data/lib/ufo/docker/cleaner.rb +1 -2
  26. data/lib/ufo/docker/pusher.rb +1 -5
  27. data/lib/ufo/dsl.rb +1 -1
  28. data/lib/ufo/dsl/helper.rb +3 -8
  29. data/lib/ufo/dsl/task_definition.rb +7 -45
  30. data/lib/ufo/ecr/cleaner.rb +2 -2
  31. data/lib/ufo/help/deploy.md +9 -1
  32. data/lib/ufo/help/init.md +18 -0
  33. data/lib/ufo/help/task.md +6 -6
  34. data/lib/ufo/init.rb +9 -2
  35. data/lib/ufo/param.rb +24 -0
  36. data/lib/ufo/scale.rb +1 -1
  37. data/lib/ufo/sequence.rb +14 -0
  38. data/lib/ufo/ship.rb +6 -6
  39. data/lib/ufo/task.rb +9 -1
  40. data/lib/ufo/tasks/register.rb +21 -1
  41. data/lib/ufo/template_scope.rb +45 -0
  42. data/lib/ufo/upgrade/params.yml +47 -0
  43. data/lib/ufo/upgrade33_to_34.rb +32 -0
  44. data/lib/ufo/util.rb +25 -0
  45. data/lib/ufo/version.rb +1 -1
  46. data/spec/fixtures/settings.yml +0 -4
  47. data/spec/lib/setting_spec.rb +3 -3
  48. data/spec/spec_helper.rb +1 -1
  49. data/ufo.gemspec +1 -0
  50. metadata +25 -4
  51. data/lib/template/.ufo/variables/base.rb +0 -6
  52. data/lib/ufo/default.rb +0 -40
@@ -1,6 +1,6 @@
1
1
  module Ufo
2
2
  class Task
3
- include Default
3
+ include Util
4
4
  include AwsService
5
5
 
6
6
  def initialize(task_definition, options)
@@ -12,15 +12,23 @@ module Ufo
12
12
  def run
13
13
  puts "Running task_definition: #{@task_definition}".colorize(:green) unless @options[:mute]
14
14
  return if @options[:noop]
15
+
15
16
  task_options = {
16
17
  cluster: @cluster,
17
18
  task_definition: @task_definition
18
19
  }
20
+ task_options = task_options.merge(default_params[:run_task] || {})
21
+
19
22
  if @options[:command]
20
23
  task_options.merge!(overrides: overrides)
21
24
  puts "Running task with container overrides."
22
25
  puts "Command: #{@options[:command].join(' ')}"
23
26
  end
27
+
28
+ unless @options[:mute]
29
+ puts "Running task with params:"
30
+ display_params(task_options)
31
+ end
24
32
  resp = ecs.run_task(task_options)
25
33
  puts "Task ARN: #{resp.tasks[0].task_arn}" unless @options[:mute]
26
34
  end
@@ -3,6 +3,7 @@ require 'json'
3
3
 
4
4
  module Ufo
5
5
  class Tasks::Register
6
+ include Util
6
7
  include AwsService
7
8
 
8
9
  def self.register(task_name, options={})
@@ -28,11 +29,30 @@ module Ufo
28
29
  if @options[:noop]
29
30
  message = "NOOP: #{message}"
30
31
  else
31
- ecs.register_task_definition(data)
32
+ register_task_definition(data)
32
33
  end
33
34
  puts message unless @options[:mute]
34
35
  end
35
36
 
37
+ def register_task_definition(data)
38
+ if ENV["UFO_SHOW_REGISTER_TASK_DEFINITION"]
39
+ puts "Registering task definition with:"
40
+ display_params(data)
41
+ end
42
+
43
+ ecs.register_task_definition(data)
44
+ rescue Aws::ECS::Errors::ClientException => e
45
+ if e.message =~ /No Fargate configuration exists for given values/
46
+ puts "ERROR: #{e.message}".colorize(:red)
47
+ puts "Configured values are: cpu #{data[:cpu]} memory #{data[:memory]}"
48
+ puts "Check that the cpu and memory values are a supported combination by Fargate."
49
+ puts "More info: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html"
50
+ exit 1
51
+ else
52
+ raise
53
+ end
54
+ end
55
+
36
56
  # LogConfiguration requires a string with dashes as the keys
37
57
  # https://docs.aws.amazon.com/sdkforruby/api/Aws/ECS/Client.html
38
58
  def fix_log_configuation_option(data)
@@ -0,0 +1,45 @@
1
+ module Ufo
2
+ class TemplateScope
3
+ attr_reader :helper
4
+ def initialize(helper=nil)
5
+ @helper = helper
6
+ load_variables_file("base")
7
+ load_variables_file(Ufo.env)
8
+ end
9
+
10
+ # Load the variables defined in ufo/variables/* to make available in the
11
+ # template blocks in ufo/templates/*.
12
+ #
13
+ # Example:
14
+ #
15
+ # `ufo/variables/base.rb`:
16
+ # @name = "docker-process-name"
17
+ # @image = "docker-image-name"
18
+ #
19
+ # `ufo/templates/main.json.erb`:
20
+ # {
21
+ # "containerDefinitions": [
22
+ # {
23
+ # "name": "<%= @name %>",
24
+ # "image": "<%= @image %>",
25
+ # ....
26
+ # }
27
+ #
28
+ # NOTE: Only able to make instance variables avaialble with instance_eval
29
+ # Wasnt able to make local variables available.
30
+ def load_variables_file(filename)
31
+ path = "#{Ufo.root}/.ufo/variables/#{filename}.rb"
32
+ instance_eval(IO.read(path)) if File.exist?(path)
33
+ end
34
+
35
+ def assign_instance_variables
36
+ # copy over the instance variables to make available in RenderMePretty's scope
37
+ hash = {}
38
+ instance_variables.each do |var|
39
+ key = var.to_s.sub('@','') # rid of the leading @
40
+ hash[key.to_sym] = instance_variable_get(var)
41
+ end
42
+ hash
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,47 @@
1
+ <%%
2
+ # replace with actual values:
3
+ @subnets = ["subnet-111","subnet-222"]
4
+ @security_groups = ["sg-111"]
5
+ %>
6
+ # These params are passsed to the corresponding aws-sdk ecs client methods.
7
+ # AWS Docs example: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/ECS/Client.html#run_task-instance_method
8
+ #
9
+ # Comments left in as examples.
10
+ # Uncomment launch_type and network_configuration sections to enable fargate.
11
+ #
12
+
13
+ create_service:
14
+ deployment_configuration:
15
+ maximum_percent: 200
16
+ minimum_healthy_percent: 100
17
+ desired_count: 1
18
+ # launch_type: "FARGATE"
19
+ # network_configuration:
20
+ # awsvpc_configuration:
21
+ # subnets: <%%= @subnets.inspect %> # required
22
+ # security_groups: <%%= @security_groups.inspect %>
23
+ # assign_public_ip: "ENABLED" # accepts ENABLED, DISABLED
24
+
25
+ # update service is provide as an example below. Though it is probably better
26
+ # to not add any options to update_service if you are using the ECS console
27
+ # to update these settings often.
28
+ update_service:
29
+ # force_new_deployment: true
30
+ # deployment_configuration:
31
+ # maximum_percent: 200
32
+ # minimum_healthy_percent: 100
33
+ # desired_count: 1
34
+ # launch_type: "FARGATE"
35
+ # network_configuration:
36
+ # awsvpc_configuration:
37
+ # subnets: <%%= @subnets.inspect %> # required
38
+ # security_groups: <%%= @security_groups.inspect %>
39
+ # assign_public_ip: "ENABLED" # accepts ENABLED, DISABLED
40
+
41
+ run_task:
42
+ # launch_type: "FARGATE"
43
+ # network_configuration:
44
+ # awsvpc_configuration:
45
+ # subnets: <%%= @subnets.inspect %> # required
46
+ # security_groups: <%%= @security_groups.inspect %>
47
+ # assign_public_ip: "ENABLED" # accepts ENABLED, DISABLED
@@ -0,0 +1,32 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module Ufo
5
+ class Upgrade33_to_34
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def run
11
+ if File.exist?("#{Ufo.root}/.ufo/params.yml")
12
+ puts "It looks like you already have a .ufo/params.yml project. This is the new project structure so exiting without updating anything."
13
+ return
14
+ end
15
+
16
+ create_params_yaml
17
+ warn_about_removing_new_service_from_settings
18
+ end
19
+
20
+ def create_params_yaml
21
+ src = File.expand_path("./upgrade/params.yml", File.dirname(__FILE__))
22
+ dest = "#{Ufo.root}/.ufo/params.yml"
23
+ FileUtils.cp(src, dest)
24
+ puts "File .ufo/params.yml created.".colorize(:green)
25
+ puts "Please check it out and adjust it to your needs."
26
+ end
27
+
28
+ def warn_about_removing_new_service_from_settings
29
+ puts "WARN: The new_service option is not longer a part of the .ufo/settings.yml. Please remove it. It is now a part of the .ufo/params.yml file."
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,26 @@
1
+ require 'active_support/core_ext/hash'
2
+
1
3
  module Ufo
2
4
  module Util
5
+ # The default cluster normally defaults to the Ufo.env value.
6
+ # But it can be overriden by ufo/settings.yml cluster
7
+ #
8
+ # More info: http://ufoships.com/docs/settings/
9
+ def default_cluster
10
+ settings["cluster"] || Ufo.env
11
+ end
12
+
13
+ # Keys are strings for simplicity.
14
+ def settings
15
+ @settings ||= Setting.new.data
16
+ end
17
+
18
+ # Naming it default_params because params is too commonly used in ufo.
19
+ # Param keys must be symbols for the aws-sdk calls.
20
+ def default_params
21
+ @default_params ||= Param.new.data.deep_symbolize_keys
22
+ end
23
+
3
24
  def execute(command, local_options={})
4
25
  if @options[:noop] && !local_options[:live]
5
26
  say "NOOP: #{command}"
@@ -24,5 +45,9 @@ module Ufo
24
45
  "#{minutes.to_i}m #{seconds.to_i}s"
25
46
  end
26
47
  end
48
+
49
+ def display_params(options)
50
+ puts YAML.dump(options.deep_stringify_keys)
51
+ end
27
52
  end
28
53
  end
@@ -1,3 +1,3 @@
1
1
  module Ufo
2
- VERSION = "3.3.2"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -4,10 +4,6 @@ base:
4
4
  # clean_keep: 30 # cleans up docker images on your docker server.
5
5
  # ecr_keep: 30 # cleans up images on ECR and keeps this remaining amount. Defaults to keep all.
6
6
  # defaults when an new ECS service is created by ufo ship
7
- new_service:
8
- maximum_percent: 200
9
- minimum_healthy_percent: 100
10
- desired_count: 1
11
7
 
12
8
  development:
13
9
  cluster: dev
@@ -5,8 +5,8 @@ describe Ufo::Setting do
5
5
 
6
6
  let(:setting) { Ufo::Setting.new }
7
7
 
8
- it "includes base into other environments automatically" do
9
- count = setting.data["new_service"]["desired_count"]
10
- expect(count).to eq 1
8
+ it "includes the cluster setting" do
9
+ cluster = setting.data["cluster"]
10
+ expect(cluster).to eq "dev"
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  ENV["TEST"] = "1"
2
- # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
2
+ # Ensures aws api never called. Fixture home does not contain ~/.aws/credentials
3
3
  ENV['HOME'] = "spec/fixtures/home"
4
4
 
5
5
  # CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "aws-sdk-elasticloadbalancingv2"
26
26
  spec.add_dependency "colorize"
27
27
  spec.add_dependency "deep_merge"
28
+ spec.add_dependency "memoist"
28
29
  spec.add_dependency "plissken"
29
30
  spec.add_dependency "render_me_pretty"
30
31
  spec.add_dependency "thor"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.4.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: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudwatchlogs
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: memoist
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: plissken
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -254,6 +268,7 @@ files:
254
268
  - docs/_docs/install.md
255
269
  - docs/_docs/migrations.md
256
270
  - docs/_docs/next-steps.md
271
+ - docs/_docs/params.md
257
272
  - docs/_docs/run-in-pieces.md
258
273
  - docs/_docs/settings.md
259
274
  - docs/_docs/single-task.md
@@ -319,6 +334,7 @@ files:
319
334
  - docs/_reference/ufo-tasks-register.md
320
335
  - docs/_reference/ufo-tasks.md
321
336
  - docs/_reference/ufo-upgrade3.md
337
+ - docs/_reference/ufo-upgrade3_3_to_3_4.md
322
338
  - docs/_reference/ufo-version.md
323
339
  - docs/articles.md
324
340
  - docs/bin/web
@@ -356,10 +372,12 @@ files:
356
372
  - docs/style.css
357
373
  - exe/ufo
358
374
  - lib/template/.env
375
+ - lib/template/.ufo/params.yml.tt
359
376
  - lib/template/.ufo/settings.yml.tt
360
377
  - lib/template/.ufo/task_definitions.rb.tt
378
+ - lib/template/.ufo/templates/fargate.json.erb
361
379
  - lib/template/.ufo/templates/main.json.erb
362
- - lib/template/.ufo/variables/base.rb
380
+ - lib/template/.ufo/variables/base.rb.tt
363
381
  - lib/template/.ufo/variables/development.rb
364
382
  - lib/template/.ufo/variables/production.rb
365
383
  - lib/template/Dockerfile
@@ -372,7 +390,6 @@ files:
372
390
  - lib/ufo/completer/script.rb
373
391
  - lib/ufo/completer/script.sh
374
392
  - lib/ufo/core.rb
375
- - lib/ufo/default.rb
376
393
  - lib/ufo/default/settings.yml
377
394
  - lib/ufo/default/templates/main.json.erb
378
395
  - lib/ufo/deploy.rb
@@ -415,6 +432,7 @@ files:
415
432
  - lib/ufo/help/tasks/register.md
416
433
  - lib/ufo/init.rb
417
434
  - lib/ufo/log_group.rb
435
+ - lib/ufo/param.rb
418
436
  - lib/ufo/scale.rb
419
437
  - lib/ufo/sequence.rb
420
438
  - lib/ufo/setting.rb
@@ -423,7 +441,10 @@ files:
423
441
  - lib/ufo/tasks.rb
424
442
  - lib/ufo/tasks/builder.rb
425
443
  - lib/ufo/tasks/register.rb
444
+ - lib/ufo/template_scope.rb
445
+ - lib/ufo/upgrade/params.yml
426
446
  - lib/ufo/upgrade3.rb
447
+ - lib/ufo/upgrade33_to_34.rb
427
448
  - lib/ufo/util.rb
428
449
  - lib/ufo/version.rb
429
450
  - spec/fixtures/home_existing/.aws/config
@@ -1,6 +0,0 @@
1
- # Example ufo/variables/base.rb
2
- # More info on how variables work: http://ufoships.com/docs/variables/
3
- @image = helper.full_image_name # includes the git sha tongueroo/hi:ufo-[sha].
4
- @cpu = 128
5
- @memory_reservation = 256
6
- @environment = helper.env_file(".env")
@@ -1,40 +0,0 @@
1
- module Ufo
2
- # To include this module must have this in initialize:
3
- #
4
- # def initialize(optiions, ...)
5
- # @options = options
6
- # ...
7
- # end
8
- #
9
- # So @options must be set
10
- module Default
11
- # The default cluster normally defaults to the Ufo.env value.
12
- # But it can be overriden by ufo/settings.yml cluster
13
- #
14
- # More info: http://ufoships.com/docs/settings/
15
- def default_cluster
16
- setting.data["cluster"] || Ufo.env
17
- end
18
-
19
- # These default service values only are used when a service is created by `ufo`
20
- def default_maximum_percent
21
- Integer(new_service_setting["maximum_percent"] || 200)
22
- end
23
-
24
- def default_minimum_healthy_percent
25
- Integer(new_service_setting["minimum_healthy_percent"] || 100)
26
- end
27
-
28
- def default_desired_count
29
- Integer(new_service_setting["desired_count"] || 1)
30
- end
31
-
32
- def new_service_setting
33
- setting.data["new_service"] || {}
34
- end
35
-
36
- def setting
37
- @setting ||= Setting.new
38
- end
39
- end
40
- end