From 705be0e3c92e2cb0fa19d02d214ef99ede9cd6e1 Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Wed, 30 May 2018 00:54:06 +0200 Subject: [PATCH] Added auto-stop feature --- docker/Genymotion | 4 +++- geny.yml | 31 +++++++++++++++++++++++++++++++ genymotion/geny_start.sh | 27 +++++++++++++++++++++++++++ src/appium.sh | 7 +------ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 geny.yml create mode 100755 genymotion/geny_start.sh diff --git a/docker/Genymotion b/docker/Genymotion index 2e3bfc9..5645664 100644 --- a/docker/Genymotion +++ b/docker/Genymotion @@ -115,5 +115,7 @@ EXPOSE 4723 6080 5555 COPY src /root/src COPY supervisord.conf /root/ RUN chmod -R +x /root/src && chmod +x /root/supervisord.conf +COPY genymotion/geny_start.sh /root +RUN chmod +x /root/geny_start.sh -CMD /usr/bin/supervisord --configuration supervisord.conf +CMD ["./geny_start.sh"] diff --git a/geny.yml b/geny.yml new file mode 100644 index 0000000..402355c --- /dev/null +++ b/geny.yml @@ -0,0 +1,31 @@ +# Note: It requires docker-compose 1.13.0 +# +# Usage: docker-compose up -d +version: "2.2" + +services: + # Selenium hub + selenium_hub: + image: selenium/hub:3.12.0-americium + ports: + - 4444:4444 + + # Please stop this container by using docker stop instead of docker-compose stop + genymotion: + image: geny + depends_on: + - selenium_hub + privileged: true + ports: + - 6080:6080 + - 4723:4723 + volumes: + - $PWD/example/sample_apk:/opt + - $PWD/genymotion/sample:/root/tmp + environment: + - GENY_TEMPLATE=/root/tmp/devices.json + - USER=xxx + - PASS=xxx + - LICENSE=xxx + - CONNECT_TO_GRID=True + - APPIUM=true diff --git a/genymotion/geny_start.sh b/genymotion/geny_start.sh new file mode 100755 index 0000000..5e0671d --- /dev/null +++ b/genymotion/geny_start.sh @@ -0,0 +1,27 @@ +#!/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" +fi + +if [ ! -f "$GENY_TEMPLATE" ]; then + echo "File not found! Nothing to do!" + exit 1 +fi + +contents=$(cat $GENY_TEMPLATE) +getAbort() { + echo "ABORT SIGNAL detected! Stopping all created emulators..." + for row in $(echo "${contents}" | jq -r '.[] | @base64'); do + get_value() { + echo ${row} | base64 --decode | jq -r ${1} + } + + gmtool --cloud admin stopdisposable $(get_value '.device') + done + echo "Done" +} +trap 'getAbort; exit' EXIT + +/usr/bin/supervisord --configuration supervisord.conf diff --git a/src/appium.sh b/src/appium.sh index d2c607c..974a608 100644 --- a/src/appium.sh +++ b/src/appium.sh @@ -1,12 +1,7 @@ #!/bin/bash if [ -z "$GENY_TEMPLATE" ]; then - GENY_TEMPLATE="/root/tmp/devices.json" -fi - -if [ ! -f "$GENY_TEMPLATE" ]; then - echo "File not found! Nothing to do!" - exit 1 + GENY_TEMPLATE="/root/tmp/devices.json" fi contents=$(cat $GENY_TEMPLATE)