2017-07-03 20:50:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-08-11 18:38:47 +01:00
|
|
|
types=($TYPES)
|
|
|
|
echo "Available types: ${types[@]}"
|
|
|
|
echo "Selected type of deployment: $TYPE, Template file: $TEMPLATE"
|
2018-05-29 01:04:30 +01:00
|
|
|
|
|
|
|
function prepare_geny_cloud() {
|
2018-08-11 18:38:47 +01:00
|
|
|
contents=$(cat $TEMPLATE)
|
2018-06-22 00:16:40 +01:00
|
|
|
|
2018-05-29 01:04:30 +01:00
|
|
|
# Register
|
2018-08-11 18:38:47 +01:00
|
|
|
echo "Register user"
|
2018-05-29 01:04:30 +01:00
|
|
|
gmtool config username="${USER}" password="${PASS}"
|
|
|
|
gmtool license register "${LICENSE}"
|
|
|
|
|
|
|
|
# Start device(s)
|
|
|
|
echo "Creating device(s) based on given json file..."
|
|
|
|
for row in $(echo "${contents}" | jq -r '.[] | @base64'); do
|
|
|
|
get_value() {
|
|
|
|
echo ${row} | base64 --decode | jq -r ${1}
|
|
|
|
}
|
|
|
|
|
|
|
|
template=$(get_value '.template')
|
|
|
|
device=$(get_value '.device')
|
2018-06-19 00:20:15 +01:00
|
|
|
port=$(get_value '.port')
|
|
|
|
|
|
|
|
if [[ $port != null ]]; then
|
|
|
|
echo "Starting \"$device\" with template name \"$template\" on port \"$port\"..."
|
|
|
|
gmtool --cloud admin startdisposable "${template}" "${device}" --adb-serial-port "${port}"
|
|
|
|
else
|
|
|
|
echo "Starting \"$device\" with template name \"$template\"..."
|
|
|
|
gmtool --cloud admin startdisposable "${template}" "${device}"
|
|
|
|
fi
|
2018-05-29 01:04:30 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-08-11 18:38:47 +01:00
|
|
|
function prepare_geny_aws() {
|
|
|
|
contents=$(cat $TEMPLATE)
|
|
|
|
|
|
|
|
# Creating aws tf file(s)
|
|
|
|
echo "Creating tf file(s)"
|
|
|
|
index=1
|
2018-08-30 12:35:03 +01:00
|
|
|
port=5555
|
2018-08-11 18:38:47 +01:00
|
|
|
for row in $(echo "${contents}" | jq -r '.[] | @base64'); do
|
|
|
|
get_value() {
|
|
|
|
echo ${row} | base64 --decode | jq -r ${1}
|
|
|
|
}
|
|
|
|
|
|
|
|
region=$(get_value '.region')
|
2018-08-20 10:46:09 +01:00
|
|
|
android_version=$(get_value '.android_version')
|
2018-08-11 18:38:47 +01:00
|
|
|
instance=$(get_value '.instance')
|
|
|
|
|
|
|
|
|
|
|
|
echo $region
|
2018-08-20 10:46:09 +01:00
|
|
|
echo $android_version
|
2018-08-11 18:38:47 +01:00
|
|
|
echo $instance
|
|
|
|
|
|
|
|
aws_tf_content=$(cat <<_EOF
|
|
|
|
variable "aws_region_$index" {
|
|
|
|
type = "string"
|
|
|
|
default = "$region"
|
|
|
|
}
|
|
|
|
|
2018-08-20 10:46:09 +01:00
|
|
|
variable "android_version_$index" {
|
|
|
|
type = "string"
|
|
|
|
default = "$android_version"
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
variable "instance_type_$index" {
|
|
|
|
type = "string"
|
|
|
|
default = "$instance"
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
|
|
|
alias = "provider_$index"
|
|
|
|
region = "\${var.aws_region_$index}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "geny_sg_$index" {
|
2018-09-04 09:34:49 +01:00
|
|
|
provider = "aws.provider_$index"
|
2018-08-11 18:38:47 +01:00
|
|
|
ingress {
|
2018-08-20 10:46:09 +01:00
|
|
|
from_port = 0
|
|
|
|
to_port = 65535
|
|
|
|
protocol = "tcp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
2018-08-20 10:46:09 +01:00
|
|
|
egress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 65535
|
|
|
|
protocol = "udp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "aws_ami" "geny_aws_$index" {
|
|
|
|
provider = "aws.provider_$index"
|
|
|
|
most_recent = true
|
|
|
|
|
|
|
|
filter {
|
|
|
|
name = "name"
|
|
|
|
values = ["genymotion-ami-\${var.android_version_$index}-*"]
|
|
|
|
}
|
2018-08-21 08:49:10 +01:00
|
|
|
|
|
|
|
owners = ["679593333241"] #Genymotion
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 15:14:04 +01:00
|
|
|
resource "aws_key_pair" "geny_key_$index" {
|
|
|
|
provider = "aws.provider_$index"
|
2018-08-27 13:30:51 +01:00
|
|
|
public_key = "\${file("~/.ssh/id_rsa.pub")}"
|
2018-08-24 15:14:04 +01:00
|
|
|
}
|
|
|
|
|
2018-08-11 18:38:47 +01:00
|
|
|
resource "aws_instance" "geny_aws_$index" {
|
|
|
|
provider = "aws.provider_$index"
|
2018-08-20 10:46:09 +01:00
|
|
|
ami = "\${data.aws_ami.geny_aws_$index.id}"
|
2018-08-11 18:38:47 +01:00
|
|
|
instance_type = "\${var.instance_type_$index}"
|
|
|
|
vpc_security_group_ids = ["\${aws_security_group.geny_sg_$index.name}"]
|
2018-08-24 15:14:04 +01:00
|
|
|
key_name = "\${aws_key_pair.geny_key_$index.key_name}"
|
2018-08-11 18:38:47 +01:00
|
|
|
tags {
|
2018-08-20 10:46:09 +01:00
|
|
|
Name = "EK-\${data.aws_ami.geny_aws_$index.id}"
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
count = 1
|
2018-08-29 12:02:44 +01:00
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
|
|
|
user = "shell"
|
|
|
|
private_key = "\${file("~/.ssh/id_rsa")}"
|
|
|
|
}
|
|
|
|
|
|
|
|
script = "/root/enable_adb.sh"
|
|
|
|
}
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
output "public_dns_$index" {
|
2018-08-30 12:36:53 +01:00
|
|
|
value = "\${aws_instance.geny_aws_$index.public_dns}"
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
_EOF
|
|
|
|
)
|
|
|
|
echo "$aws_tf_content" > /root/aws_tf_$index.tf
|
|
|
|
((index++))
|
2018-08-30 12:35:03 +01:00
|
|
|
((port++))
|
2018-08-11 18:38:47 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Deploy EC2 instance(s)
|
|
|
|
echo "Deploy EC2 instance(s) on AWS with Genymotion image based on given json file..."
|
|
|
|
./terraform init
|
|
|
|
./terraform plan
|
|
|
|
./terraform apply -auto-approve
|
2018-08-24 15:14:04 +01:00
|
|
|
|
2018-08-30 12:35:03 +01:00
|
|
|
# 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"
|
2018-08-11 18:38:47 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 01:04:30 +01:00
|
|
|
function run_appium() {
|
|
|
|
echo "Preparing appium-server..."
|
|
|
|
CMD="appium --log $APPIUM_LOG"
|
2018-06-20 22:30:54 +01:00
|
|
|
if [ "$CONNECT_TO_GRID" = true ]; then
|
2018-05-29 01:04:30 +01:00
|
|
|
NODE_CONFIG_JSON="/root/src/nodeconfig.json"
|
|
|
|
/root/generate_config.sh $NODE_CONFIG_JSON
|
|
|
|
CMD+=" --nodeconfig $NODE_CONFIG_JSON"
|
|
|
|
fi
|
2018-06-20 22:30:54 +01:00
|
|
|
|
|
|
|
if [ "$RELAXED_SECURITY" = true ]; then
|
|
|
|
CMD+=" --relaxed-security"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Preparation is done"
|
2018-05-29 01:04:30 +01:00
|
|
|
$CMD
|
|
|
|
}
|
|
|
|
|
2018-06-22 00:16:40 +01:00
|
|
|
if [ "$REAL_DEVICE" = true ]; then
|
2018-06-12 00:05:35 +01:00
|
|
|
echo "Using real device"
|
2018-05-29 01:04:30 +01:00
|
|
|
run_appium
|
2018-06-22 00:16:40 +01:00
|
|
|
elif [ "$GENYMOTION" = true ]; then
|
2018-06-12 00:05:35 +01:00
|
|
|
echo "Using Genymotion"
|
2018-08-11 18:38:47 +01:00
|
|
|
echo "${types[@]}"
|
|
|
|
case $TYPE in
|
2018-09-04 09:34:49 +01:00
|
|
|
"${types[0]}" )
|
|
|
|
echo "Using Genymotion-Cloud"
|
2018-08-11 18:38:47 +01:00
|
|
|
prepare_geny_cloud
|
|
|
|
run_appium
|
2018-09-04 09:34:49 +01:00
|
|
|
;;
|
|
|
|
"${types[1]}" )
|
|
|
|
echo "Using Genymotion-AWS"
|
|
|
|
prepare_geny_aws
|
|
|
|
run_appium
|
|
|
|
;;
|
|
|
|
esac
|
2017-07-03 20:50:37 +01:00
|
|
|
else
|
2018-06-12 00:05:35 +01:00
|
|
|
echo "Using Emulator"
|
2018-05-29 01:04:30 +01:00
|
|
|
python3 -m src.app
|
2017-07-03 20:50:37 +01:00
|
|
|
fi
|