Class: EtnaApp::Polyphemus
Instance Attribute Summary
#parent
Instance Method Summary
collapse
#environment, #exit, exit, #janus_client, #magma_client, #metis_client, #polyphemus_client, #token
#completions, #fill_in_missing_params, #find_command, #initialize, parent_scope, #setup
#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_yml ⇒ Object
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
# File 'lib/commands.rb', line 652
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_tag ⇒ Object
667
668
669
670
671
672
673
674
|
# File 'lib/commands.rb', line 667
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
614
615
616
617
618
619
620
621
622
623
624
625
|
# File 'lib/commands.rb', line 614
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
|
#image ⇒ Object
676
677
678
679
680
681
682
|
# File 'lib/commands.rb', line 676
def image
if @local
"polyphemus:#{@tag}"
else
"etnaagent/polyphemus:#{@tag}"
end
end
|
#run_cmd ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
# File 'lib/commands.rb', line 627
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_file ⇒ Object
648
649
650
|
# File 'lib/commands.rb', line 648
def temp_config_file
@temp_config_file ||= Tempfile.new
end
|