ufo 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/docs/_docs/conventions.md +4 -0
  4. data/docs/_docs/helpers.md +1 -1
  5. data/docs/_docs/install.md +11 -11
  6. data/docs/_docs/settings.md +64 -23
  7. data/docs/_docs/structure.md +7 -2
  8. data/docs/_docs/tutorial-ufo-init.md +22 -16
  9. data/docs/_docs/tutorial-ufo-ship.md +19 -18
  10. data/docs/_docs/tutorial-ufo-ships.md +5 -5
  11. data/docs/_docs/tutorial-ufo-tasks-build.md +50 -63
  12. data/docs/_docs/ufo-destroy.md +2 -2
  13. data/docs/_docs/ufo-env.md +54 -0
  14. data/docs/_docs/ufo-init.md +7 -3
  15. data/docs/_docs/ufo-scale.md +2 -2
  16. data/docs/_docs/ufo-ship.md +8 -8
  17. data/docs/_docs/ufo-ships.md +4 -4
  18. data/docs/_docs/ufo-tasks-build.md +42 -26
  19. data/docs/_docs/ufo-tasks-register.md +3 -3
  20. data/docs/_docs/variables.md +48 -0
  21. data/docs/_includes/commands.html +1 -0
  22. data/docs/_includes/subnav.html +2 -0
  23. data/docs/bin/web +4 -0
  24. data/docs/img/tutorials/ecs-console-ufo-ship.png +0 -0
  25. data/docs/quick-start.md +22 -4
  26. data/lib/starter_project/bin/deploy +1 -1
  27. data/lib/starter_project/ufo/settings.yml +14 -6
  28. data/lib/starter_project/ufo/task_definitions.rb +13 -24
  29. data/lib/starter_project/ufo/variables/base.rb +6 -0
  30. data/lib/starter_project/ufo/variables/prod.rb +7 -0
  31. data/lib/starter_project/ufo/variables/stag.rb +7 -0
  32. data/lib/ufo.rb +3 -0
  33. data/lib/ufo/default/settings.yml +25 -0
  34. data/lib/ufo/defaults.rb +11 -10
  35. data/lib/ufo/dsl/task_definition.rb +31 -0
  36. data/lib/ufo/env.rb +18 -0
  37. data/lib/ufo/settings.rb +18 -12
  38. data/lib/ufo/version.rb +1 -1
  39. metadata +10 -4
  40. data/docs/img/tutorials/ufo-init.png +0 -0
  41. data/docs/img/tutorials/ufo-tasks-build.png +0 -0
@@ -5,45 +5,34 @@
5
5
  # * helper.full_image_name - Docker image name with the tag when docker image is built by ufo. This is defined in ufo/settings.yml. The helper.full_image_name includes the git sha tongueroo/hi:ufo-[sha].
6
6
  # * helper.dockerfile_port - Expose port in the Dockerfile. Only supports one exposed port, the first one that is encountered.
7
7
  #
8
- # env_vars - is a helper method that generates the proper environment Array of Hashes
9
-
10
- # common variables
11
- common = {
12
- image: helper.full_image_name, # includes the git sha tongueroo/hi:ufo-[sha].
13
- cpu: 128,
14
- memory_reservation: 256,
15
- environment: helper.env_file(".env")
16
- # another example
17
- # environment: helper.env_vars(%Q{
18
- # RAILS_ENV=production
19
- # SECRET_KEY_BASE=secret
20
- # })
21
- }
22
-
23
- task_definition "<%= @app %>-web-<%= @env %>" do
8
+ # helper.env_vars - is a helper method that generates the proper environment Array of Hashes
9
+ #
10
+ # More info: http://ufoships.com/docs/helpers/
11
+ #
12
+ task_definition "<%= @app %>-web" do
24
13
  source "main" # will use ufo/templates/main.json.erb
25
- variables(common.dup.deep_merge(
14
+ variables(
26
15
  family: task_definition_name,
27
16
  name: "web",
28
17
  container_port: helper.dockerfile_port,
29
18
  command: ["bin/web"]
30
- ))
19
+ )
31
20
  end
32
21
 
33
- task_definition "<%= @app %>-worker-<%= @env %>" do
22
+ task_definition "<%= @app %>-worker" do
34
23
  source "main" # will use ufo/templates/main.json.erb
35
- variables(common.dup.deep_merge(
24
+ variables(
36
25
  family: task_definition_name,
37
26
  name: "worker",
38
27
  command: ["bin/worker"]
39
- ))
28
+ )
40
29
  end
41
30
 
42
- task_definition "<%= @app %>-clock-<%= @env %>" do
31
+ task_definition "<%= @app %>-clock" do
43
32
  source "main" # will use ufo/templates/main.json.erb
44
- variables(common.dup.deep_merge(
33
+ variables(
45
34
  family: task_definition_name,
46
35
  name: "clock",
47
36
  command: ["bin/clock"]
48
- ))
37
+ )
49
38
  end
@@ -0,0 +1,6 @@
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")
@@ -0,0 +1,7 @@
1
+ # Example ufo/variables/prod.rb
2
+ # More info on how variables work: http://ufoships.com/docs/variables/
3
+ @cpu = 256
4
+ @environment = helper.env_vars(%Q{
5
+ RAILS_ENV=production
6
+ SECRET_KEY_BASE=secret
7
+ })
@@ -0,0 +1,7 @@
1
+ # Example ufo/variables/prod.rb
2
+ # More info on how variables work: http://ufoships.com/docs/variables/
3
+ @cpu = 192
4
+ @environment = helper.env_vars(%Q{
5
+ RAILS_ENV=staging
6
+ SECRET_KEY_BASE=secret
7
+ })
data/lib/ufo.rb CHANGED
@@ -5,6 +5,7 @@ require 'colorize'
5
5
  require 'fileutils'
6
6
 
7
7
  module Ufo
8
+ autoload :Env, 'ufo/env'
8
9
  autoload :Defaults, 'ufo/defaults'
9
10
  autoload :AwsServices, 'ufo/aws_services'
10
11
  autoload :Command, 'ufo/command'
@@ -23,3 +24,5 @@ module Ufo
23
24
  autoload :Ecr, 'ufo/ecr'
24
25
  autoload :Tasks, 'ufo/tasks'
25
26
  end
27
+
28
+ Ufo::Env.setup!
@@ -0,0 +1,25 @@
1
+ # More info: http://ufoships.com/docs/ufo-settings/
2
+ #
3
+ # image:
4
+ # clean_keep: 30
5
+ # ecr_keep: 30
6
+
7
+ # aws_profile_ufo_env_map:
8
+ # default: prod
9
+ # # More examples:
10
+ # aws_profile1: prod
11
+ # aws_profile2: stag
12
+ # aws_profile3: dev
13
+
14
+ # ufo_env_cluster_map:
15
+ # default: prod
16
+ # # More examples:
17
+ # aws_profile1: prod
18
+ # aws_profile2: stag
19
+ # aws_profile3: dev
20
+
21
+ # defaults when an new ECS service is created by ufo ship
22
+ new_service:
23
+ maximum_percent: 200
24
+ minimum_healthy_percent: 100
25
+ desired_count: 1
@@ -8,18 +8,19 @@ module Ufo
8
8
  #
9
9
  # So @options must be set
10
10
  module Defaults
11
- # image: 123456789.dkr.ecr.us-east-1.amazonaws.com/sinatra
12
- # # service to cluster mapping, overrides default cluster cli overrides this
13
- # service_cluster:
14
- # default: prod-lo
15
- # hi-web-prod: prod-hi
16
- # hi-clock-prod: prod-lo
17
- # hi-worker-prod: prod-lo
11
+ # The default cluster normally defaults to the UFO_ENV value.
12
+ # But it can be overriden by ufo/settings.yml ufo_env_cluster_map
18
13
  #
19
- # Assumes that @service is set in the class that the Defaults module is included in.
14
+ # Covered: http://localhost:4000/docs/settings/
20
15
  def default_cluster
21
- service_cluster = settings.data["service_cluster"]
22
- service_cluster[@service] || service_cluster["default"]
16
+ #
17
+
18
+ map = settings.data["ufo_env_cluster_map"]
19
+ if map
20
+ ecs_cluster = map[UFO_ENV] || map["default"]
21
+ end
22
+
23
+ ecs_cluster || UFO_ENV
23
24
  end
24
25
 
25
26
  # These default service values only are used when a service is created by `ufo`
@@ -19,10 +19,41 @@ module Ufo
19
19
  end
20
20
 
21
21
  def build
22
+ load_variables
22
23
  instance_eval(&@block)
23
24
  erb_result(source_path)
24
25
  end
25
26
 
27
+ def load_variables
28
+ load_variables_file("base")
29
+ load_variables_file(UFO_ENV)
30
+ end
31
+
32
+ # Load the variables defined in ufo/variables/* to make available in the
33
+ # template blocks in ufo/templates/*.
34
+ #
35
+ # Example:
36
+ #
37
+ # `ufo/variables/base.rb`:
38
+ # @name = "docker-process-name"
39
+ # @image = "docker-image-name"
40
+ #
41
+ # `ufo/templates/main.json.erb`:
42
+ # {
43
+ # "containerDefinitions": [
44
+ # {
45
+ # "name": "<%= @name %>",
46
+ # "image": "<%= @image %>",
47
+ # ....
48
+ # }
49
+ #
50
+ # NOTE: Only able to make instance variables avaialble with instance_eval
51
+ # Wasnt able to make local variables available.
52
+ def load_variables_file(filename)
53
+ path = "#{@project_root}/ufo/variables/#{filename}.rb"
54
+ instance_eval(IO.read(path)) if File.exist?(path)
55
+ end
56
+
26
57
  def erb_result(path)
27
58
  template = IO.read(path)
28
59
  begin
@@ -0,0 +1,18 @@
1
+ class Ufo::Env
2
+ def self.setup!(project_root='.')
3
+ # Ensures that UFO_ENV is always set to a default value.
4
+ # For Ufo::Env.setup! we do not need to check if we're in a ufo project
5
+ # Because we could not be at first. For example when: ufo init is first called.
6
+ # Other uses of Ufo::Settings assumes that we should be in a ufo project.
7
+ settings = Ufo::Settings.new(project_root, false).data
8
+ map = settings['aws_profile_ufo_env_map']
9
+
10
+ if map
11
+ ufo_env = map[ENV['AWS_PROFILE']] || map['default']
12
+ end
13
+ ufo_env ||= 'prod' # defaults to prod
14
+ ufo_env = ENV['UFO_ENV'] if ENV['UFO_ENV'] # highest precedence
15
+
16
+ Kernel.const_set(:UFO_ENV, ufo_env)
17
+ end
18
+ end
@@ -2,31 +2,37 @@ require 'yaml'
2
2
 
3
3
  module Ufo
4
4
  class Settings
5
- def initialize(project_root='.')
5
+ def initialize(project_root='.', check_ufo_project=true)
6
6
  @project_root = project_root
7
+ @check_ufo_project = check_ufo_project
7
8
  end
8
9
 
9
10
  # data contains the settings.yml config. The order or precedence for settings
10
11
  # is the project ufo/settings.yml and then the ~/.ufo/settings.yml.
11
12
  def data
12
- return @data if @data
13
+ return @settings_yaml if @settings_yaml
13
14
 
14
- if File.exist?(settings_path)
15
- @data = YAML.load_file(settings_path)
16
- @data = user_settings.merge(@data)
17
- else
18
- puts "ERROR: No settings file at #{settings_path}. Are you sure you are in a project with ufo setup?"
15
+ if @check_ufo_project && !File.exist?(project_settings_path)
16
+ puts "ERROR: No settings file at #{project_settings_path}. Are you sure you are in a project with ufo setup?"
19
17
  puts "Please create a settings file via: ufo init"
20
18
  exit 1
21
19
  end
22
- end
23
20
 
24
- def user_settings
25
- path = "#{ENV['HOME']}/.ufo/settings.yml"
26
- File.exist?(path) ? YAML.load_file(path) : {}
21
+ project = File.exist?(project_settings_path) ?
22
+ YAML.load_file(project_settings_path) :
23
+ {}
24
+
25
+ user_file = "#{ENV['HOME']}/.ufo/settings.yml"
26
+ user = File.exist?(user_file) ? YAML.load_file(user_file) : {}
27
+
28
+ default_file = File.expand_path("../default/settings.yml", __FILE__)
29
+ default = YAML.load_file(default_file)
30
+
31
+ @settings_yaml = default.merge(user.merge(project))
27
32
  end
28
33
 
29
- def settings_path
34
+ private
35
+ def project_settings_path
30
36
  "#{@project_root}/ufo/settings.yml"
31
37
  end
32
38
  end
@@ -1,3 +1,3 @@
1
1
  module Ufo
2
- VERSION = "1.7.1"
2
+ VERSION = "2.0.0"
3
3
  end
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: 1.7.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -197,6 +197,7 @@ files:
197
197
  - docs/_docs/ufo-docker-build.md
198
198
  - docs/_docs/ufo-docker-clean.md
199
199
  - docs/_docs/ufo-docker-name.md
200
+ - docs/_docs/ufo-env.md
200
201
  - docs/_docs/ufo-help.md
201
202
  - docs/_docs/ufo-init.md
202
203
  - docs/_docs/ufo-scale.md
@@ -204,6 +205,7 @@ files:
204
205
  - docs/_docs/ufo-ships.md
205
206
  - docs/_docs/ufo-tasks-build.md
206
207
  - docs/_docs/ufo-tasks-register.md
208
+ - docs/_docs/variables.md
207
209
  - docs/_includes/about.html
208
210
  - docs/_includes/commands.html
209
211
  - docs/_includes/contact.html
@@ -234,6 +236,7 @@ files:
234
236
  - docs/_layouts/default.html
235
237
  - docs/_layouts/style.css
236
238
  - docs/articles.md
239
+ - docs/bin/web
237
240
  - docs/css/font-awesome/css/font-awesome.css
238
241
  - docs/css/font-awesome/css/font-awesome.min.css
239
242
  - docs/css/font-awesome/fonts/FontAwesome.otf
@@ -250,8 +253,6 @@ files:
250
253
  - docs/img/tutorials/ecs-console-task-definitions.png
251
254
  - docs/img/tutorials/ecs-console-ufo-ship.png
252
255
  - docs/img/tutorials/ecs-console-ufo-ships.png
253
- - docs/img/tutorials/ufo-init.png
254
- - docs/img/tutorials/ufo-tasks-build.png
255
256
  - docs/index.html
256
257
  - docs/js/bootstrap.js
257
258
  - docs/js/bootstrap.min.js
@@ -273,11 +274,15 @@ files:
273
274
  - lib/starter_project/ufo/settings.yml
274
275
  - lib/starter_project/ufo/task_definitions.rb
275
276
  - lib/starter_project/ufo/templates/main.json.erb
277
+ - lib/starter_project/ufo/variables/base.rb
278
+ - lib/starter_project/ufo/variables/prod.rb
279
+ - lib/starter_project/ufo/variables/stag.rb
276
280
  - lib/ufo.rb
277
281
  - lib/ufo/aws_services.rb
278
282
  - lib/ufo/cli.rb
279
283
  - lib/ufo/cli/help.rb
280
284
  - lib/ufo/command.rb
285
+ - lib/ufo/default/settings.yml
281
286
  - lib/ufo/defaults.rb
282
287
  - lib/ufo/destroy.rb
283
288
  - lib/ufo/docker.rb
@@ -292,6 +297,7 @@ files:
292
297
  - lib/ufo/ecr.rb
293
298
  - lib/ufo/ecr/auth.rb
294
299
  - lib/ufo/ecr/cleaner.rb
300
+ - lib/ufo/env.rb
295
301
  - lib/ufo/init.rb
296
302
  - lib/ufo/log_group.rb
297
303
  - lib/ufo/scale.rb