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



650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/commands.rb', line 650

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



665
666
667
668
669
670
671
672
# File 'lib/commands.rb', line 665

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



612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/commands.rb', line 612

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



674
675
676
677
678
679
680
# File 'lib/commands.rb', line 674

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

#run_cmdObject



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/commands.rb', line 625

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



646
647
648
# File 'lib/commands.rb', line 646

def temp_config_file
  @temp_config_file ||= Tempfile.new
end