Module: Orchparty::Plugin::RancherV2

Defined in:
lib/orchparty/plugins/rancher_v2.rb

Class Method Summary collapse

Class Method Details

.define_flags(c) ⇒ Object



33
34
35
36
# File 'lib/orchparty/plugins/rancher_v2.rb', line 33

def self.define_flags(c)
  c.flag [:docker_compose,:d], :desc => 'Set the output file'
  c.flag [:rancher_compose,:r], :desc => 'Set the output file'
end

.descObject



29
30
31
# File 'lib/orchparty/plugins/rancher_v2.rb', line 29

def self.desc
  "generate rancher-compose.yml v2 file"
end

.docker_output(application) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/orchparty/plugins/rancher_v2.rb', line 63

def self.docker_output(application)
  output_hash = {"version" => "2",
                 "services" =>
                 application.services.map do |name,service|
                   service = service.to_h
                   #p service.keys
                   service.delete('rancher')
                   service.delete(:rancher)
                   [service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)]
                 end.to_h,
                }
  output_hash["volumes"] = transform_to_yaml(application.volumes) if application.volumes && !application.volumes.empty?
  output_hash["networks"] = transform_to_yaml(application.networks) if application.networks && !application.networks.empty?
  output_hash.to_yaml(line_width: -1)
end

.generate(ast, options) ⇒ Object



38
39
40
41
42
43
# File 'lib/orchparty/plugins/rancher_v2.rb', line 38

def self.generate(ast, options)
  output = rancher_output(ast)
  File.write(options[:rancher_compose], output)
  output = docker_output(ast)
  File.write(options[:docker_compose], output)
end

.rancher_output(application) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/orchparty/plugins/rancher_v2.rb', line 50

def self.rancher_output(application)
  output_hash = {
    "version" => "2",
     "services" =>
     application.services.map do |name,service|
       service = service.to_h
       rancher= ( service['rancher'] || service[:rancher] || { scale: 1 } ) # some dummy placeholder
       [service.delete(:name), HashUtils.deep_stringify_keys(rancher)]
     end.to_h,
  }
  output_hash.to_yaml(line_width: -1)
end

.transform_to_yaml(hash) ⇒ Object



45
46
47
48
# File 'lib/orchparty/plugins/rancher_v2.rb', line 45

def self.transform_to_yaml(hash)
  hash = hash.deep_transform_values{|v| v.is_a?(Hash) ? v.to_h : v }
  HashUtils.deep_stringify_keys(hash)
end