Class: Dockerun::Command::RunNewContainer

Inherits:
Object
  • Object
show all
Includes:
Dockerun::CliHelper::CliPrompt, Dockerun::CommandHelper::DockerContainerHelper, DockerCommandFactoryHelper, TR::CondUtils, TTY::Option
Defined in:
lib/dockerun/command/run_new_container.rb

Instance Method Summary collapse

Methods included from Dockerun::CliHelper::CliPrompt

#cli

Methods included from DockerCommandFactoryHelper

#dcFact

Methods included from Dockerun::CommandHelper::DockerContainerHelper

#run_docker_container

Instance Method Details

#runObject



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dockerun/command/run_new_container.rb', line 28

def run

  if params[:help]
    print help
    exit(0)

  else

    config = ::Dockerun::Config.from_storage

    imageName = nil
    if is_empty?(config.image_names)
      STDERR.puts "Image name not availab eyet"
      exit(1)
    elsif config.image_names == 1
      imageName = config.image_names.first
    else
      imageName = cli.select("Please select the new container shall be based on which image : ") do |m|
        config.image_names.each do |n|
          m.choice n,n
        end
      end
    end

    contName = run_docker_container(imageName, nil) do |ops, *args|
      case ops
      when :new_container_name
        cli.ask("Please provide a new container name : ", required: true)
      when :container_name_exist
        cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
      when :volume_mapping_required?
        cli.yes?("Is there any volume mapping required? ")
      when :source_prompt
        cli.ask("Directory to share with docker : ", required: true)
      when :destination_prompt
        src = args.first
        srcDir = File.basename(src)
        cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
     when :add_mount_to_container
        config.add_mount_to_container(imageName, *args)
      when :add_more_volume_mapping?
        cli.yes?("Add more volume mapping?")
      end
   end

    #contName = nil
    #loop do
    #  contName = cli.ask("Please provide a new container name : ", required: true)
    #  res = dcFact.find_from_all_container(contName).run
    #  if not res[:result].failed? and not_empty?(res[:outStream])
    #    STDERR.puts "Given container name '#{contName}' already taken. Please try again"
    #  else
    #    break
    #  end
    #end

    #create_new_docker_container(config, contName, dcFact. cli)
    config.add_container(imageName, contName)
    config.to_storage

  end
  
end