Class: Envirobly::ContainerShell
- Inherits:
-
Object
- Object
- Envirobly::ContainerShell
- Defined in:
- lib/envirobly/container_shell.rb
Constant Summary collapse
- AWS_ENV =
[ "AWS_ACCESS_KEY_ID='%s'", "AWS_SECRET_ACCESS_KEY='%s'", "AWS_SESSION_TOKEN='%s'" ]
- SSH =
[ "ssh -i %s", "-o StrictHostKeyChecking=no", "-o UserKnownHostsFile=/dev/null", "-o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL", "-o SendEnv=ENVIROBLY_SERVICE_SHELL_USER", "-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id %s --region %s'" ]
- USER_AND_HOST =
"envirobly-service@%s"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Instance Method Summary collapse
- #exec(command = nil) ⇒ Object
-
#initialize(service_name, options, shell:) ⇒ ContainerShell
constructor
A new instance of ContainerShell.
- #rsync(source, destination) ⇒ Object
Constructor Details
#initialize(service_name, options, shell:) ⇒ ContainerShell
Returns a new instance of ContainerShell.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/envirobly/container_shell.rb', line 22 def initialize(service_name, , shell:) @service_name = service_name @options = commit = Git::Commit.new "HEAD" default_account = Defaults::Account.new(shell:) default_project = Defaults::Project.new(shell:) target = Target.new( default_account_id: default_account.value, default_project_id: default_project.value, default_project_name: Defaults::Project.dirname, default_environ_name: commit.current_branch, account_id: .account_id, project_id: .project_id, project_name: .project_name, environ_name: .environ_name ) if target.missing_params.include?(:account_id) target.account_id = default_account.require_value end target.ignored_params.each do |param| shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it" end @params = { account_id: target.account_id, project_id: target.project_id, project_name: target.project_name, environ_name: target.environ_name, service_name:, instance_slot: .instance_slot || 0 } if .project_name.blank? && .account_id.blank? && .project_id.blank? @params[:project_id] = Defaults::Project.new.value end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/envirobly/container_shell.rb', line 20 def @options end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
20 21 22 |
# File 'lib/envirobly/container_shell.rb', line 20 def service_name @service_name end |
Instance Method Details
#exec(command = nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/envirobly/container_shell.rb', line 63 def exec(command = nil) with_private_key do system join(env_vars, ssh, user_and_host, command) end end |
#rsync(source, destination) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/envirobly/container_shell.rb', line 69 def rsync(source, destination) with_private_key do system join( env_vars, %(rsync #{.args} -e "#{ssh}"), source.sub("#{service_name}:", "#{user_and_host}:"), destination.sub("#{service_name}:", "#{user_and_host}:") ) end end |