Class: Docker::Cli::DockerComposer

Inherits:
Object
  • Object
show all
Includes:
TR::ArgUtils, TR::CondUtils
Defined in:
lib/docker/cli/docker_composer.rb

Instance Method Summary collapse

Instance Method Details

#parse_input(argv, &block) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/docker/cli/docker_composer.rb', line 20

def parse_input(argv, &block)
  @dcPath = argv.first
  @dcPath = "./docker-compose.yml" if is_empty?(@dcPath) 
  @dcPath = "./docker-compose.yaml" if not File.exist?(@dcPath)
  raise RuntimeException, "docker-compose.[yml,yaml] not found. Please provide the docker-compose.yml file to load" if not File.exist?(@dcPath)

  @outPath = argv[1]
  @outPath = "#{@dcPath}-gen.yml" if is_empty?(@outPath)

  process_dc

  [true, []]
end

#process_dcObject



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
# File 'lib/docker/cli/docker_composer.rb', line 34

def process_dc
  if File.exist?(@dcPath)

    cont = YAML.safe_load(File.read(@dcPath))

    if not_empty?(cont["services"])

      cont["services"].each do |servName, conf|

        # if user key is empty, match with current uid and gid
        if conf.keys.include?("user") and is_empty?(conf["user"])
          conf["user"] = "#{[:uid]}:#{user_group_info[:gid]}"
        end

        # add to volumes if there is development gems found
        if not_empty?(conf["volumes"])
          vol = conf["volumes"]

          if vol.include?("devgems")

            vol.delete("devgems")
            logger.debug "Volume after delete : #{vol.inspect}"

            devGems = Cli.find_dev_gems
            logger.debug " Found #{devGems.length} devgems"
            if devGems.length > 0
              if @parse_argv_block
                @mount_root = @parse_argv_block.call(:prompt_docker_mount_root)
              else
                raise RuntimeException, "Please provide a block to prompt for missing parameters"
              end

              devGems.each do |name,path|
                vol << "#{path}:#{File.join(@mount_root, name)}"
              end
            end

          end

        end
      end

    end

    reCont = cont.to_yaml
    reCont = reCont.gsub("---","")
    File.open(@outPath, "w") do |f|
      f.write reCont
    end

  else
    raise RuntimeException, "Given docker compose file '#{@dcPath}' does not exist"
  end
end