Class: Ufo::Init

Inherits:
Sequence show all
Includes:
Network::Helper
Defined in:
lib/ufo/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

source_paths

Class Method Details

.cli_optionsObject

Ugly, this is how I can get the options from to match with this Thor::Group



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ufo/init.rb', line 6

def self.cli_options
  [
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:image, required: true, desc: "Docker image name without the tag. Example: tongueroo/demo-ufo. Configures ufo/settings.yml"],
    [:app, desc: "App name. Preferably one word. Used in the generated ufo/task_definitions.rb.  If not specified then the app name is inferred as the folder name."],
    [:launch_type, default: "ec2", desc: "ec2 or fargate."],
    [:execution_role_arn, desc: "execution role arn used by tasks, required for fargate."],
    [:template, desc: "Custom template to use."],
    [:template_mode, desc: "Template mode: replace or additive."],
    [:vpc_id, desc: "Vpc id. For settings/network/default.yml."],
    [:ecs_subnets, type: :array, desc: "Subnets for ECS tasks, defaults to --elb-subnets set to. For settings/network/default.yml"],
    [:elb_subnets, type: :array, desc: "Subnets for ELB. For settings/network/default.yml"],
  ]
end

Instance Method Details

#init_filesObject



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

def init_files
  # map variables
  @app = options[:app] || inferred_app
  @image = options[:image]
  @execution_role_arn_input = get_execution_role_arn_input
  # copy the files
  puts "Setting up ufo project..."
  exclude_pattern = File.exist?("#{Ufo.root}/Dockerfile") ?
                      /(\.git|Dockerfile)/ :
                      /(\.git)/
  directory ".", exclude_pattern: exclude_pattern
end

#set_destination_rootObject

for specs



42
43
44
45
46
47
48
49
# File 'lib/ufo/init.rb', line 42

def set_destination_root
  return unless ENV['UFO_ROOT']

  dest = ENV['UFO_ROOT']
  FileUtils.rm_rf(dest) && FileUtils.mkdir_p(dest)
  self.destination_root = dest
  FileUtils.cd(dest)
end

#set_network_optionsObject



51
52
53
# File 'lib/ufo/init.rb', line 51

def set_network_options
  configure_network_settings
end

#set_source_pathObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ufo/init.rb', line 28

def set_source_path
  return unless @options[:template]

  custom_template = "#{ENV['HOME']}/.ufo/templates/#{@options[:template]}"

  if @options[:template_mode] == "replace" # replace the template entirely
    override_source_paths(custom_template)
  else # additive: modify on top of default template
    default_template = File.expand_path("../../template", __FILE__)
    override_source_paths([custom_template, default_template])
  end
end

#setup_template_repoObject



22
23
24
25
26
# File 'lib/ufo/init.rb', line 22

def setup_template_repo
  return unless @options[:template]&.include?('/')

  sync_template_repo
end

#upsert_dockerignoreObject



82
83
84
85
86
87
88
89
# File 'lib/ufo/init.rb', line 82

def upsert_dockerignore
  text = ".ufo\n"
  if File.exist?(".dockerignore")
    append_to_file ".dockerignore", text
  else
    create_file ".dockerignore", text
  end
end

#upsert_gitignoreObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ufo/init.rb', line 68

def upsert_gitignore
  text =<<-EOL
.ufo/current
.ufo/data
.ufo/log
.ufo/output
EOL
  if File.exist?(".gitignore")
    append_to_file ".gitignore", text
  else
    create_file ".gitignore", text
  end
end

#user_messageObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ufo/init.rb', line 91

def user_message
  puts "Starter ufo files created."
  puts <<-EOL
Congrats 🎉 You have successfully set up ufo for your project.
#{"="*64}

## Task Definition Customizations

If you need to customize the ECS task definition to configure things like memory and cpu allocation. You can do this by adjusting the files the .ufo/variables folder. These variables get applied to the .ufo/templates/main.json.erb task definition json that is passed to the ECS register task definition api.

Some additional starter example roles for your apps were set up in in .ufo/task_definitions.rb.  Be sure to check it out and adjust it for your needs.

## Settings files

Additionally, ufo generated starter settings files that allow you to customize more settings.

* .ufo/settings.yml: general settings.
* .ufo/settings/cfn/default.yml: properties of CloudFormation resources that ufo creates.
* .ufo/settings/network/default.yml: network settings.

More more info refer to: http://ufoships.com/docs/settings/

To deploy to ECS:

  ufo current --service #{@app}-web
  ufo ship

EOL
end