Class: Fastlane::Helper::MangoHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::MangoHelper
- Defined in:
- lib/fastlane/plugin/mango/helper/mango_helper.rb
Instance Attribute Summary collapse
-
#container_name ⇒ Object
readonly
Returns the value of attribute container_name.
-
#core_amount ⇒ Object
readonly
Returns the value of attribute core_amount.
-
#device_name ⇒ Object
readonly
Returns the value of attribute device_name.
-
#docker_image ⇒ Object
readonly
Returns the value of attribute docker_image.
-
#environment_variables ⇒ Object
readonly
Returns the value of attribute environment_variables.
-
#is_running_on_emulator ⇒ Object
readonly
Returns the value of attribute is_running_on_emulator.
-
#maximal_run_time ⇒ Object
readonly
Returns the value of attribute maximal_run_time.
-
#no_vnc_port ⇒ Object
readonly
Returns the value of attribute no_vnc_port.
-
#port_factor ⇒ Object
readonly
Returns the value of attribute port_factor.
-
#sleep_interval ⇒ Object
readonly
Returns the value of attribute sleep_interval.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#vnc_enabled ⇒ Object
readonly
Returns the value of attribute vnc_enabled.
Instance Method Summary collapse
-
#initialize(params) ⇒ MangoHelper
constructor
A new instance of MangoHelper.
- #kvm_disabled? ⇒ Boolean
-
#setup_container ⇒ Object
Setting up the container: 1.
Constructor Details
#initialize(params) ⇒ MangoHelper
Returns a new instance of MangoHelper.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 12 def initialize(params) @container_name = params[:container_name] @no_vnc_port = params[:no_vnc_port] @device_name = params[:device_name] @docker_image = params[:docker_image] @timeout = params[:container_timeout] @sdk_path = params[:sdk_path] @port_factor = params[:port_factor].to_i @core_amount = params[:core_amount].to_i @maximal_run_time = params[:maximal_run_time] @sleep_interval = 5 @container = nil @adb_path = adb_path @is_running_on_emulator = params[:is_running_on_emulator] @pre_action = params[:pre_action] @docker_registry_login = params[:docker_registry_login] @pull_latest_image = params[:pull_latest_image] @environment_variables = params[:environment_variables] @vnc_enabled = params[:vnc_enabled] @docker_commander = DockerCommander.new(container_name) @emulator_commander = EmulatorCommander.new(container_name) end |
Instance Attribute Details
#container_name ⇒ Object (readonly)
Returns the value of attribute container_name.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def container_name @container_name end |
#core_amount ⇒ Object (readonly)
Returns the value of attribute core_amount.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def core_amount @core_amount end |
#device_name ⇒ Object (readonly)
Returns the value of attribute device_name.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def device_name @device_name end |
#docker_image ⇒ Object (readonly)
Returns the value of attribute docker_image.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def docker_image @docker_image end |
#environment_variables ⇒ Object (readonly)
Returns the value of attribute environment_variables.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def environment_variables @environment_variables end |
#is_running_on_emulator ⇒ Object (readonly)
Returns the value of attribute is_running_on_emulator.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def is_running_on_emulator @is_running_on_emulator end |
#maximal_run_time ⇒ Object (readonly)
Returns the value of attribute maximal_run_time.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def maximal_run_time @maximal_run_time end |
#no_vnc_port ⇒ Object (readonly)
Returns the value of attribute no_vnc_port.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def no_vnc_port @no_vnc_port end |
#port_factor ⇒ Object (readonly)
Returns the value of attribute port_factor.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def port_factor @port_factor end |
#sleep_interval ⇒ Object (readonly)
Returns the value of attribute sleep_interval.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def sleep_interval @sleep_interval end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def timeout @timeout end |
#vnc_enabled ⇒ Object (readonly)
Returns the value of attribute vnc_enabled.
9 10 11 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 9 def vnc_enabled @vnc_enabled end |
Instance Method Details
#kvm_disabled? ⇒ Boolean
101 102 103 104 105 106 107 108 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 101 def kvm_disabled? begin @docker_commander.exec(command: 'kvm-ok > kvm-ok.txt') rescue StandardError # kvm-ok will always throw regardless of the result. therefore we save the output in the file and ignore the error end @docker_commander.exec(command: 'cat kvm-ok.txt').include?('KVM acceleration can NOT be used') end |
#setup_container ⇒ Object
Setting up the container:
-
Checks if ports are already allocated and kill the ones that do
-
Checks if Container we want to create already exist. If it does, restart it and check that the ports are correct
-
Creates container if there wasn’t one already created or the created one has incorrect ports
-
Finally, waits until container is up and running (Healthy) using timeout specified in params
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fastlane/plugin/mango/helper/mango_helper.rb', line 40 def setup_container assign_unique_vnc_port if port_factor && is_running_on_emulator if container_available? UI.important('Container was already started. Stopping and removing..') @docker_commander.delete_container end handle_ports_allocation if is_running_on_emulator && vnc_enabled pull_from_registry if @pull_latest_image # Make sure that network bridge for the current container is not already used @docker_commander.disconnect_network_bridge create_container if is_running_on_emulator && kvm_disabled? raise 'Linux requires GPU acceleration for running emulators, but KVM virtualization is not supported by your CPU. Exiting..' end container_state = wait_for_healthy_container if is_running_on_emulator && container_state connection_state = @emulator_commander.check_connection container_state = connection_state && connection_state end unless container_state UI.important("Will retry to create a healthy docker container after #{sleep_interval} seconds") @docker_commander.delete_container sleep @sleep_interval create_container unless wait_for_healthy_container UI.important('Container is unhealthy. Exiting..') begin Actions.sh("docker logs #{container_name} --tail 200") Actions.sh("docker exec -i #{container_name} cat /var/log/supervisor/docker-android.stderr.log") Actions.sh("docker exec -i #{container_name} cat /var/log/supervisor/supervisord.log") rescue StandardError # do nothing end # We use code "2" as we need something than just standard error code 1, so we can differentiate the next step in CI exit 2 end if is_running_on_emulator && !@emulator_commander.check_connection UI.important('Cannot connect to emulator. Exiting..') exit 2 end end if is_running_on_emulator @emulator_commander.disable_animations @emulator_commander.increase_logcat_storage end execute_pre_action if @pre_action end |