Class: Central::Cli::Apps::InitCommand

Inherits:
Clamp::Command
  • Object
show all
Includes:
Common, Common
Defined in:
lib/central/cli/apps/init_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#app_json, #create_yml, #current_dir, #extend_env_vars, #extend_options, #extend_secrets, #load_services, #normalize_env_vars, #parse_services, #prefixed_name, #require_config_file, #service_exists?, #token, #valid_addons

Methods included from Services::ServicesHelper

#create_service, #delete_service, #deploy_service, #get_service, #int_to_filesize, #parse_image, #parse_links, #parse_log_opts, #parse_memory, #parse_ports, #parse_relative_time, #parse_secrets, #parse_service_id, #restart_service, #scale_service, #show_service, #start_service, #stop_service, #update_service, #wait_for_deploy_to_finish

Methods included from Common

#access_token=, #add_master, #api_url, #api_url=, #clear_current_stack, #client, #current_master, #current_master=, #current_master_index, #current_stack, #current_stack=, #ensure_custom_ssl_ca, #require_api_url, #require_current_stack, #require_token, #reset_client, #save_settings, #settings, #settings_filename

Instance Attribute Details

#service_prefixObject (readonly)

Returns the value of attribute service_prefix.



17
18
19
# File 'lib/central/cli/apps/init_command.rb', line 17

def service_prefix
  @service_prefix
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/central/cli/apps/init_command.rb', line 19

def execute
  require 'highline/import'

  @service_prefix = project_name || File.basename(Dir.getwd)

  if File.exist?('Dockerfile')
    puts 'Found Dockerfile'
  elsif create_dockerfile?
    puts "Creating #{'Dockerfile'.colorize(:cyan)}"
    DockerfileGenerator.new.generate(base_image)
  end

  procfile = if File.exist?('Procfile')
               YAML.load(File.read('Procfile'))
             else
               {}
  end

  app_env = create_env_file(app_json)
  addons = app_json['addons'] || []

  if File.exist?(docker_compose_file)
    puts "Found #{docker_compose_file}."
  elsif create_docker_compose_yml?
    puts "Creating #{docker_compose_file.colorize(:cyan)}"
    docker_compose_generator = DockerComposeGenerator.new(docker_compose_file)
    docker_compose_generator.generate(procfile, addons, app_env)
  end

  if File.exist?('central.yml')
    puts "Updating #{'central.yml'.colorize(:cyan)}"
  else
    puts "Creating #{'central.yml'.colorize(:cyan)}"
  end

  central_yml_generator = CentralYmlGenerator.new(image_name, service_prefix)
  if File.exist?(docker_compose_file)
    central_yml_generator.generate_from_compose_file(docker_compose_file)
  else
    central_yml_generator.generate(procfile, addons, app_env)
  end

  puts "Your app is ready! Deploy with 'cm app deploy'.".colorize(:green)
end