Class: Ufo::DSL::Helper

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Util
Defined in:
lib/ufo/dsl/helper.rb,
lib/ufo/dsl/helper/vars.rb

Defined Under Namespace

Classes: Vars

Instance Method Summary collapse

Methods included from Util

#default_cluster, #display_params, #execute, #pretty_time, #settings, #task_definition_arns, #user_params

Instance Method Details

#add_project_helpersObject

Add helpers from .ufo/helpers folder



14
15
16
17
18
19
20
21
# File 'lib/ufo/dsl/helper.rb', line 14

def add_project_helpers
  helpers_dir = "#{Ufo.root}/.ufo/helpers"
  Dir.glob("#{helpers_dir}/**/*").each do |path|
    next unless File.file?(path)
    klass = path.gsub(%r{.*\.ufo/helpers/},'').sub(".rb",'').camelize
    self.class.send(:include, klass.constantize)
  end
end

#current_regionObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/ufo/dsl/helper.rb', line 56

def current_region
  default_region = 'us-east-1'
  return default_region if ENV['TEST']

  return ENV['UFO_AWS_REGION'] if ENV['UFO_AWS_REGION'] # highest precedence
  return ENV['AWS_REGION'] if ENV['AWS_REGION']

  region = `aws configure get region`.strip rescue default_region
  region.blank? ? default_region : region
end

#dockerfile_portObject

helper variables



25
26
27
28
29
30
# File 'lib/ufo/dsl/helper.rb', line 25

def dockerfile_port
  dockerfile_path = "#{Ufo.root}/Dockerfile"
  if File.exist?(dockerfile_path)
    parse_for_dockerfile_port(dockerfile_path)
  end
end

#env(text) ⇒ Object Also known as: env_vars

helper methods



39
40
41
# File 'lib/ufo/dsl/helper.rb', line 39

def env(text)
  Vars.new(text: text).env
end

#env_file(path) ⇒ Object



44
45
46
# File 'lib/ufo/dsl/helper.rb', line 44

def env_file(path)
  Vars.new(file: path).env
end

#full_image_nameObject



32
33
34
35
# File 'lib/ufo/dsl/helper.rb', line 32

def full_image_name
  # Dont need to use @options here. Helps simplify the Helper initialization.
  Docker::Builder.new({}).full_image_name
end

#parse_for_dockerfile_port(dockerfile_path) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/ufo/dsl/helper.rb', line 67

def parse_for_dockerfile_port(dockerfile_path)
  lines = IO.read(dockerfile_path).split("\n")
  expose_line = lines.find { |l| l =~ /^EXPOSE / }
  if expose_line
    md = expose_line.match(/EXPOSE (\d+)/)
    port = md[1] if md
  end
  port.to_i if port
end

#secrets(text) ⇒ Object



48
49
50
# File 'lib/ufo/dsl/helper.rb', line 48

def secrets(text)
  Vars.new(text: text).secrets
end

#secrets_file(path) ⇒ Object



52
53
54
# File 'lib/ufo/dsl/helper.rb', line 52

def secrets_file(path)
  Vars.new(file: path).secrets
end