Connect to Genymotion emulator automatically

This commit is contained in:
butomo1989 2018-08-30 13:35:03 +02:00
parent ccec2c5969
commit aa7a798f62
3 changed files with 20 additions and 14 deletions

View file

@ -47,4 +47,4 @@ services:
environment: environment:
- TYPE=aws - TYPE=aws
- TEMPLATE=/root/tmp/aws.json - TEMPLATE=/root/tmp/aws.json
#TODO - CONNECT_TO_GRID=true - CONNECT_TO_GRID=true

View file

@ -52,7 +52,7 @@ getAbort() {
"${types[1]}" ) "${types[1]}" )
contents=$(cat $TEMPLATE) contents=$(cat $TEMPLATE)
echo "ABORT SIGNAL detected! Detroy all EC2 instance(s)..." echo "ABORT SIGNAL detected! Detroy all EC2 instance(s)..."
./terraform destroy -auto-approve ./terraform destroy -auto-approve -lock=false
;; ;;
esac esac
} }

View file

@ -39,6 +39,7 @@ function prepare_geny_aws() {
# Creating aws tf file(s) # Creating aws tf file(s)
echo "Creating tf file(s)" echo "Creating tf file(s)"
index=1 index=1
port=5555
for row in $(echo "${contents}" | jq -r '.[] | @base64'); do for row in $(echo "${contents}" | jq -r '.[] | @base64'); do
get_value() { get_value() {
echo ${row} | base64 --decode | jq -r ${1} echo ${row} | base64 --decode | jq -r ${1}
@ -129,21 +130,14 @@ resource "aws_instance" "geny_aws_$index" {
} }
} }
output "image_id_$index" {
value = "\${data.aws_ami.geny_aws_$index.id}"
}
output "instance_id_$index" {
value = "\${aws_instance.geny_aws_$index.*.id}"
}
output "public_dns_$index" { output "public_dns_$index" {
value = "\${aws_instance.geny_aws_$index.*.public_dns}" value = "\${aws_instance.geny_aws_1.public_dns}"
} }
_EOF _EOF
) )
echo "$aws_tf_content" > /root/aws_tf_$index.tf echo "$aws_tf_content" > /root/aws_tf_$index.tf
((index++)) ((index++))
((port++))
done done
# Deploy EC2 instance(s) # Deploy EC2 instance(s)
@ -151,9 +145,21 @@ _EOF
./terraform init ./terraform init
./terraform plan ./terraform plan
./terraform apply -auto-approve ./terraform apply -auto-approve
#TODO
# Workaround to connect adb remotely because there is a issue by using local-exec
time_sleep=5
interval_sleep=1
echo "Connect to adb remotely"
for ((i=index;i>=1;i--)); do
dns=$(./terraform output public_dns_$i)
((sleep ${interval_sleep} && adb connect localhost:${port}) > /dev/null & ssh -i ~/.ssh/id_rsa -oStrictHostKeyChecking=no -q -NL ${port}:localhost:5555 shell@${dns}) &
((port--))
time_sleep=$((time_sleep+interval_sleep))
done
echo "It will wait for ${time_sleep} until all device(s) to be connected"
sleep ${time_sleep}
adb devices
echo "Process is completed"
} }
function run_appium() { function run_appium() {
@ -188,7 +194,7 @@ elif [ "$GENYMOTION" = true ]; then
"${types[1]}" ) "${types[1]}" )
echo "Using Genymotion-AWS" echo "Using Genymotion-AWS"
prepare_geny_aws prepare_geny_aws
# TODO: please activate this: run_appium run_appium
;; ;;
esac esac
else else