Class: EtnaApp::Polyphemus

Inherits:
Etna::Command show all
Includes:
WithEtnaClients
Defined in:
lib/commands.rb

Instance Attribute Summary

Attributes inherited from Etna::Command

#parent

Instance Method Summary collapse

Methods included from WithEtnaClients

#environment, #exit, exit, #janus_client, #magma_client, #metis_client, #polyphemus_client, #token

Methods inherited from Etna::Command

#completions, #fill_in_missing_params, #find_command, #initialize, parent_scope, #setup

Methods included from Etna::CommandOrExecutor

#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage

Constructor Details

This class inherits a constructor from Etna::Command

Instance Method Details

#create_config_ymlObject



430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/commands.rb', line 430

def create_config_yml
  host_config = [:metis, :magma, :janus, :timur].map do |host|
    [host, (EtnaApp.instance.config(host) || {}).update(token: token)]
  end.to_h

  config = {
      EtnaApp.instance.environment => {
                                          log_file: '/dev/stdout',
                                          log_level: 'info',
                                      }.update(host_config)
  }

  File.open(temp_config_file.path, 'w') { |f| YAML.dump(config, f) }
end

#default_tagObject



445
446
447
448
449
450
451
452
# File 'lib/commands.rb', line 445

def default_tag
  docker = EtnaApp.instance.config(:docker)
  if docker.nil?
    nil
  else
    docker[:default_tag]
  end || 'master'
end

#execute(tag: nil, local: false) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/commands.rb', line 392

def execute(tag: nil, local: false)
  @tag = tag || default_tag
  @local = local
  create_config_yml

  unless @local
    puts `docker pull #{image}`
  end

  puts run_cmd
  exec(run_cmd)
end

#imageObject



454
455
456
457
458
459
460
# File 'lib/commands.rb', line 454

def image
  if @local
    "polyphemus:#{@tag}"
  else
    "etnaagent/polyphemus:#{@tag}"
  end
end

#run_cmdObject



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/commands.rb', line 405

def run_cmd
  parts = ['docker run --rm -it']

  unless Gem.win_platform?
    uid = Etc.getpwnam(ENV['USER']).uid
    gid = Etc.getgrnam('docker').gid
    parts << "-u #{uid}:#{gid}"
    parts << "-v /etc/passwd:/etc/passwd:ro"
    parts << "-v /etc/group:/etc/group:ro"
  end

  parts << "-v #{temp_config_file.path}:/app/config.yml:ro"
  parts << "-v #{Dir.pwd}:/app/workspace"
  parts << "-e HOME=/root"

  parts << image
  parts << "bash -c 'cd /app/workspace && exec bash --rcfile /root/.bashrc'"

  parts.join(' ')
end

#temp_config_fileObject



426
427
428
# File 'lib/commands.rb', line 426

def temp_config_file
  @temp_config_file ||= Tempfile.new
end