Added integration with Genymotion in AWS

This commit is contained in:
butomo1989 2018-08-11 19:38:47 +02:00
parent d7c9730712
commit dd7ef41590
6 changed files with 196 additions and 17 deletions

View file

@ -103,6 +103,16 @@ RUN wget -nv -O genymotion.bin "https://dl.genymotion.com/releases/genymotion-${
&& rm genymotion.bin
COPY genymotion/generate_config.sh genymotion/geny_start.sh /root/
#===================
# Install Terraform
#===================
ARG TERRAFORM_VERSION=0.11.7
ENV TERRAFORM_VERSION=$TERRAFORM_VERSION
RUN wget -nv -O terraform.zip "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" \
&& unzip -x terraform.zip \
&& rm terraform.zip
#===============
# Expose Ports
#---------------

View file

@ -11,10 +11,11 @@ services:
- 4444:4444
# Please stop this container by using docker stop instead of docker-compose stop
genymotion:
cloud:
image: butomo1989/docker-android-genymotion
depends_on:
- selenium_hub
privileged: true
ports:
- 6080:6080
- 4723:4723
@ -22,8 +23,28 @@ services:
- $PWD/sample_apk:/root/tmp/sample_apk
- $PWD/sample_devices:/root/tmp
environment:
- GENY_TEMPLATE=/root/tmp/devices.json
- USER=xxx
- PASS=xxx
- LICENSE=xxx
- TYPE=genycloud
- TEMPLATE=/root/tmp/devices.json
- USER=$USER
- PASS=$PASS
- LICENSE=$LICENSE
- CONNECT_TO_GRID=true
# Please stop this container by using docker stop instead of docker-compose stop
# The implementation still in progress
aws:
image: butomo1989/docker-android-genymotion
depends_on:
- selenium_hub
privileged: true
ports:
- 6080:6080
- 4723:4723
volumes:
- ~/.aws:/root/.aws
- $PWD/sample_apk:/root/tmp/sample_apk
- $PWD/sample_devices:/root/tmp
environment:
- TYPE=aws
- TEMPLATE=/root/tmp/aws.json
#TODO - CONNECT_TO_GRID=true

View file

@ -0,0 +1,12 @@
[
{
"region": "eu-west-1",
"ami": "ami-861125ff",
"instance": "t2.small"
},
{
"region": "eu-west-1",
"ami": "ami-861125ff",
"instance": "t2.small"
}
]

View file

@ -0,0 +1,3 @@
#!/bin/bash
(export USER=$USER && export PASS=$PASS && export LICENSE=$LICENSE && docker-compose -f geny.yml up -d)

View file

@ -1,18 +1,44 @@
#!/bin/bash
# This script is needed because of https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/
if [ -z "$GENY_TEMPLATE" ]; then
GENY_TEMPLATE="/root/tmp/devices.json"
types=(genycloud aws)
if [ -z "$TYPE" ]; then
echo "Please specify one of following types: ${types[@]}"
exit 1
fi
TYPE=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]')
if [ -z "$TEMPLATE" ]; then
case $TYPE in
"${types[0]}" )
TEMPLATE="/root/tmp/devices.json"
;;
"${types[1]}" )
TEMPLATE="/root/tmp/aws.json"
;;
*)
"Type $TYPE is not supported! Valid types: ${types[@]}"
exit 1
;;
esac
fi
if [ ! -f "$GENY_TEMPLATE" ]; then
if [ ! -f "$TEMPLATE" ]; then
echo "File not found! Nothing to do!"
exit 1
fi
echo "[geny_start] Available types: ${types[@]}"
echo "[geny_start] Selected type of deployment: $TYPE, Template file: $TEMPLATE"
export TYPE=$TYPE
export TEMPLATE=$TEMPLATE
export TYPES=${types[@]}
getAbort() {
if [ "$GENYMOTION" = true ]; then
contents=$(cat $GENY_TEMPLATE)
case $TYPE in
"${types[0]}" )
contents=$(cat $TEMPLATE)
echo "ABORT SIGNAL detected! Stopping all created emulators..."
for row in $(echo "${contents}" | jq -r '.[] | @base64'); do
get_value() {
@ -22,7 +48,13 @@ getAbort() {
gmtool --cloud admin stopdisposable $(get_value '.device')
done
echo "Done"
fi
;;
"${types[1]}" )
contents=$(cat $TEMPLATE)
echo "ABORT SIGNAL detected! Detroy all EC2 instance(s)..."
./terraform destroy -auto-approve
;;
esac
}
trap 'getAbort; exit' EXIT

View file

@ -1,13 +1,14 @@
#!/bin/bash
if [ -z "$GENY_TEMPLATE" ]; then
GENY_TEMPLATE="/root/tmp/devices.json"
fi
types=($TYPES)
echo "Available types: ${types[@]}"
echo "Selected type of deployment: $TYPE, Template file: $TEMPLATE"
function prepare_geny_cloud() {
contents=$(cat $GENY_TEMPLATE)
contents=$(cat $TEMPLATE)
# Register
echo "Register user"
gmtool config username="${USER}" password="${PASS}"
gmtool license register "${LICENSE}"
@ -32,6 +33,95 @@ function prepare_geny_cloud() {
done
}
function prepare_geny_aws() {
contents=$(cat $TEMPLATE)
# Creating aws tf file(s)
echo "Creating tf file(s)"
index=1
for row in $(echo "${contents}" | jq -r '.[] | @base64'); do
get_value() {
echo ${row} | base64 --decode | jq -r ${1}
}
region=$(get_value '.region')
ami=$(get_value '.ami')
instance=$(get_value '.instance')
echo $region
echo $ami
echo $instance
aws_tf_content=$(cat <<_EOF
variable "aws_region_$index" {
type = "string"
default = "$region"
}
variable "ami_id_$index" {
type = "string"
default = "$ami"
}
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" {
provider = "aws.provider_$index"
name = "geny_sg_$index"
description = "Security group for EC2 instance of Genymotion"
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "geny_aws_$index" {
provider = "aws.provider_$index"
ami = "\${var.ami_id_$index}"
instance_type = "\${var.instance_type_$index}"
vpc_security_group_ids = ["\${aws_security_group.geny_sg_$index.name}"]
tags {
Name = "EK-\${var.ami_id_$index}"
}
count = 1
}
output "instance_id_$index" {
value = "\${aws_instance.geny_aws_$index.*.id}"
}
output "public_dns_$index" {
value = "\${aws_instance.geny_aws_$index.*.public_dns}"
}
_EOF
)
echo "$aws_tf_content" > /root/aws_tf_$index.tf
((index++))
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
# Connect with adb
# TODO
}
function run_appium() {
echo "Preparing appium-server..."
CMD="appium --log $APPIUM_LOG"
@ -54,8 +144,19 @@ if [ "$REAL_DEVICE" = true ]; then
run_appium
elif [ "$GENYMOTION" = true ]; then
echo "Using Genymotion"
echo "${types[@]}"
case $TYPE in
"${types[0]}" )
echo "Using Genymotion-Cloud"
prepare_geny_cloud
run_appium
;;
"${types[1]}" )
echo "Using Genymotion-AWS"
prepare_geny_aws
# TODO: please activate this: run_appium
;;
esac
else
echo "Using Emulator"
python3 -m src.app