Class: PcfBlueGreen::SharedDeployFunctions

Inherits:
Object
  • Object
show all
Defined in:
lib/pcf_blue_green.rb

Instance Method Summary collapse

Constructor Details

#initializeSharedDeployFunctions

Returns a new instance of SharedDeployFunctions.



175
176
177
178
179
180
181
182
# File 'lib/pcf_blue_green.rb', line 175

def initialize
  cmd = "echo $(gem which pcf_blue_green)"
  shell = Mixlib::ShellOut.new(cmd)
  shell.run_command
  gem_path = shell.stdout
  sdf_path = gem_path.gsub("pcf_blue_green.rb\n", "shared-deploy-functions.sh")
  @source_cmd = "source \'#{sdf_path}\'"
end

Instance Method Details

#blue_green_deployObject



184
185
186
187
# File 'lib/pcf_blue_green.rb', line 184

def blue_green_deploy
  status = bash("#{@source_cmd} && blue-green")
  raise PcfBlueGreen::BlueGreenDeploymentFailed unless status
end

#env_var_manifest_updateObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/pcf_blue_green.rb', line 189

def env_var_manifest_update
  bash("#{@source_cmd} && cf-setup")
  manifest_file_path = ENV['cf_manifest']
  app = ENV['cf_app']
  tmp_json =''

  command = 'cf curl /v2/apps'
  shell = Mixlib::ShellOut.new(command)
  shell.run_command
  tmp_stdout = JSON.parse(shell.stdout)

  tmp_stdout['resources'].each do |resource|
    tmp_json = resource if resource['entity']['name'] == app
  end
  environments = tmp_json['entity']['environment_json'].map { |k,v| [k, "'#{v}'"]}.to_h

  open(manifest_file_path, 'a') do |f|
    environments.each do |env|
      f.puts "\s\s\s\s#{env.join(': ')}"
    end
  end
end