Big restructuring by moving to python
19
.dockerignore
Normal file
@ -0,0 +1,19 @@
|
||||
# Git
|
||||
.git/
|
||||
|
||||
# IDE
|
||||
**/*.idea
|
||||
backup
|
||||
|
||||
# Python
|
||||
**/*.egg-info
|
||||
**/*.pyc
|
||||
**/__pycache__
|
||||
**/venv
|
||||
|
||||
# Unit Test
|
||||
**/.coverage
|
||||
**/coverage.xml
|
||||
**/xunit.xml
|
||||
**/coverage
|
||||
tmp/
|
||||
1
.gitattributes
vendored
@ -1 +0,0 @@
|
||||
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
||||
16
.github/FUNDING.yml
vendored
Executable file → Normal file
@ -1,17 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
github: [budtmo]
|
||||
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
|
||||
# Bitcoin (BTC)
|
||||
custom:
|
||||
- "paypal.me/budtmo"
|
||||
- "paypal.me/budtmo"
|
||||
|
||||
28
.github/ISSUE_TEMPLATE/bug.md
vendored
@ -1,28 +0,0 @@
|
||||
---
|
||||
|
||||
name: 🐛 Bug report
|
||||
about: Report a bug to improve the tool
|
||||
---
|
||||
|
||||
## 🐛 Bug Report
|
||||
|
||||
Operating System:
|
||||
<!-- OSX Yosemite, Ubuntu 18.04, Windows 10 etc -->
|
||||
|
||||
Docker Image:
|
||||
<!-- budtmo/docker-android-x86-7.1.1, budtmo/docker-android-real-device etc -->
|
||||
|
||||
Docker Version:
|
||||
<!-- 17.09.0-ce, 17.06.2-ce etc -->
|
||||
|
||||
Docker-compose version (Only if you use it):
|
||||
<!-- 1.16.1 etc -->
|
||||
|
||||
Docker Command to start docker-android:
|
||||
<!-- docker run ... -->
|
||||
|
||||
## Expected Behavior
|
||||
<!-- Explaination about expected behaviour goes here -->
|
||||
|
||||
## Actual Behavior
|
||||
<!-- Explaination about actual behaviour goes here -->
|
||||
45
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: 🐛 Bug Report
|
||||
description: File a bug report
|
||||
title: "[🐛 Bug ]: "
|
||||
labels: [bug]
|
||||
body:
|
||||
- type: input
|
||||
id: operating-system
|
||||
attributes:
|
||||
label: Operating System
|
||||
description: Which host operating system do you use?
|
||||
placeholder: e.g. OSX Yosemite / Ubuntu 20.04 / Windows 10 etc
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: docker-image
|
||||
attributes:
|
||||
label: Docker Image
|
||||
description: Which docker image do you use?
|
||||
placeholder: e.g. budtmo/docker-android:emulator_10.0_v2.0 / budtmo/docker-android:genymotion_v2.0 etc
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected-behaviour
|
||||
attributes:
|
||||
label: Expected behaviour
|
||||
description: |
|
||||
What behaviour that you expected?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual-behaviour
|
||||
attributes:
|
||||
label: Actual behaviour
|
||||
description: |
|
||||
What is the actual behaviour?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Logs
|
||||
description: |
|
||||
Please provide logs here
|
||||
validations:
|
||||
required: false
|
||||
45
.github/ISSUE_TEMPLATE/bug_pro_version.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: 🐛 [Pro version] Bug Report
|
||||
description: File a bug report
|
||||
title: "[🐛 PRO | Bug ]: "
|
||||
labels: [bug, pro]
|
||||
body:
|
||||
- type: input
|
||||
id: operating-system
|
||||
attributes:
|
||||
label: Operating System
|
||||
description: Which host operating system do you use?
|
||||
placeholder: e.g. OSX Yosemite / Ubuntu 20.04 / Windows 10 etc
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: docker-image
|
||||
attributes:
|
||||
label: Docker Image
|
||||
description: Which docker image do you use?
|
||||
placeholder: e.g. budtmo/docker-android-pro:emulator_10.0_v2.0 / budtmo/docker-android-pro:emulator_headless_10.0_v2.0 etc
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected-behaviour
|
||||
attributes:
|
||||
label: Expected behaviour
|
||||
description: |
|
||||
What behaviour that you expected?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual-behaviour
|
||||
attributes:
|
||||
label: Actual behaviour
|
||||
description: |
|
||||
What is the actual behaviour?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Logs
|
||||
description: |
|
||||
Please provide logs here
|
||||
validations:
|
||||
required: false
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 📖 Docker-Android Documentation
|
||||
url: https://github.com/budtmo/docker-android
|
||||
about: Please read the whole project README before filling out an issue.
|
||||
16
.github/ISSUE_TEMPLATE/feature.md
vendored
@ -1,16 +0,0 @@
|
||||
---
|
||||
|
||||
name: 🚀 Feature Request
|
||||
about: Submit your idea to have cool features
|
||||
---
|
||||
|
||||
## 🚀 Feature Request
|
||||
|
||||
Idea:
|
||||
<!-- A clear explanation about the feature -->
|
||||
|
||||
Problems that want to be solved:
|
||||
<!-- A clear explanation about why we need that feature -->
|
||||
|
||||
Note:
|
||||
<!-- Additional note -->
|
||||
29
.github/ISSUE_TEMPLATE/feature.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
name: 🚀 Feature Request
|
||||
description: Submit your idea to have cool feature(s)
|
||||
title: "[🚀 Feature Request ]: "
|
||||
labels: [feature-request]
|
||||
body:
|
||||
- type: textarea
|
||||
id: idea
|
||||
attributes:
|
||||
label: Idea
|
||||
description: |
|
||||
What is the idea that you want to share to improve the project?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: problem
|
||||
attributes:
|
||||
label: Probelm to solve
|
||||
description: |
|
||||
What is the problem that you want to solve with requested feature?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: Note
|
||||
attributes:
|
||||
label: Additional Note
|
||||
description: |
|
||||
Please share any additional information here if needed
|
||||
validations:
|
||||
required: false
|
||||
9
.github/ISSUE_TEMPLATE/question.md
vendored
@ -1,9 +0,0 @@
|
||||
---
|
||||
|
||||
name: 💬 Questions / Help
|
||||
about: If you have questions, please check the group chat
|
||||
---
|
||||
|
||||
## 💬 Questions and Help
|
||||
|
||||
**Please make sure that it is an issue / a feature request. If it is a question / help wanted, please visit [our group chat](https://gitter.im/budtmo/docker-android). Thank you!**
|
||||
8
.github/PULL_REQUEST_TEMPLATE.md
vendored
Executable file → Normal file
@ -1,12 +1,8 @@
|
||||
### Purpose of changes
|
||||
<!-- Please describe why this change is required / What problem you want to solve. -->
|
||||
|
||||
### Types of changes
|
||||
_Put an `x` in the boxes that apply_
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
|
||||
### How has this been tested?
|
||||
<!-- Please describe in detail how you tested your changes. -->
|
||||
### Purpose of changes
|
||||
<!-- Please describe why this change is required / What problem you want to solve. -->
|
||||
|
||||
82
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*-*'
|
||||
|
||||
jobs:
|
||||
run_test:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.8"]
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
cd cli
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
|
||||
- name: Run test
|
||||
run: |
|
||||
cd cli && nosetests -v
|
||||
|
||||
release_base:
|
||||
runs-on: ubuntu-20.04
|
||||
needs: run_test
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get release version
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and push base image (${RELEASE_VERSION})
|
||||
run: |
|
||||
docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
|
||||
./app.sh push base ${RELEASE_VERSION}
|
||||
docker logout
|
||||
|
||||
release_emulator:
|
||||
runs-on: ubuntu-20.04
|
||||
needs: release_base
|
||||
strategy:
|
||||
matrix:
|
||||
android: ["9.0", "10.0", "11.0", "12.0", "13.0"]
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get release version
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and push emulator image ${{ matrix.android }} (${RELEASE_VERSION})
|
||||
run: |
|
||||
docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
|
||||
./app.sh push emulator ${RELEASE_VERSION} ${{ matrix.android }}
|
||||
docker logout
|
||||
|
||||
release_genymotion:
|
||||
runs-on: ubuntu-20.04
|
||||
needs: release_base
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get release version
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and push genymotion image (${RELEASE_VERSION})
|
||||
run: |
|
||||
docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
|
||||
./app.sh push genymotion ${RELEASE_VERSION}
|
||||
docker logout
|
||||
25
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
name: Run Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build base image
|
||||
run: script -e -c "./app.sh build base test"
|
||||
|
||||
- name: Build emulator image and run unit-test
|
||||
run: script -e -c "./app.sh test emulator test 11.0 && sudo mv tmp/* . && ls -al"
|
||||
|
||||
- name: Publish test result
|
||||
run: script -e -c "bash <(curl -s https://codecov.io/bash)"
|
||||
27
.gitignore
vendored
@ -1,9 +1,20 @@
|
||||
.idea/*
|
||||
.DS_Store
|
||||
*.pyc
|
||||
# IDE
|
||||
**/*.idea
|
||||
backup
|
||||
|
||||
# Coverage
|
||||
.coverage
|
||||
coverage.xml
|
||||
xunit.xml
|
||||
coverage/*
|
||||
# Python
|
||||
**/*.egg-info
|
||||
**/*.pyc
|
||||
**/__pycache__
|
||||
**/venv
|
||||
|
||||
# Unit Test
|
||||
**/.coverage
|
||||
**/coverage.xml
|
||||
**/xunit.xml
|
||||
**/coverage
|
||||
tmp/
|
||||
|
||||
# Dev-files
|
||||
n*.txt
|
||||
test-*.sh
|
||||
|
||||
37
Analytics.md
@ -1,37 +0,0 @@
|
||||
# Docker-Android's Anonymous Aggregate User Behaviour Analytics
|
||||
Docker-Android has begun gathering anonymous aggregate user behaviour analytics and reporting these to Google Analytics. You are notified about this when you start Docker-Android.
|
||||
|
||||
## Why?
|
||||
Docker-Android is provided free of charge for our internal and external users and we don't have direct communication with its users nor time resources to ask directly for their feedback. As a result, we now use anonymous aggregate user analytics to help us understand how Docker-Android is being used, the most common used features based on how, where and when people use it. With this information we can prioritize some features over other ones.
|
||||
|
||||
## What?
|
||||
Docker-Android's analytics record some shared information for every event:
|
||||
|
||||
- The Google Analytics version i.e. `1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v)
|
||||
- The Google Analytics anonymous IP setting is enabled i.e. `1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip)
|
||||
- The Docker-Android analytics tracking ID e.g. `UA-133466903-1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid)
|
||||
- The release version of machine, e.g. `Linux_version_4.4.16-boot2docker_(gcc_version_4.9.2_(Debian_4.9.2-10)_)_#1_SMP_Fri_Jul_29_00:13:24_UTC_2016` This does not allow us to track individual users but does enable us to accurately measure user counts vs. event counts (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid)
|
||||
- Docker-Android analytics hit type, e.g. `event` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t)
|
||||
- Application type, e.g. `Emulator` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ec)
|
||||
- Description will contains information about Emulator configuration, e.g. `Processor type`. (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#el)
|
||||
- Docker-Android application name, e.g. `docker-android` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an)
|
||||
- Docker-Android application version, e.g. `1.5-p0` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#av)
|
||||
|
||||
With the recorded information, it is not possible for us to match any particular real user.
|
||||
|
||||
As far as we can tell it would be impossible for Google to match the randomly generated analytics user ID to any other Google Analytics user ID. If Google turned evil the only thing they could do would be to lie about anonymising IP addresses and attempt to match users based on IP addresses.
|
||||
|
||||
## When/Where?
|
||||
Docker-Android's analytics are sent throughout Docker-Android's execution to Google Analytics over HTTPS.
|
||||
|
||||
## Who?
|
||||
Docker-Android's analytics are accessible to Docker-Android's current maintainers. Contact [@budtmo](https://github.com/budtmo) if you are a maintainer and need access.
|
||||
|
||||
## How?
|
||||
The code is viewable in [this script](./src/appium.sh).
|
||||
|
||||
## Opting out before starting Docker-Android
|
||||
Docker-Android analytics helps us, maintainers and leaving it on is appreciated. However, if you want to opt out and not send any information, you can do this by using passing environment variable GA=false to the Docker container.
|
||||
|
||||
## Disclaimer
|
||||
This document and the implementation are based on the great idea implemented by [Homebrew](https://github.com/Homebrew/brew/blob/master/docs/Analytics.md)
|
||||
30
LICENSE.md
@ -1,6 +1,6 @@
|
||||
## License Information
|
||||
|
||||
Copyright 2016 budi utomo
|
||||
Copyright 2023 budi utomo
|
||||
|
||||
This program is subject to the terms of the Apache License, Version 2.0 AND the following amendments on forks and data processing. Thus, this is a Custom Apache 2.0 License, NOT a dual-license model you may choose from.
|
||||
|
||||
@ -12,10 +12,10 @@ Unless required by applicable law or agreed to in writing, software distributed
|
||||
|
||||
|
||||
## Forks
|
||||
Additionally to Apache-2.0, when you fork this repo you are required to either remove our Google Analytics tracking ID: UA-133466903-1 or stop usage gathering completely.
|
||||
Additionally to Apache-2.0, when you fork this repo you are required to either remove our Google Form ID: 1FAIpQLSdrKWQdMh6Nt8v8NQdYvTIntohebAgqWCpXT3T9NofAoxcpkw or stop usage gathering completely.
|
||||
|
||||
## Data processing agreement
|
||||
By using this software you agree that the following non-PII (non personally identifiable information) data will be collected, processed and used by the maintainers for the purpose of improving the docker-android project. Anonymisation with respect of the IP address means that only the first two octets of the IP address are collected.
|
||||
By using this software you agree that the following non-PII (non personally identifiable information) data will be collected, processed and used by the maintainers for the purpose of improving the docker-android project.
|
||||
|
||||
|
||||
By using this software you also grant us a nonexclusive, irrevocable, world-wide, perpetual royalty-free permission to use, modify and publish these data for all purposes, internally or publicly, including the right to sub-license said permission rights.
|
||||
@ -23,14 +23,24 @@ By using this software you also grant us a nonexclusive, irrevocable, world-wide
|
||||
|
||||
We collect, process and use the following data:
|
||||
|
||||
* Release version of Docker-Android
|
||||
* Anonymized IP address (only first two octets)
|
||||
* Country and city
|
||||
* Date and time when Docker-Android started
|
||||
* User (it will collect the information about Release Version of Machine)
|
||||
* Application type, e.g. Emulator or Device or Genymotion
|
||||
* Emulator configuration, e.g. Processor type, Device name, Appium mode, Selenium grid mode and mobile test mode
|
||||
* User (it will collect the information about Release Version of Machine), e.g. Linux-5.4.0-146-generic-x86_64-with-glibc2.29_#163-Ubuntu_SMP_Fri_Mar_17_18:26:02_UTC_2023. This does not allow us to track individual users but does enable us to accurately measure user counts
|
||||
* City (the information come from https://ipinfo.io)
|
||||
* Region (the information come from https://ipinfo.io)
|
||||
* Country (the information come from https://ipinfo.io)
|
||||
* Release version of Docker-Android
|
||||
* Appium (Whether user use Appium or not - The possible value will be "true" or "false")
|
||||
* Appium Additional Arguments
|
||||
* Web-Log (Whether user use Web-Log feature or not - The possible value will be "true" or "false")
|
||||
* Web-Vnc (Whether user use Web-Vnc feature or not - The possible value will be "true" or "false")
|
||||
* Screen-Resolution
|
||||
* Device Type (Which docker image is used - The possible value will be "emulator" or "geny_cloud" or "geny_aws")
|
||||
* Emulator Device (Which device profile and skin is used if the user use device_type "emulator")
|
||||
* Emulator Android Version (Which Android version is used if the user use device_type "emulator"
|
||||
* Emulator No-Skin feature (Whether user use no-skin feature or not - The possible value will be "true" or "false")
|
||||
* Emulator Data Partition
|
||||
* Emulator Additional Arguments
|
||||
|
||||
## End of License Information
|
||||
|
||||
More information about anonymized data collection can be seen [here](Analytics.md)
|
||||
More information about anonymized data collection can be seen [here](./documentations/USER_BEHAVIOR_ANALYTICS.md)
|
||||
|
||||
289
README.md
@ -1,60 +1,32 @@
|
||||
|
||||
<p align="center">
|
||||
<img id="header" src="./images/logo_dockerandroid_small.png" />
|
||||
<img id="header" src="./images/logo_docker-android.png" />
|
||||
</p>
|
||||
|
||||
[](https://github.com/igrigorik/ga-beacon "Analytics")
|
||||
[](https://gitter.im/budtmo/docker-android?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://dev.azure.com/budtmoos/budtmoos/_build/latest?definitionId=7&branchName=master)
|
||||
[](https://codecov.io/gh/budtmo/docker-android)
|
||||
[](https://www.codacy.com/app/butomo1989/docker-appium?utm_source=github.com&utm_medium=referral&utm_content=butomo1989/docker-appium&utm_campaign=Badge_Grade)
|
||||
[](https://github.com/budtmo/docker-android/releases)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fbudtmo%2Fdocker-android?ref=badge_shield)
|
||||
[](http://paypal.me/budtmo)
|
||||
[](http://makeapullrequest.com)
|
||||
[](http://paypal.me/budtmo) [](http://makeapullrequest.com) [](https://gitter.im/budtmo/docker-android?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://codecov.io/gh/budtmo/docker-android) [](https://github.com/budtmo/docker-android/releases)
|
||||
|
||||
Docker-Android is a docker image built to be used for everything related to mobile website testing and Android project.
|
||||
Docker-Android is a docker image built to be used for everything related to Android. It can be used for Application development and testing (native, web and hybrid-app).
|
||||
|
||||
Emulator - Samsung Device | Emulator - Nexus Device | Real Device
|
||||
:---------------------------:|:---------------------------:|:---------------------------:
|
||||
![][emulator samsung] |![][emulator nexus] |![][real device]
|
||||
|
||||
Purposes
|
||||
--------
|
||||
|
||||
1. Run UI tests for mobile websites with [appium]
|
||||
2. Build Android project and run unit tests with the latest build-tools
|
||||
3. Run UI tests for Android applications with different frameworks ([appium], [espresso], [robotium], etc.)
|
||||
4. Run monkey / stress tests
|
||||
5. SMS testing
|
||||
|
||||
Advantages compare with other docker-android projects
|
||||
-----------------------------------------------------
|
||||
|
||||
1. noVNC to see what happen inside docker container
|
||||
2. Emulator for different devices / skins, such as Samsung Galaxy S6, LG Nexus 4, HTC Nexus One and more.
|
||||
3. Ability to connect to Selenium Grid
|
||||
Advantages of using this projects
|
||||
---------------------------------
|
||||
1. Emulator with different device profile and skins, such as Samsung Galaxy S6, LG Nexus 4, HTC Nexus One and more.
|
||||
2. Support vnc to be able to see what happen inside docker container
|
||||
3. Support log sharing feature where all logs can be accessed from web-UI
|
||||
4. Ability to control emulator from outside container by using adb connect
|
||||
5. Support real devices with screen mirroring
|
||||
6. Ability to record video during test execution for debugging
|
||||
7. Integrated with other cloud solutions, e.g. [Genymotion Cloud](https://www.genymotion.com/cloud/)
|
||||
8. Open source with more features coming
|
||||
5. Integrated with other cloud solutions, e.g. [Genymotion Cloud](https://www.genymotion.com/cloud/)
|
||||
6. It can be used to build Android project
|
||||
7. It can be used to run unit and UI-Test with different test-frameworks, e.g. Appium, Espresso, etc.
|
||||
|
||||
List of Docker images
|
||||
List of Docker-Images
|
||||
---------------------
|
||||
|
||||
|OS |Android |API |Browser |Browser version |Chromedriver |Image |Size |
|
||||
|:---|:---|:---|:---|:---|:---|:---|:---|
|
||||
|Linux|6.0|23|browser|44.0|2.18|budtmo/docker-android-x86-6.0|[](https://microbadger.com/images/budtmo/docker-android-x86-6.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|7.0|24|chrome|51.0|2.23|budtmo/docker-android-x86-7.0|[](https://microbadger.com/images/budtmo/docker-android-x86-7.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|7.1.1|25|chrome|55.0|2.28|budtmo/docker-android-x86-7.1.1|[](https://microbadger.com/images/budtmo/docker-android-x86-7.1.1 "Get your own image badge on microbadger.com")|
|
||||
|Linux|8.0|26|chrome|58.0|2.31|budtmo/docker-android-x86-8.0|[](https://microbadger.com/images/budtmo/docker-android-x86-8.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|8.1|27|chrome|61.0|2.33|budtmo/docker-android-x86-8.1|[](https://microbadger.com/images/budtmo/docker-android-x86-8.1 "Get your own image badge on microbadger.com")|
|
||||
|Linux|9.0|28|chrome|66.0|2.40|budtmo/docker-android-x86-9.0|[](https://microbadger.com/images/budtmo/docker-android-x86-9.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|10.0|29|chrome|74.0|74.0.3729.6|budtmo/docker-android-x86-10.0|[](https://microbadger.com/images/budtmo/docker-android-x86-10.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|11.0|30|chrome|83.0|83.0.4103.39|budtmo/docker-android-x86-11.0|[](https://microbadger.com/images/budtmo/docker-android-x86-11.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|12.0|31|chrome|93.0|93.0.4577.15|budtmo/docker-android-x86-12.0|[](https://microbadger.com/images/budtmo/docker-android-x86-12.0 "Get your own image badge on microbadger.com")|
|
||||
|All |-|-|-|-|-|budtmo/docker-android-real-device|[](https://microbadger.com/images/budtmo/docker-android-real-device "Get your own image badge on microbadger.com")|
|
||||
|All|All|All|All|All|All|budtmo/docker-android-genymotion|[](https://microbadger.com/images/budtmo/docker-android-genymotion "Get your own image badge on microbadger.com")|
|
||||
|Android |API |Image with latest release version |Image with specific release version|
|
||||
|:---|:---|:---|:---|
|
||||
|9.0|28|budtmo/docker-android:emulator_9.0|budtmo/docker-android:emulator_9.0_<release_version>|
|
||||
|10.0|29|budtmo/docker-android:emulator_10.0|budtmo/docker-android:emulator_10.0_<release_version>|
|
||||
|11.0|30|budtmo/docker-android:emulator_11.0|budtmo/docker-android:emulator_11.0_<release_version>|
|
||||
|12.0|32|budtmo/docker-android:emulator_12.0|budtmo/docker-android:emulator_12.0_<release_version>|
|
||||
|13.0|33|budtmo/docker-android:emulator_13.0|budtmo/docker-android:emulator_13.0_<release_version>|
|
||||
|-|-|budtmo/docker-android:genymotion|budtmo/docker-android:genymotion_<release_version>|
|
||||
|
||||
List of Devices
|
||||
---------------
|
||||
@ -76,162 +48,45 @@ Tablet | Nexus 7
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Docker is installed in your system.
|
||||
1. Docker is installed on your system.
|
||||
|
||||
Quick Start
|
||||
-----------
|
||||
|
||||
1. Your machine need to support virtualization. To check it:
|
||||
1. If you use ***Ubuntu OS*** on your host machine, you can skip this step. For ***OSX*** and ***Windows OS*** user, you need to use Virtual Machine that support Virtualization with Ubuntu OS because the image can be run under ***Ubuntu OS only***.
|
||||
|
||||
```
|
||||
sudo apt install cpu-checker
|
||||
kvm-ok
|
||||
```
|
||||
|
||||
2. Run Docker-Android
|
||||
|
||||
- For ***Linux OS***, please use image name that contains "x86"
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
- For ***OSX*** and ***Windows OS***, please use Virtual Machine that support Virtualization with Ubuntu OS
|
||||
|
||||
|
||||
3. Verify the ip address of docker host.
|
||||
|
||||
- For OSX, you can find out by using following command:
|
||||
|
||||
```bash
|
||||
docker-machine ip default
|
||||
```
|
||||
|
||||
- For different OS, localhost should work.
|
||||
|
||||
4. Open ***http://docker-host-ip-address:6080*** from web browser. Note: Adding ```?view_only=true``` will give user only view only permission.
|
||||
|
||||
Custom configurations
|
||||
---------------------
|
||||
|
||||
[This document](README_CUSTOM_CONFIG.md) contains custom configurations of Docker-Android that you might need, e.g. Proxy, Changing language on fly, etc.
|
||||
|
||||
Build Android project
|
||||
---------------------
|
||||
|
||||
Docker-Android can be used for building Android project and executing its unit test. This following steps will illustrate how to build Android project:
|
||||
|
||||
1. Clone [this sample test project](https://github.com/android/testing-samples).
|
||||
|
||||
```bash
|
||||
git clone git@github.com:android/testing-samples.git
|
||||
2. Your machine should support virtualization. To check if the virtualization is enabled is:
|
||||
```
|
||||
sudo apt install cpu-checker
|
||||
kvm-ok
|
||||
```
|
||||
|
||||
2. Build the project
|
||||
|
||||
```bash
|
||||
docker run -it --rm -v $PWD/testing-samples/ui/espresso/BasicSample:/tmp -w /tmp budtmo/docker-android-x86-8.1 /tmp/gradlew build
|
||||
3. Run Docker-Android container
|
||||
```
|
||||
docker run -d -p 6080:6080 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0
|
||||
```
|
||||
|
||||
Control Android connected to host (Emulator or Real Device)
|
||||
-----------------------------------------------------------
|
||||
1. Create a docker container with this command
|
||||
4. Open ***http://localhost:6080*** to see inside running container.
|
||||
|
||||
```
|
||||
$ docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 --name android-container-appium budtmo/docker-android-real-device
|
||||
```
|
||||
5. To check the status of the emulator
|
||||
```
|
||||
docker exec -it android-container cat device_status
|
||||
```
|
||||
|
||||
2. Open noVNC [http://localhost:6080](http://localhost:6080)
|
||||
Use-Cases
|
||||
---------
|
||||
|
||||
3. Open terminal by clicking right on **noVNC** window >> **Terminal emulator**
|
||||
1. [Build Android project](./documentations/USE_CASE_BUILD_ANDROID_PROJECT.md)
|
||||
2. [UI-Test with Appium](./documentations/USE_CASE_APPIUM.md)
|
||||
3. [Control Android emulator on host machine](./documentations/USE_CASE_CONTROL_EMULATOR.md)
|
||||
4. [SMS Simulation](./documentations/USE_CASE_SMS.md)
|
||||
5. [Jenkins](./documentations/USE_CASE_JENKINS.md)
|
||||
6. [Deploying on cloud (Azure, AWS, GCP)](./documentations/USE_CASE_CLOUD.md)
|
||||
|
||||
4. To connect to host's adb (make sure your host have adb and connected to the device.)
|
||||
Custom-Configurations
|
||||
---------------------
|
||||
|
||||
```
|
||||
$ adb -H host.docker.internal devices
|
||||
```
|
||||
|
||||
To specify port, just add `-P port_number`
|
||||
|
||||
```
|
||||
$ adb -H host.docker.internal -P 5037 devices
|
||||
```
|
||||
|
||||
5. Now your container can access your host devices. But, you need to add `remoteAdbHost` and `adbPort` desired capabilities to make **Appium** can recognise those devices.
|
||||
|
||||
|
||||
Appium and Selenium Grid
|
||||
------------------------
|
||||
|
||||
If you want to use Appium and Selenium Grid, you can follow [this document](README_APPIUM_AND_SELENIUM.md). It also contains sample and use cases.
|
||||
|
||||
Control android emulator outside container
|
||||
------------------------------------------
|
||||
|
||||
```bash
|
||||
adb connect <docker-machine-ip-address>:5555
|
||||
```
|
||||
|
||||
![][adb_connection]
|
||||
|
||||
**Note:** You need to have Android Debug Bridge (adb) installed in your host machine.
|
||||
|
||||
SMS Simulation
|
||||
--------------
|
||||
|
||||
1. Using telnet
|
||||
- Find the auth_token and copy it.
|
||||
|
||||
```bash
|
||||
docker exec -it android-container cat /root/.emulator_console_auth_token
|
||||
```
|
||||
|
||||
- Access emulator using telnet and login with auth_token
|
||||
|
||||
```bash
|
||||
telnet <docker-machine-ip-address> 5554
|
||||
```
|
||||
|
||||
- Login with given auth_token from 1.step
|
||||
|
||||
```bash
|
||||
auth <auth_token>
|
||||
```
|
||||
|
||||
- Send the sms
|
||||
|
||||
```bash
|
||||
sms send <phone_number> <message>
|
||||
```
|
||||
|
||||
2. Using adb
|
||||
|
||||
```bash
|
||||
docker exec -it android-container adb emu sms send <phone_number> <message>
|
||||
```
|
||||
|
||||
3. You can also integrate it inside project using adb library.
|
||||
|
||||
![][sms]
|
||||
|
||||
Google Play Services and Google Play Store
|
||||
------------------------------------------
|
||||
Not installed at this time.
|
||||
|
||||
Jenkins
|
||||
-------
|
||||
|
||||
This [document](README_JENKINS.md) gives you information about custom plugin that supports Docker-Android.
|
||||
|
||||
VMWARE
|
||||
------
|
||||
|
||||
This [document](README_VMWARE.md) shows you how to configure Virtual Machine on VMWARE to be able to run Docker-Android.
|
||||
|
||||
Cloud
|
||||
-----
|
||||
|
||||
This [document](README_CLOUD.md) contains information about deploying Docker-Android on cloud services.
|
||||
This [document](./documentations/CUSTOM_CONFIGURATIONS.md) contains information about configurations that can be used to enable some features, e.g. log-sharing, etc.
|
||||
|
||||
Genymotion
|
||||
----------
|
||||
@ -240,52 +95,34 @@ Genymotion
|
||||
<img id="geny" src="./images/logo_genymotion_and_dockerandroid.png" />
|
||||
</p>
|
||||
|
||||
For you who do not have ressources to maintain the simulator or to buy machines or need different device profiles, you need to give a try to [Genymotion Cloud](https://www.genymotion.com/cloud/). Docker-Android is integrated with Genymotion on different cloud services, e.g. Genymotion Cloud, AWS, GCP, Alibaba Cloud. Please follow [this document](README_GENYMOTION.md) or [this blog](https://medium.com/genymobile/run-your-appium-tests-using-docker-android-genymotion-cloud-e4817132ccd8) for more detail.
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
All logs inside container are stored under folder **/var/log/supervisor**. you can print out log file by using **docker exec**. Example:
|
||||
|
||||
```bash
|
||||
docker exec -it android-container tail -f /var/log/supervisor/docker-android.stdout.log
|
||||
```
|
||||
For you who do not have ressources to maintain the simulator or to buy machines or need different device profiles, you can give a try by using [Genymotion SAAS](https://cloud.geny.io/). Docker-Android is [integrated with Genymotion](https://www.genymotion.com/blog/partner_tag/docker/) on different cloud services, e.g. Genymotion SAAS, AWS, GCP, Alibaba Cloud. Please follow [this document](./documentations/THIRD_PARTY_GENYMOTION.md) for more detail.
|
||||
|
||||
Emulator Skins
|
||||
--------------
|
||||
The Emulator skins are taken from [Android Studio IDE](https://developer.android.com/studio) and [Samsung Developer Website](https://developer.samsung.com/)
|
||||
|
||||
|
||||
Monitoring
|
||||
----------
|
||||
You can use [cadvisor](https://github.com/google/cadvisor) combined with influxdb / prometheus and grafana if needed to monitor each running container.
|
||||
PRO VERSION
|
||||
-----------
|
||||
|
||||
Users
|
||||
-----
|
||||
Docker-Android are being used by 100+ countries around the world.
|
||||
Due to high requests for help and to be able to actively maintain the projects, the creator has decided to create docker-android-pro. Docker-Android-Pro is a sponsor based project which mean that the docker image of pro-version can be pulled only by [active sponsor](https://github.com/sponsors/budtmo).
|
||||
|
||||
[](https://datastudio.google.com/s/ht7HVKHKAQE)
|
||||
The differences between normal version and pro version are:
|
||||
|
||||
Stargazers over time
|
||||
--------------------
|
||||
|Feature |Normal |Pro |Comment|
|
||||
|:---|:---|:---|:---|
|
||||
|user-behavior-analytics|Yes|No|-|
|
||||
|proxy|No|Yes|Set up company proxy on Android emulator on fly|
|
||||
|language|No|Yes|Set up language on Android emulator on fly|
|
||||
|root-privileged|No|Yes|Able to run command with security privileged|
|
||||
|headless-mode|No|Yes|Save resources by using headless mode|
|
||||
|multiple Android-Simulators|No|Yes (soon)|Save resources by having multiple Android-Simulators on one docker-container|
|
||||
|Google Play Store|No|Yes (soon)|-|
|
||||
|Video Recording|No|Yes (soon)|Helpful for debugging|
|
||||
|
||||
[](https://starchart.cc/budtmo/docker-android)
|
||||
This [document](./documentations/DOCKER-ANDROID-PRO.md) contains detail information about how to use docker-android-pro.
|
||||
|
||||
Special Thanks
|
||||
--------------
|
||||
- [Gian Christanto] for creating a great logo!
|
||||
|
||||
LICENSE
|
||||
--------------
|
||||
-------
|
||||
See [License](LICENSE.md)
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fbudtmo%2Fdocker-android?ref=badge_large)
|
||||
|
||||
[appium]: <https://appium.io>
|
||||
[espresso]: <https://developer.android.com/training/testing/espresso/>
|
||||
[robotium]: <https://github.com/RobotiumTech/robotium>
|
||||
[emulator samsung]: <images/emulator_samsung_galaxy_s6.png>
|
||||
[emulator nexus]: <images/emulator_nexus_5.png>
|
||||
[real device]: <images/real_device.png>
|
||||
[adb_connection]: <images/adb_connection.png>
|
||||
[sms]: <images/SMS.png>
|
||||
[gian christanto]: <https://www.linkedin.com/in/gian-christanto-0b398b131/>
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
Run Appium Server
|
||||
-----------------
|
||||
|
||||
Appium is automation test framework to test mobile website and mobile application, including Android. To be able to use Appium, you need to run appium-server. You run Appium-Server inside docker-android container by ***opening port 4723*** and ***passing an environment variable APPIUM=true***.
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 -e DEVICE="Samsung Galaxy S6" -e APPIUM=true --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
### Share Volume
|
||||
|
||||
If you want to use appium to test UI of your android application, you need to share volume where the APK is located to folder ***/root/tmp***.
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -v $PWD/example/sample_apk:/root/tmp -e DEVICE="Nexus 5" -e APPIUM=true -e CONNECT_TO_GRID=true -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
### Connect to Selenium Grid
|
||||
|
||||
It is also possible to connect appium server that run inside docker-android with selenium grid by passing following environment variables:
|
||||
|
||||
- CONNECT\_TO\_GRID=true
|
||||
- APPIUM_HOST="\<host\_ip\_address>"
|
||||
- APPIUM_PORT=\<port\_number>
|
||||
- SELENIUM_HOST="\<host\_ip\_address>"
|
||||
- SELENIUM_PORT=\<port\_number>
|
||||
- SELENIUM_TIMEOUT=\<timeout\_in\_seconds>
|
||||
- SELENIUM_PROXY_CLASS=\<selenium\_proxy\_class\_name>
|
||||
|
||||
To run tests for mobile browser, following parameter can be passed:
|
||||
|
||||
- MOBILE\_WEB\_TEST=true
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e APPIUM=true -e CONNECT_TO_GRID=true -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 -e MOBILE_WEB_TEST=true --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
### Video Recording
|
||||
|
||||
You can deactivate auto_record by changing the value to "False" in docker-compose file. e.g. change value to "False" in this [line](docker-compose.yml#L70).
|
||||
|
||||
### Relaxed Security
|
||||
|
||||
Pass environment variable RELAXED_SECURITY=true to disable additional security check to use some advanced features.
|
||||
|
||||
### Docker-Compose
|
||||
|
||||
![][compose]
|
||||
|
||||
There is [example of compose file](docker-compose.yml) to run complete selenium grid and docker-android container as nodes. [docker-compose](https://docs.docker.com/compose/install/) version [1.13.0](https://github.com/docker/compose/releases/tag/1.13.0) or higher is required to be able to execute that compose file.
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
[compose]: <images/compose.png>
|
||||
@ -1,88 +0,0 @@
|
||||
VNC pass
|
||||
--------
|
||||
|
||||
Passing ```VNC_PASSWORD="your_pass_here"``` will secure your vnc connection.
|
||||
|
||||
Proxy
|
||||
-----
|
||||
|
||||
You can enable proxy inside container and Android emulator by passing following environment variables:
|
||||
|
||||
- HTTP_PROXY="http://\<docker\_bridge\_ip>:<port>"
|
||||
- HTTPS_PROXY=""http://\<docker\_bridge\_ip>:<port>"
|
||||
- NO_PROXY="localhost"
|
||||
- ENABLE_PROXY_ON_EMULATOR=true
|
||||
|
||||
Proxy with authentication
|
||||
----
|
||||
|
||||
You can set proxy with authentication by passing following environment variable:
|
||||
|
||||
- HTTP_PROXY_USER="\<username>"
|
||||
- HTTP_PROXY_PASSWORD="\<password>"
|
||||
|
||||
|
||||
Language
|
||||
--------
|
||||
|
||||
You can change the language setting of Android Emulator on the fly by passing following environment variable:
|
||||
|
||||
- LANGUAGE="\<language>"
|
||||
- COUNTRY="\<country>"
|
||||
|
||||
Data partition size
|
||||
-------------------
|
||||
|
||||
The size of the data partition can be set by passing the following environment variable:
|
||||
|
||||
- DATAPARTITION="\<size>"
|
||||
|
||||
The value can be specified in the same format that is used by the emulator config file (`disk.dataPartition.size`), e.g. `800m`.
|
||||
|
||||
Camera
|
||||
------
|
||||
|
||||
Passing following environment variable to be able to connect laptop / pc camera to Android emulator:
|
||||
|
||||
- EMULATOR_ARGS="-camera-back webcam0"
|
||||
|
||||
Custom Avd name Arguments
|
||||
-------------------------
|
||||
|
||||
Passing following environment variable to set a custom avd name
|
||||
|
||||
- AVD_NAME="customName"
|
||||
|
||||
|
||||
Custom Emulator Arguments
|
||||
-------------------------
|
||||
|
||||
If you want to add more arguments for running emulator, you can ***pass an environment variable EMULATOR_ARGS*** while running docker command.
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e EMULATOR_ARGS="-no-snapshot-load -partition-size 512" --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
SaltStack
|
||||
---------
|
||||
|
||||
You can enable [SaltStack](https://github.com/saltstack/salt) to control running containers by passing environment variable SALT_MASTER=<ip_address_of_salt_master>.
|
||||
|
||||
Back & Restore
|
||||
--------------
|
||||
|
||||
If you want to backup/reuse the avds created with furture upgrades or for replication, run the container with two extra mounts
|
||||
|
||||
- -v local_backup/.android:/root/.android
|
||||
- -v local_backup/android_emulator:/root/android_emulator
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -v local_backup/.android:/root/.android -v local_backup/android_emulator:/root/android_emulator -e DEVICE="Nexus 5" --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
For the first run, this will create a new avd and all the changes will be accessible in the `local_backup` directory. Now for all future runs, it will reuse the avds. Even this should work with new releases of `docker-android`
|
||||
|
||||
Nginx
|
||||
-----
|
||||
|
||||
Sample nginx configuration can be found [here](nginx)
|
||||
@ -1,41 +0,0 @@
|
||||
Genymotion Cloud
|
||||
----------------
|
||||
|
||||

|
||||
|
||||
You can easily scale your Appium tests on Genymotion Android virtual devices in the cloud. They are available on [SaaS](http://bit.ly/2YP0P1l) or as virtual images on AWS, GCP or Alibaba Cloud.
|
||||
|
||||
1. On SaaS <br />
|
||||
Use [device.json](genymotion/example/sample_devices/devices.json) to define the device to start. You can specify the port on which the device will start so you don't need to change the device name in your tests every time you need to run those tests. Then run following command
|
||||
|
||||
```bash
|
||||
export USER="xxx"
|
||||
export PASS="xxx"
|
||||
|
||||
docker run -it --rm -p 4723:4723 -v $PWD/genymotion/example/sample_devices:/root/tmp -e TYPE=SaaS -e USER=$USER -e PASS=$PASS budtmo/docker-android-genymotion
|
||||
```
|
||||
|
||||
In case you are interesed to play around with Genymotion on SaaS, you can register to [this link](http://bit.ly/2YP0P1l) to get 1000 free minutes for free.
|
||||
|
||||
2. On PaaS (AWS) <br />
|
||||
Use [aws.json](genymotion/example/sample_devices/aws.json) to define configuration of EC2 instance and run following command:
|
||||
|
||||
```bash
|
||||
docker run -it --rm -p 4723:4723 -v $PWD/genymotion/example/sample_devices:/root/tmp -v ~/.aws:/root/.aws -e TYPE=aws budtmo/docker-android-genymotion
|
||||
```
|
||||
|
||||
Existing security group and subnet can be used:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"region": "us-west-2",
|
||||
"instance": "t2.small",
|
||||
"AMI": "ami-0673cbd39ef84d97c",
|
||||
"SG": "sg-000aaa",
|
||||
"subnet_id": "subnet-000aaa"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
You can also use [this docker-compose file](genymotion/example/geny.yml).
|
||||
@ -1,85 +0,0 @@
|
||||
VMWare Fusion on OSX
|
||||
--------------------
|
||||
|
||||
The following instructions are used for OS X. You'll need [docker-machine-parallels](https://github.com/Parallels/docker-machine-parallels) to create a virtual machine (vm) with tiny core linux for running docker images. After that, you may start the vm you created for VMWare Fusion or Parallels Desktop and run a docker container inside this vm. If you're going to use the android docker of emulator with x86 processor, setup this vm for nested virtualization and kvm support before you run a docker container.
|
||||
|
||||
1. Install docker-machine-parallels via Homebrew:
|
||||
```bash
|
||||
$ brew install docker-machine-parallels
|
||||
```
|
||||
|
||||
2. Create a virtual machine for running docker images based on the virtual machine tool you use
|
||||
|
||||
2.1. Create a virtual machine of VMWare Fusion
|
||||
```bash
|
||||
$ docker-machine create --driver=vmwarefusion vmware-dev
|
||||
```
|
||||
|
||||
2.2. Create a virtual machine of Parallels Desktop
|
||||
```bash
|
||||
$ docker-machine create --driver=parallels prl-dev
|
||||
```
|
||||
|
||||
This utility `docker-machine-parallels` will fetch boot2docker.iso to create a vm of VMWare fusion or Parallels Desktop. When the vm is created, you'll see it's booted with VMWare fusion or Parallels Desktop where the network of vm is set to NAT and one IP is assigned. You'll be able to connect to vnc service inside the docker image through that IP. Say it's `10.211.55.3` and we'll use it later.
|
||||
|
||||
3. Setup the virtual machine for nested virtualization support
|
||||
|
||||
3.1. Shutdown the vm by running the command below in the boot2docker vm before you setup it.
|
||||
```bash
|
||||
# shutdown -h now
|
||||
```
|
||||
|
||||
If you use VMWare Fusion, go to menu bar > Vitual Machine > Settings > Processors and Memory, expand Advanced options, and select `Enable hypervisor applications in this virtual machine`.
|
||||
|
||||

|
||||
|
||||
If you use Parallels Desktop, open settings screen of that vm and go to `CPU & Memory` under `hardware` tab, expand Advanced settings and select `Enable nested virtualization`.
|
||||
|
||||

|
||||
|
||||
4. Enable kvm inside virtual machine
|
||||
|
||||
4.0 SSH to the machine
|
||||
```bash
|
||||
docker-machine ssh vmware-dev
|
||||
```
|
||||
|
||||
4.1 Check kvm version
|
||||
```bash
|
||||
# version
|
||||
$ 10.1
|
||||
```
|
||||
|
||||
Go to http://tinycorelinux.net/10.x/x86_64/tcz/ and check your kvm version, for version 10.1 is kvm-4.19.10-tinycore64.tcz
|
||||
|
||||
4.2. Run as an account other than root to install kvm packages using tce-load.
|
||||
```bash
|
||||
# su docker
|
||||
$ tce-load -wi kvm-4.19.10-tinycore64.tcz
|
||||
```
|
||||
|
||||
4.3. Run as root to load kvm module after kvm packages install.
|
||||
```bash
|
||||
$ sudo modprobe kvm_intel
|
||||
```
|
||||
|
||||
4.4. Check if the kvm device is loaded.
|
||||
```bash
|
||||
$ ls /dev/kvm
|
||||
```
|
||||
|
||||
4.5. Check if your CPU supports hardware virtualization now
|
||||
```bash
|
||||
$ egrep -c '(vmx|svm)' /proc/cpuinfo
|
||||
```
|
||||
|
||||
If **0** it means that your CPU doesn't support hardware virtualization.
|
||||
If **1** or more it does - but you still need to make sure that virtualization is enabled in the BIOS.
|
||||
|
||||
5. You may now run a docker container
|
||||
5.1. Let's run a docker image for an emulator with x86 processor.
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" --name android-container budtmo/docker-android-x86-8.1
|
||||
```
|
||||
|
||||
When the services inside this docker container are running, connect to http://10.211.55.3:6080/vnc.html (the IP we got when the docker machine was created) and login. The emulator with x86 processor should be running on screen.
|
||||
@ -1,86 +0,0 @@
|
||||
# Kubernetes & Azure (AKS, Terraform, Kompose, Kubectl, Azure CLI)
|
||||
|
||||
- Azure CLI configuration
|
||||
- Infrastructure as code for Azure
|
||||
- Generating Kubernetes configuration files with Kompose (Services, Deployments, Pods & Persistent volumes)
|
||||
- Terraform with Azure Provider
|
||||
- Kubectl configuration
|
||||
|
||||
## Setting up Azure CLI
|
||||
|
||||
- Install Azure CLI -> https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
|
||||
- Execute ```sh $ az login ``` and authenticate with your Azure account
|
||||
- Execute ```sh $ az account show --query "{subscriptionId:id, tenantId:tenantId" ``` . Then copy subscriptionId and tenantId
|
||||
- Execute ```sh $ az account set --subscription="${SUBSCRIPTION_ID}" ``` . Replace ${SUBSCRIPTION_ID} for your subscriptionId copied
|
||||
|
||||
## Create infrastucture in Azure (AKS Service with node master)
|
||||
|
||||
Terraform version >= v0.11.7
|
||||
|
||||
- Install Terraform -> https://www.terraform.io/downloads.html
|
||||
- Edit vars with Azure Account values in ```sh terraform.tfvars ```
|
||||
- After that:
|
||||
|
||||
```sh
|
||||
$ terraform init
|
||||
$ terraform plan
|
||||
$ terraform apply
|
||||
```
|
||||
|
||||
## Setting up Kubectl with Azure account
|
||||
|
||||
- For apply Kubernetes files:
|
||||
|
||||
First configurate azure-cli with Azure account and install kubernetes tools with az:
|
||||
|
||||
```sh
|
||||
$ az aks install-cli
|
||||
```
|
||||
|
||||
Then log in in to the Azure Container Registry (if you're using it, but dockerhub or other):
|
||||
|
||||
```sh
|
||||
$ az acr login
|
||||
```
|
||||
|
||||
After that, connect to cluster with Kubectl:
|
||||
|
||||
```sh
|
||||
$ az aks get-credentials --resource-group docker-android --name k8s-docker-android
|
||||
```
|
||||
|
||||
## Running with custom K8s files (Recommended)
|
||||
|
||||
- You can use this approach or Kompose (Next 2 steps)
|
||||
|
||||
```sh
|
||||
$ kubectl create -f volumes.yaml
|
||||
$ kubectl create -f services_deployments.yaml
|
||||
```
|
||||
|
||||
## Generate Kube files with Kompose
|
||||
|
||||
- Install Kompose -> https://github.com/kubernetes/kompose
|
||||
|
||||
Kompose version: >= 1.1.0
|
||||
|
||||
- For convert to Kompose:
|
||||
|
||||
```sh
|
||||
$ cd kompose
|
||||
$ kompose convert -f ../kompose.yml
|
||||
```
|
||||
|
||||
## Execute Kube files (Kompose)
|
||||
|
||||
- First create Persistent Volume Claims, then Services; finally Deployments files. For example:
|
||||
|
||||
```sh
|
||||
$ cd kompose
|
||||
$ kubectl create -f nexus-7.1.1-claim0-persistentvolumeclaim.yaml
|
||||
$ kubectl create -f nexus-7.1.1-claim1-persistentvolumeclaim.yaml
|
||||
$ kubectl create -f nexus-7.1.1-service.yaml
|
||||
$ kubectl create -f nexus-7.1.1-deployment.yaml
|
||||
```
|
||||
|
||||
|
||||
@ -1,114 +0,0 @@
|
||||
# Note: It requires docker-compose 1.13.0
|
||||
#
|
||||
# Usage: docker-compose up -d
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
# Selenium hub
|
||||
selenium_hub:
|
||||
image: selenium/hub:3.14.0-curium
|
||||
ports:
|
||||
- 4444:4444
|
||||
|
||||
# There is a bug for using appium. Issue: https://github.com/butomo1989/docker-android/issues/73
|
||||
# Real devices
|
||||
#real_device:
|
||||
# image: butomo1989/docker-android-real-device
|
||||
# privileged: true
|
||||
# depends_on:
|
||||
# - selenium_hub
|
||||
# ports:
|
||||
# - 6080:6080
|
||||
# volumes:
|
||||
# - ./video-real-device:/tmp/video
|
||||
# - /dev/bus/usb:/dev/bus/usb
|
||||
# - ~/.android:/root/.android
|
||||
# environment:
|
||||
# - CONNECT_TO_GRID=true
|
||||
# - APPIUM=true
|
||||
# - SELENIUM_HOST=selenium_hub
|
||||
# - AUTO_RECORD=true
|
||||
# - BROWSER_NAME=chrome
|
||||
|
||||
# Using Appium Docker Android
|
||||
real_device:
|
||||
image: appium/appium
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
network_mode: "service:selenium_hub"
|
||||
privileged: true
|
||||
volumes:
|
||||
- /dev/bus/usb:/dev/bus/usb
|
||||
- ~/.android:/root/.android
|
||||
- ../example/sample_apk:/root/tmp
|
||||
environment:
|
||||
- CONNECT_TO_GRID=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
# Enable it for msite testing
|
||||
#- BROWSER_NAME=chrome
|
||||
|
||||
# Docker-Android for Android application testing
|
||||
nexus_7.1.1:
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
#scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
# Change path of apk that you want to test. I use sample_apk that I provide in folder "example"
|
||||
volumes:
|
||||
- ../example/sample_apk:/root/tmp/sample_apk
|
||||
- ../video-nexus_7.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Nexus 5
|
||||
- CONNECT_TO_GRID=true
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- AUTO_RECORD=true
|
||||
|
||||
# Docker-Android for mobile website testing with chrome browser
|
||||
# Chrome browser exists only for version 7.0 and 7.1.1
|
||||
samsung_galaxy_web_7.1.1:
|
||||
image: butomo1989/docker-android-x86-8.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
#scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
volumes:
|
||||
- ../video-samsung_7.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=true
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=true
|
||||
- AUTO_RECORD=true
|
||||
|
||||
# Docker-Android for mobile website testing with default browser
|
||||
# Default browser exists only for version 5.0.1, 5.1.1 and 6.0
|
||||
samsung_galaxy_web_5.1.1:
|
||||
image: butomo1989/docker-android-x86-5.1.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
#scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
volumes:
|
||||
- ../video-samsung_5.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=true
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=true
|
||||
- AUTO_RECORD=true
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: nexus-7.1.1-claim0
|
||||
name: nexus-7.1.1-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: nexus-7.1.1-claim1
|
||||
name: nexus-7.1.1-claim1
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,53 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: nexus-7.1.1
|
||||
name: nexus-7.1.1
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: nexus-7.1.1
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: APPIUM
|
||||
value: "true"
|
||||
- name: AUTO_RECORD
|
||||
value: "true"
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: DEVICE
|
||||
value: Nexus 5
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
name: nexus-7.1.1
|
||||
ports:
|
||||
- containerPort: 6080
|
||||
resources: {}
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /root/tmp/sample_apk
|
||||
name: nexus-7.1.1-claim0
|
||||
- mountPath: /tmp/video
|
||||
name: nexus-7.1.1-claim1
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: nexus-7.1.1-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: nexus-7.1.1-claim0
|
||||
- name: nexus-7.1.1-claim1
|
||||
persistentVolumeClaim:
|
||||
claimName: nexus-7.1.1-claim1
|
||||
status: {}
|
||||
@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: nexus-7.1.1
|
||||
name: nexus-7.1.1
|
||||
spec:
|
||||
ports:
|
||||
- name: "6080"
|
||||
port: 6080
|
||||
targetPort: 6080
|
||||
selector:
|
||||
io.kompose.service: nexus-7.1.1
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device-claim0
|
||||
name: real-device-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device-claim1
|
||||
name: real-device-claim1
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device-claim2
|
||||
name: real-device-claim2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,50 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device
|
||||
name: real-device
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: appium/appium
|
||||
name: real-device
|
||||
resources: {}
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /dev/bus/usb
|
||||
name: real-device-claim0
|
||||
- mountPath: /root/.android
|
||||
name: real-device-claim1
|
||||
- mountPath: /root/tmp
|
||||
name: real-device-claim2
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: real-device-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim0
|
||||
- name: real-device-claim1
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim1
|
||||
- name: real-device-claim2
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim2
|
||||
status: {}
|
||||
@ -1,20 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: real-device
|
||||
name: real-device
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
- name: headless
|
||||
port: 55555
|
||||
targetPort: 0
|
||||
selector:
|
||||
io.kompose.service: real-device
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-5.1.1-claim0
|
||||
name: samsung-galaxy-web-5.1.1-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,50 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-5.1.1
|
||||
name: samsung-galaxy-web-5.1.1
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-5.1.1
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: APPIUM
|
||||
value: "true"
|
||||
- name: AUTO_RECORD
|
||||
value: "true"
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: DEVICE
|
||||
value: Samsung Galaxy S6
|
||||
- name: MOBILE_WEB_TEST
|
||||
value: "true"
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: butomo1989/docker-android-x86-5.1.1
|
||||
name: samsung-galaxy-web-5.1.1
|
||||
ports:
|
||||
- containerPort: 6080
|
||||
resources: {}
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/video
|
||||
name: samsung-galaxy-web-5.1.1-claim0
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: samsung-galaxy-web-5.1.1-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: samsung-galaxy-web-5.1.1-claim0
|
||||
status: {}
|
||||
@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-5.1.1
|
||||
name: samsung-galaxy-web-5.1.1
|
||||
spec:
|
||||
ports:
|
||||
- name: "6080"
|
||||
port: 6080
|
||||
targetPort: 6080
|
||||
selector:
|
||||
io.kompose.service: samsung-galaxy-web-5.1.1
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-7.1.1-claim0
|
||||
name: samsung-galaxy-web-7.1.1-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
status: {}
|
||||
@ -1,50 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-7.1.1
|
||||
name: samsung-galaxy-web-7.1.1
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-7.1.1
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: APPIUM
|
||||
value: "true"
|
||||
- name: AUTO_RECORD
|
||||
value: "true"
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: DEVICE
|
||||
value: Samsung Galaxy S6
|
||||
- name: MOBILE_WEB_TEST
|
||||
value: "true"
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: butomo1989/docker-android-x86-8.1
|
||||
name: samsung-galaxy-web-7.1.1
|
||||
ports:
|
||||
- containerPort: 6080
|
||||
resources: {}
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/video
|
||||
name: samsung-galaxy-web-7.1.1-claim0
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: samsung-galaxy-web-7.1.1-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: samsung-galaxy-web-7.1.1-claim0
|
||||
status: {}
|
||||
@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: samsung-galaxy-web-7.1.1
|
||||
name: samsung-galaxy-web-7.1.1
|
||||
spec:
|
||||
ports:
|
||||
- name: "6080"
|
||||
port: 6080
|
||||
targetPort: 6080
|
||||
selector:
|
||||
io.kompose.service: samsung-galaxy-web-7.1.1
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@ -1,27 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: selenium-hub
|
||||
name: selenium-hub
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy: {}
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: selenium-hub
|
||||
spec:
|
||||
containers:
|
||||
- image: selenium/hub:3.14.0-curium
|
||||
name: selenium-hub
|
||||
ports:
|
||||
- containerPort: 4444
|
||||
resources: {}
|
||||
restartPolicy: Always
|
||||
status: {}
|
||||
@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
kompose.cmd: kompose convert -f ../kompose.yml
|
||||
kompose.version: 1.1.0 (36652f6)
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: selenium-hub
|
||||
name: selenium-hub
|
||||
spec:
|
||||
ports:
|
||||
- name: "4444"
|
||||
port: 4444
|
||||
targetPort: 4444
|
||||
selector:
|
||||
io.kompose.service: selenium-hub
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@ -1,48 +0,0 @@
|
||||
|
||||
resource "azurerm_container_service" "container_service" {
|
||||
name = "k8s-docker-android"
|
||||
resource_group_name = "${var.resource_group_name}"
|
||||
location = "${var.resource_group_location}"
|
||||
orchestration_platform = "Kubernetes"
|
||||
|
||||
master_profile {
|
||||
count = "${var.master_count}"
|
||||
dns_prefix = "${var.dns_name_prefix}-master"
|
||||
}
|
||||
|
||||
agent_pool_profile {
|
||||
name = "agentpools"
|
||||
count = "${var.linux_agent_count}"
|
||||
dns_prefix = "${var.dns_name_prefix}-agent"
|
||||
vm_size = "${var.linux_agent_vm_size}"
|
||||
}
|
||||
|
||||
linux_profile {
|
||||
admin_username = "${var.linux_admin_username}"
|
||||
|
||||
ssh_key {
|
||||
key_data = "${var.linux_admin_ssh_publickey}"
|
||||
}
|
||||
}
|
||||
|
||||
service_principal {
|
||||
client_id = "${var.service_principal_client_id}"
|
||||
client_secret = "${var.service_principal_client_secret}"
|
||||
}
|
||||
|
||||
diagnostics_profile {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
tags {
|
||||
Source = "K8s with Terraform"
|
||||
}
|
||||
}
|
||||
|
||||
output "master_fqdn" {
|
||||
value = "${azurerm_container_service.container_service.master_profile.fqdn}"
|
||||
}
|
||||
|
||||
output "ssh_command_master0" {
|
||||
value = "ssh ${var.linux_admin_username}@${azurerm_container_service.container_service.master_profile.fqdn} -A -p 22"
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
|
||||
# Use this if you can't specify your credentials in file but you need ingress in the UI console.
|
||||
provider "azurerm" {}
|
||||
|
||||
#Use this if you can specify your credentials and no more configuration is necessary
|
||||
#provider "azurerm" {
|
||||
# subscription_id = "${var.subscription_id}"
|
||||
# client_id = "${var.service_principal_client_id}"
|
||||
# client_secret = "${var.service_principal_client_secret}"
|
||||
# tenant_id = "${var.tenant_id}"
|
||||
#}
|
||||
@ -1,147 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: selenium
|
||||
spec:
|
||||
ports:
|
||||
- name: "4444"
|
||||
port: 4444
|
||||
targetPort: 4444
|
||||
selector:
|
||||
app: selenium
|
||||
type: LoadBalancer
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: selenium-deployment
|
||||
labels:
|
||||
app: selenium
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: selenium
|
||||
spec:
|
||||
containers:
|
||||
- image: selenium/hub:3.14.0-curium
|
||||
name: selenium-hub
|
||||
ports:
|
||||
- containerPort: 4444
|
||||
resources: {}
|
||||
restartPolicy: Always
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: real-device
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
- name: headless
|
||||
port: 55555
|
||||
targetPort: 0
|
||||
selector:
|
||||
app: real-device
|
||||
type: LoadBalancer
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: real-device
|
||||
name: real-device
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: real-device
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: appium/appium
|
||||
name: real-device
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /dev/bus/usb
|
||||
name: real-device-claim0
|
||||
- mountPath: /root/.android
|
||||
name: real-device-claim1
|
||||
- mountPath: /root/tmp
|
||||
name: real-device-claim2
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: real-device-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim0
|
||||
- name: real-device-claim1
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim1
|
||||
- name: real-device-claim2
|
||||
persistentVolumeClaim:
|
||||
claimName: real-device-claim2
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nexus-7.1.1
|
||||
spec:
|
||||
ports:
|
||||
- name: "6080"
|
||||
port: 6080
|
||||
targetPort: 6080
|
||||
selector:
|
||||
app: nexus-7.1.1
|
||||
type: LoadBalancer
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nexus-7.1.1
|
||||
name: nexus-7.1.1
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nexus-7.1.1
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: APPIUM
|
||||
value: "true"
|
||||
- name: AUTO_RECORD
|
||||
value: "true"
|
||||
- name: CONNECT_TO_GRID
|
||||
value: "true"
|
||||
- name: DEVICE
|
||||
value: Nexus 5
|
||||
- name: SELENIUM_HOST
|
||||
value: selenium_hub
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
name: nexus-7.1.1
|
||||
ports:
|
||||
- containerPort: 6080
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- mountPath: /root/tmp/sample_apk
|
||||
name: nexus-7.1.1-claim0
|
||||
- mountPath: /tmp/video
|
||||
name: nexus-7.1.1-claim1
|
||||
restartPolicy: Always
|
||||
volumes:
|
||||
- name: nexus-7.1.1-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: nexus-7.1.1-claim0
|
||||
- name: nexus-7.1.1-claim1
|
||||
persistentVolumeClaim:
|
||||
claimName: nexus-7.1.1-claim1
|
||||
@ -1,19 +0,0 @@
|
||||
|
||||
resource_group_name = "docker-android"
|
||||
resource_group_location = "West US"
|
||||
dns_name_prefix = "docker-android"
|
||||
linux_agent_count = "1"
|
||||
|
||||
#Only use Dv3 or Ev3 series
|
||||
linux_agent_vm_size = "Standard_D2_v3"
|
||||
|
||||
linux_admin_username = "(Insert any username here!)"
|
||||
linux_admin_ssh_publickey = "(Insert ssh key here!)"
|
||||
master_count = "1"
|
||||
|
||||
|
||||
# Azure credentials
|
||||
service_principal_client_id = "(Insert principal key client id here!)"
|
||||
service_principal_client_secret = "(Insert principal key client secret here!)"
|
||||
subscription_id = "(Insert subscription id here!)"
|
||||
tenant_id = "(Insert tenant id here!)"
|
||||
@ -1,62 +0,0 @@
|
||||
variable "resource_group_name" {
|
||||
type = "string"
|
||||
description = "Name of the azure resource group."
|
||||
}
|
||||
|
||||
variable "resource_group_location" {
|
||||
type = "string"
|
||||
description = "Location of the azure resource group."
|
||||
}
|
||||
|
||||
variable "dns_name_prefix" {
|
||||
type = "string"
|
||||
description = "Sets the domain name prefix for the cluster. The suffix 'master' will be added to address the master agents and the suffix 'agent' will be added to address the linux agents."
|
||||
}
|
||||
|
||||
variable "linux_agent_count" {
|
||||
type = "string"
|
||||
default = "1"
|
||||
description = "The number of Kubernetes linux agents in the cluster. Allowed values are 1-100 (inclusive). The default value is 1."
|
||||
}
|
||||
|
||||
variable "linux_agent_vm_size" {
|
||||
type = "string"
|
||||
default = "Standard_D2_v2"
|
||||
description = "The size of the virtual machine used for the Kubernetes linux agents in the cluster."
|
||||
}
|
||||
|
||||
variable "linux_admin_username" {
|
||||
type = "string"
|
||||
description = "User name for authentication to the Kubernetes linux agent virtual machines in the cluster."
|
||||
}
|
||||
|
||||
variable "linux_admin_ssh_publickey" {
|
||||
type = "string"
|
||||
description = "Configure all the linux virtual machines in the cluster with the SSH RSA public key string. The key should include three parts, for example 'ssh-rsa AAAAB...snip...UcyupgH azureuser@linuxvm'"
|
||||
}
|
||||
|
||||
variable "master_count" {
|
||||
type = "string"
|
||||
default = "1"
|
||||
description = "The number of Kubernetes masters for the cluster. Allowed values are 1, 3, and 5. The default value is 1."
|
||||
}
|
||||
|
||||
variable "service_principal_client_id" {
|
||||
type = "string"
|
||||
description = "The client id of the azure service principal used by Kubernetes to interact with Azure APIs."
|
||||
}
|
||||
|
||||
variable "service_principal_client_secret" {
|
||||
type = "string"
|
||||
description = "The client secret of the azure service principal used by Kubernetes to interact with Azure APIs."
|
||||
}
|
||||
|
||||
variable "subscription_id" {
|
||||
type = "string"
|
||||
description = "Your Azure subscription"
|
||||
}
|
||||
|
||||
variable "tenant_id" {
|
||||
type = "string"
|
||||
description = "Your Azure Tenant id"
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: real-device-claim0
|
||||
name: real-device-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: real-device-claim1
|
||||
name: real-device-claim1
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: real-device-claim2
|
||||
name: real-device-claim2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: nexus-7.1.1-claim0
|
||||
name: nexus-7.1.1-claim0
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: nexus-7.1.1-claim1
|
||||
name: nexus-7.1.1-claim1
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 100Mi
|
||||
122
app.sh
Executable file
@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
|
||||
function is_str_in_list(){
|
||||
local given_str=${1}
|
||||
local list_str=${@:2}
|
||||
|
||||
if [[ ! " ${list_str[*]} " =~ " ${given_str} " ]]; then
|
||||
echo "${given_str} is not supported!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
tasks=("test" "build" "push")
|
||||
if [ -z "${1}" ]; then
|
||||
read -p "Task ($(echo "${tasks[@]}" | tr ' ' '|')) : " t
|
||||
else
|
||||
t=${1}
|
||||
fi
|
||||
is_str_in_list ${t} ${tasks[@]}
|
||||
|
||||
projects=("base" "emulator" "genymotion" "pro-emulator" "pro-emulator_headless")
|
||||
if [ -z "${2}" ]; then
|
||||
read -p "Project ($(echo "${projects[@]}" | tr ' ' '|')) : " p
|
||||
else
|
||||
p=${2}
|
||||
fi
|
||||
is_str_in_list ${p} ${projects[@]}
|
||||
|
||||
if [ -z "${3}" ]; then
|
||||
read -p "Release Version (v2.0-p0|v2.0-p1|etc) : " r_v
|
||||
else
|
||||
r_v=${3}
|
||||
fi
|
||||
|
||||
FOLDER_PATH=""
|
||||
IMAGE_NAME=""
|
||||
TAG_NAME=""
|
||||
|
||||
if [[ "${p}" == "pro"* ]]; then
|
||||
IFS='-' read -ra arr <<<"${p}"
|
||||
FOLDER_PATH+="docker/${arr[0]}/${arr[1]}"
|
||||
IMAGE_NAME+="budtmo2/docker-android-${arr[0]}"
|
||||
TAG_NAME+="${arr[1]}"
|
||||
else
|
||||
FOLDER_PATH+="docker/${p}"
|
||||
IMAGE_NAME+="budtmo/docker-android"
|
||||
TAG_NAME+="${p}"
|
||||
fi
|
||||
|
||||
if [[ "${p}" == *"emulator"* ]]; then
|
||||
supported_android_version=("9.0" "10.0" "11.0" "12.0" "13.0")
|
||||
declare -A api_levels=(
|
||||
["9.0"]=28
|
||||
["10.0"]=29
|
||||
["11.0"]=30
|
||||
["12.0"]=32
|
||||
["13.0"]=33
|
||||
)
|
||||
|
||||
# To get the last index
|
||||
keys=("${!api_levels[@]}")
|
||||
sorted_keys=($(printf '%s\n' "${keys[@]}" | sort))
|
||||
last_key=${keys[-2]} # because 9.0 will be last
|
||||
|
||||
if [ -z "${4}" ]; then
|
||||
read -p "Android Version ($(echo "${supported_android_version[@]}" \
|
||||
| tr ' ' '|')) : " a_v
|
||||
else
|
||||
a_v=${4}
|
||||
fi
|
||||
is_str_in_list ${a_v} ${supported_android_version[@]}
|
||||
a_l=${api_levels[${a_v}]}
|
||||
TAG_NAME+="_${a_v}"
|
||||
fi
|
||||
|
||||
IMAGE_NAME_LATEST="${IMAGE_NAME}:${TAG_NAME}"
|
||||
TAG_NAME+="_${r_v}"
|
||||
IMAGE_NAME_SPECIFIC_RELEASE=${IMAGE_NAME}:${TAG_NAME}
|
||||
echo "${IMAGE_NAME_SPECIFIC_RELEASE} or ${IMAGE_NAME_LATEST} "
|
||||
|
||||
function build() {
|
||||
# autopep8 --recursive --exclude=.git,__pycache__,venv --max-line-length=120 --in-place .
|
||||
cmd="docker build -t ${IMAGE_NAME_SPECIFIC_RELEASE} --build-arg DOCKER_ANDROID_VERSION=${r_v} "
|
||||
if [ -n "${a_v}" ]; then
|
||||
cmd+="--build-arg EMULATOR_ANDROID_VERSION=${a_v} --build-arg EMULATOR_API_LEVEL=${a_l} "
|
||||
fi
|
||||
|
||||
cmd+="-f ${FOLDER_PATH} ."
|
||||
${cmd}
|
||||
docker tag ${IMAGE_NAME_SPECIFIC_RELEASE} ${IMAGE_NAME_LATEST}
|
||||
|
||||
if [ -n "${a_v}" ] && [ "${a_v}" = "${last_key}" ]; then
|
||||
echo "${a_v} is the last version in the list, will use it as default image tag"
|
||||
docker tag ${IMAGE_NAME_SPECIFIC_RELEASE} ${IMAGE_NAME}:latest
|
||||
fi
|
||||
}
|
||||
|
||||
function test() {
|
||||
cli_path="/home/androidusr/docker-android/cli"
|
||||
results_path="test-results"
|
||||
tmp_folder="tmp"
|
||||
|
||||
mkdir -p tmp
|
||||
build
|
||||
docker run -it --rm --name test --entrypoint /bin/bash \
|
||||
-v $PWD/${tmp_folder}:${cli_path}/${tmp_folder} ${IMAGE_NAME_SPECIFIC_RELEASE} \
|
||||
-c "cd ${cli_path} && sudo rm -rf ${tmp_folder}/* && \
|
||||
nosetests -v && sudo mv .coverage ${tmp_folder} && \
|
||||
sudo cp -r ${results_path}/* ${tmp_folder} && sudo chown -R 1300:1301 ${tmp_folder} &&
|
||||
sudo chmod a+x -R ${tmp_folder}"
|
||||
}
|
||||
|
||||
function push() {
|
||||
build
|
||||
docker push ${IMAGE_NAME_SPECIFIC_RELEASE}
|
||||
docker push ${IMAGE_NAME_LATEST}
|
||||
if [ -n "${a_v}" ] && [ "${a_v}" = "${last_key}" ]; then
|
||||
docker push ${IMAGE_NAME}:latest
|
||||
fi
|
||||
}
|
||||
|
||||
${t}
|
||||
6
cli/requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
autopep8==2.0.2
|
||||
click==8.1.3
|
||||
coverage==7.2.5
|
||||
mock==5.0.2
|
||||
nose==1.3.7
|
||||
requests==2.30.0
|
||||
@ -1,13 +1,10 @@
|
||||
[nosetests]
|
||||
cover-xml=true
|
||||
cover-xml-file=coverage.xml
|
||||
cover-xml-file=test-results/coverage.xml
|
||||
with-coverage=true
|
||||
cover-package=src
|
||||
cover-erase=true
|
||||
with-xunit=true
|
||||
xunit-file=xunit.xml
|
||||
xunit-file=test-results/xunit.xml
|
||||
cover-html=true
|
||||
cover-html-dir=coverage
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
cover-html-dir=test-results/coverage
|
||||
21
cli/setup.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
app_version = os.getenv("DOCKER_ANDROID_VERSION", "test-version")
|
||||
|
||||
with open("requirements.txt", "r") as f:
|
||||
reqs = f.read().splitlines()
|
||||
|
||||
setup(
|
||||
name="docker-android",
|
||||
version=app_version,
|
||||
url="https://github.com/budtmo/docker-android",
|
||||
description="CLI for docker-android",
|
||||
author="Budi Utomo",
|
||||
author_email="budtmo.os@gmail.com",
|
||||
install_requires=reqs,
|
||||
py_modules=["cli", "docker-android"],
|
||||
entry_points={"console_scripts": "docker-android=src.app:cli"}
|
||||
)
|
||||
213
cli/src/app.py
Normal file
@ -0,0 +1,213 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
from typing import Union
|
||||
|
||||
import click
|
||||
import logging
|
||||
import os
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from src.application import Application
|
||||
from src.device import DeviceType
|
||||
from src.device.emulator import Emulator
|
||||
from src.device.geny_aws import GenyAWS
|
||||
from src.device.geny_saas import GenySAAS
|
||||
from src.helper import convert_str_to_bool, get_env_value_or_raise
|
||||
from src.constants import ENV
|
||||
from src.logger import log
|
||||
|
||||
log.init()
|
||||
logger = logging.getLogger("App")
|
||||
|
||||
|
||||
def get_device(given_input: str) -> Union[Emulator, GenyAWS, GenySAAS, None]:
|
||||
"""
|
||||
Get Device object based on given input
|
||||
|
||||
:param given_input: device in string
|
||||
:return: Platform object
|
||||
"""
|
||||
|
||||
input_lower = given_input.lower()
|
||||
|
||||
if input_lower == DeviceType.EMULATOR.value.lower():
|
||||
emu_av = get_env_value_or_raise(ENV.EMULATOR_ANDROID_VERSION)
|
||||
emu_img_type = get_env_value_or_raise(ENV.EMULATOR_IMG_TYPE)
|
||||
emu_sys_img = get_env_value_or_raise(ENV.EMULATOR_SYS_IMG)
|
||||
|
||||
emu_device = os.getenv(ENV.EMULATOR_DEVICE, "Nexus 5")
|
||||
emu_data_partition = os.getenv(ENV.EMULATOR_DATA_PARTITION, "550m")
|
||||
emu_additional_args = os.getenv(ENV.EMULATOR_ADDITIONAL_ARGS, "")
|
||||
|
||||
emu_name = os.getenv(ENV.EMULATOR_NAME, "{d}_{v}".format(
|
||||
d=emu_device.replace(" ", "_").lower(), v=emu_av))
|
||||
emu = Emulator(emu_name, emu_device, emu_av, emu_data_partition,
|
||||
emu_additional_args, emu_img_type, emu_sys_img)
|
||||
return emu
|
||||
elif input_lower == DeviceType.GENY_AWS.value.lower():
|
||||
return GenyAWS()
|
||||
elif input_lower == DeviceType.GENY_SAAS.value.lower():
|
||||
return GenySAAS()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@click.group(context_settings=dict(help_option_names=['-h', '--help']))
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
def start_appium() -> None:
|
||||
if convert_str_to_bool(os.getenv(ENV.APPIUM)):
|
||||
cmd = f"/usr/bin/appium"
|
||||
app_appium = Application("Appium", cmd,
|
||||
os.getenv(ENV.APPIUM_ADDITIONAL_ARGS, ""), False)
|
||||
app_appium.start()
|
||||
else:
|
||||
logger.info("env APPIUM cannot be found, Appium is not started!")
|
||||
|
||||
|
||||
def start_device() -> None:
|
||||
given_pt = get_env_value_or_raise(ENV.DEVICE_TYPE)
|
||||
selected_device = get_device(given_pt)
|
||||
if selected_device is None:
|
||||
raise RuntimeError(f"'{given_pt}' is invalid! Please check again!")
|
||||
selected_device.create()
|
||||
selected_device.start()
|
||||
selected_device.wait_until_ready()
|
||||
selected_device.reconfigure()
|
||||
selected_device.keep_alive()
|
||||
|
||||
|
||||
def start_display_screen() -> None:
|
||||
cmd = "/usr/bin/Xvfb"
|
||||
args = f"{os.getenv(ENV.DISPLAY)} " \
|
||||
f"-screen {os.getenv(ENV.SCREEN_NUMBER)} " \
|
||||
f"{os.getenv(ENV.SCREEN_WIDTH)}x" \
|
||||
f"{os.getenv(ENV.SCREEN_HEIGHT)}x" \
|
||||
f"{os.getenv(ENV.SCREEN_DEPTH)}"
|
||||
d_screen = Application("d_screen", cmd, args, False)
|
||||
d_screen.start()
|
||||
|
||||
|
||||
def start_display_wm() -> None:
|
||||
cmd = "/usr/bin/openbox-session"
|
||||
d_wm = Application("d_wm", cmd)
|
||||
d_wm.start()
|
||||
|
||||
|
||||
def start_port_forwarder() -> None:
|
||||
import socket
|
||||
local_ip = socket.gethostbyname(socket.gethostname())
|
||||
cmd = f"/usr/bin/socat tcp-listen:5554,bind={local_ip},fork tcp:127.0.0.1:5554 & " \
|
||||
f"/usr/bin/socat tcp-listen:5555,bind={local_ip},fork tcp:127.0.0.1:5555"
|
||||
pf = Application("port_forwarder", cmd)
|
||||
pf.start()
|
||||
|
||||
|
||||
def start_vnc_server() -> None:
|
||||
cmd = "/usr/bin/x11vnc"
|
||||
vnc_pass = os.getenv(ENV.VNC_PASSWORD)
|
||||
if vnc_pass:
|
||||
pass_path = os.path.join(os.getenv(ENV.WORK_PATH), ".vncpass")
|
||||
subprocess.check_call(f"{cmd} -storepasswd {vnc_pass} {pass_path}", shell=True)
|
||||
last_arg = f"-rfbauth {pass_path}"
|
||||
else:
|
||||
last_arg = "-nopw"
|
||||
|
||||
display = os.getenv(ENV.DISPLAY)
|
||||
args = f"-display {display} -forever -shared {last_arg}"
|
||||
vnc_server = Application("vnc_web", cmd, args, False)
|
||||
vnc_server.start()
|
||||
|
||||
|
||||
def start_vnc_web() -> None:
|
||||
if convert_str_to_bool(os.getenv(ENV.WEB_VNC)):
|
||||
vnc_port = get_env_value_or_raise(ENV.VNC_PORT)
|
||||
vnc_web_port = get_env_value_or_raise(ENV.WEB_VNC_PORT)
|
||||
cmd = "/opt/noVNC/utils/novnc_proxy"
|
||||
args = f"--vnc localhost:{vnc_port} localhost:{vnc_web_port}"
|
||||
vnc_web = Application("vnc_web", cmd, args, False)
|
||||
vnc_web.start()
|
||||
else:
|
||||
logger.info("env WEB_VNC cannot be found, VNC_WEB is not started!")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("app", type=click.Choice([app.value for app in Application.App]))
|
||||
def start(app):
|
||||
selected_app = str(app).lower()
|
||||
if selected_app == Application.App.APPIUM.value.lower():
|
||||
start_appium()
|
||||
elif selected_app == Application.App.DEVICE.value.lower():
|
||||
start_device()
|
||||
elif selected_app == Application.App.DISPLAY_SCREEN.value.lower():
|
||||
start_display_screen()
|
||||
elif selected_app == Application.App.DISPLAY_WM.value.lower():
|
||||
start_display_wm()
|
||||
elif selected_app == Application.App.PORT_FORWARDER.value.lower():
|
||||
start_port_forwarder()
|
||||
elif selected_app == Application.App.VNC_SERVER.value.lower():
|
||||
start_vnc_server()
|
||||
elif selected_app == Application.App.VNC_WEB.value.lower():
|
||||
start_vnc_web()
|
||||
else:
|
||||
logger.error(f"application '{selected_app}' is not supported!")
|
||||
|
||||
|
||||
class SharedComponent(Enum):
|
||||
LOG = "log"
|
||||
|
||||
|
||||
def shared_log() -> None:
|
||||
if convert_str_to_bool(os.getenv(ENV.WEB_LOG)):
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
log_path = get_env_value_or_raise(ENV.LOG_PATH)
|
||||
log_port = int(get_env_value_or_raise(ENV.WEB_LOG_PORT))
|
||||
logger.info(f"Shared log is enabled! all logs can be found on port '{log_port}'")
|
||||
|
||||
class LogSharedHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
# root path
|
||||
if self.path == "/":
|
||||
html = "<html><body>"
|
||||
for f in os.listdir(log_path):
|
||||
html += f"<p><a href=\"{f}\">{f}</a></p>"
|
||||
html += "</body></html>"
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(html.encode())
|
||||
# open each selected log file
|
||||
else:
|
||||
p = log_path + self.path
|
||||
try:
|
||||
with open(p, "rb") as file:
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(file.read())
|
||||
except FileNotFoundError:
|
||||
self.send_error(404, "File not found")
|
||||
|
||||
httpd = HTTPServer(('0.0.0.0', log_port), LogSharedHandler)
|
||||
httpd.serve_forever()
|
||||
else:
|
||||
logger.info(f"Shared log is disabled! nothing to do!")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("component", type=click.Choice([component.value for component in SharedComponent]))
|
||||
def share(component):
|
||||
selected_component = str(component).lower()
|
||||
if selected_component == SharedComponent.LOG.value.lower():
|
||||
shared_log()
|
||||
else:
|
||||
logger.error(f"component '{component}' is not supported!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
||||
35
cli/src/application/__init__.py
Normal file
@ -0,0 +1,35 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Application:
|
||||
class App(Enum):
|
||||
APPIUM = "appium"
|
||||
DEVICE = "device"
|
||||
DISPLAY_SCREEN = "display_screen"
|
||||
DISPLAY_WM = "display_wm"
|
||||
PORT_FORWARDER = "port_forwarder"
|
||||
VNC_SERVER = "vnc_server"
|
||||
VNC_WEB = "vnc_web"
|
||||
|
||||
def __init__(self, name: str, command: str, additional_args: str = "", ui: bool = False) -> None:
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.name = name
|
||||
self.command = command
|
||||
self.additional_args = additional_args
|
||||
self.ui = ui
|
||||
|
||||
def start(self) -> None:
|
||||
if self.ui:
|
||||
self.logger.info(f"{self.name} will be started with ui!")
|
||||
subprocess.check_call(f"/usr/bin/xterm -T {self.name} -n {self.name} "
|
||||
f"-e '{self.command} {self.additional_args}'", shell=True)
|
||||
else:
|
||||
self.logger.info(f"{self.name} will be started without ui!")
|
||||
subprocess.check_call(f"{self.command} {self.additional_args}", shell=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "Application(name={n}, command={c}, args={args}, ui={ui})".format(
|
||||
n=self.name, c=self.command, args=self.additional_args, ui=self.ui)
|
||||
6
cli/src/constants/DEVICE.py
Normal file
@ -0,0 +1,6 @@
|
||||
# Status
|
||||
STATUS_CREATING = "CREATING"
|
||||
STATUS_STARTING = "STARTING"
|
||||
STATUS_BOOTING = "BOOTING"
|
||||
STATUS_RECONFIGURING = "RECONFIGURING"
|
||||
STATUS_READY = "READY"
|
||||
45
cli/src/constants/ENV.py
Normal file
@ -0,0 +1,45 @@
|
||||
# General
|
||||
DOCKER_ANDROID_VERSION = "DOCKER_ANDROID_VERSION"
|
||||
USER_BEHAVIOR_ANALYTICS = "USER_BEHAVIOR_ANALYTICS"
|
||||
APPIUM = "APPIUM"
|
||||
APPIUM_ADDITIONAL_ARGS = "APPIUM_ADDITIONAL_ARGS"
|
||||
DISPLAY = "DISPLAY"
|
||||
SCREEN_DEPTH = "SCREEN_DEPTH"
|
||||
SCREEN_HEIGHT = "SCREEN_HEIGHT"
|
||||
SCREEN_NUMBER = "SCREEN_NUMBER"
|
||||
SCREEN_WIDTH = "SCREEN_WIDTH"
|
||||
VNC_PASSWORD = "VNC_PASSWORD"
|
||||
VNC_PORT = "VNC_PORT"
|
||||
WEB_VNC_PORT = "WEB_VNC_PORT"
|
||||
WEB_VNC = "WEB_VNC"
|
||||
WORK_PATH = "WORK_PATH"
|
||||
LOG_PATH = "LOG_PATH"
|
||||
WEB_LOG_PORT = "WEB_LOG_PORT"
|
||||
WEB_LOG = "WEB_LOG"
|
||||
|
||||
# Device
|
||||
DEVICE_INTERVAL_WAITING = "DEVICE_INTERVAL_WAITING"
|
||||
DEVICE_TYPE = "DEVICE_TYPE"
|
||||
|
||||
# Device (Emulator)
|
||||
EMULATOR_ADDITIONAL_ARGS = "EMULATOR_ADDITIONAL_ARGS"
|
||||
EMULATOR_ANDROID_VERSION = "EMULATOR_ANDROID_VERSION"
|
||||
EMULATOR_DATA_PARTITION = "EMULATOR_DATA_PARTITION"
|
||||
EMULATOR_DEVICE = "EMULATOR_DEVICE"
|
||||
EMULATOR_IMG_TYPE = "EMULATOR_IMG_TYPE"
|
||||
EMULATOR_NAME = "EMULATOR_NAME"
|
||||
EMULATOR_NO_SKIN = "EMULATOR_NO_SKIN"
|
||||
EMULATOR_SYS_IMG = "EMULATOR_SYS_IMG"
|
||||
|
||||
# Device (Genymotion - General)
|
||||
GENYMOTION_TEMPLATE_PATH = "GENYMOTION_TEMPLATE_PATH"
|
||||
|
||||
# Device (Geny_SAAS)
|
||||
GENY_SAAS_USER = "GENY_SAAS_USER"
|
||||
GENY_SAAS_PASS = "GENY_SAAS_PASS"
|
||||
GENY_SAAS_TEMPLATE_FILE_NAME = "saas.json"
|
||||
|
||||
# Device (Geny_AWS)
|
||||
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"
|
||||
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"
|
||||
GENY_AWS_TEMPLATE_FILE_NAME = "aws.json"
|
||||
1
cli/src/constants/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
UTF8 = "utf-8"
|
||||
172
cli/src/device/__init__.py
Normal file
@ -0,0 +1,172 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import requests
|
||||
import signal
|
||||
import time
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
|
||||
from src.helper import convert_str_to_bool, get_env_value_or_raise
|
||||
from src.constants import DEVICE, ENV
|
||||
|
||||
|
||||
class DeviceType(Enum):
|
||||
EMULATOR = "emulator"
|
||||
GENY_SAAS = "geny_saas"
|
||||
GENY_AWS = "geny_aws"
|
||||
|
||||
|
||||
class Device(ABC):
|
||||
FORM_ID = "1FAIpQLSdrKWQdMh6Nt8v8NQdYvTIntohebAgqWCpXT3T9NofAoxcpkw"
|
||||
FORM_USER = "user"
|
||||
FORM_CITY = "city"
|
||||
FORM_REGION = "region"
|
||||
FORM_COUNTRY = "country"
|
||||
FORM_APP_VERSION = "app_version"
|
||||
FORM_APPIUM = "appium"
|
||||
FORM_APPIUM_ADDITIONAL_ARGS = "appium_additional_args"
|
||||
FORM_WEB_LOG = "web_log"
|
||||
FORM_WEB_VNC = "web_vnc"
|
||||
FORM_SCREEN_RESOLUTION = "screen_resolution"
|
||||
FORM_DEVICE_TYPE = "device_type"
|
||||
FORM_EMU_DEVICE = "emu_device"
|
||||
FORM_EMU_ANDROID_VERSION = "emu_android_version"
|
||||
FORM_EMU_NO_SKIN = "emu_no_skin"
|
||||
FORM_EMU_DATA_PARTITION = "emu_data_partition"
|
||||
FORM_EMU_ADDITIONAL_ARGS = "emu_additional_args"
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.device_type = None
|
||||
self.interval_waiting = int(os.getenv(ENV.DEVICE_INTERVAL_WAITING, 2))
|
||||
self.user_behavior_analytics = convert_str_to_bool(os.getenv(ENV.USER_BEHAVIOR_ANALYTICS, "true"))
|
||||
self.form_field = {
|
||||
Device.FORM_USER: "entry.108751316",
|
||||
Device.FORM_CITY: "entry.2083022547",
|
||||
Device.FORM_REGION: "entry.1083141079",
|
||||
Device.FORM_COUNTRY: "entry.1946159560",
|
||||
Device.FORM_APP_VERSION: "entry.818050927",
|
||||
Device.FORM_APPIUM: "entry.181610571",
|
||||
Device.FORM_APPIUM_ADDITIONAL_ARGS: "entry.727759656",
|
||||
Device.FORM_WEB_LOG: "entry.1225589007",
|
||||
Device.FORM_WEB_VNC: "entry.2055392048",
|
||||
Device.FORM_SCREEN_RESOLUTION: "entry.709976626",
|
||||
Device.FORM_DEVICE_TYPE: "entry.207096546",
|
||||
Device.FORM_EMU_DEVICE: "entry.1960740382",
|
||||
Device.FORM_EMU_ANDROID_VERSION: "entry.671872491",
|
||||
Device.FORM_EMU_NO_SKIN: "entry.403556951",
|
||||
Device.FORM_EMU_DATA_PARTITION: "entry.1052258875",
|
||||
Device.FORM_EMU_ADDITIONAL_ARGS: "entry.57529972"
|
||||
}
|
||||
self.form_data = {}
|
||||
signal.signal(signal.SIGTERM, self.tear_down)
|
||||
|
||||
def set_status(self, current_status) -> None:
|
||||
bashrc_file = f"{os.getenv(ENV.WORK_PATH)}/device_status"
|
||||
with open(bashrc_file, "w+") as bf:
|
||||
bf.write(current_status)
|
||||
# It won't work using docker exec
|
||||
# os.environ[constants.ENV_DEVICE_STATUS] = current_status
|
||||
|
||||
def _prepare_analytics_payload(self) -> None:
|
||||
self.form_data.update({
|
||||
self.form_field[Device.FORM_USER]: f"{platform.platform()}_{platform.version().replace(' ', '_')}",
|
||||
self.form_field[Device.FORM_APP_VERSION]: os.getenv(ENV.DOCKER_ANDROID_VERSION),
|
||||
self.form_field[Device.FORM_DEVICE_TYPE]: self.device_type,
|
||||
self.form_field[Device.FORM_WEB_VNC]: convert_str_to_bool(os.getenv(ENV.WEB_VNC)),
|
||||
self.form_field[Device.FORM_WEB_LOG]: convert_str_to_bool(os.getenv(ENV.WEB_LOG)),
|
||||
self.form_field[Device.FORM_APPIUM]: convert_str_to_bool(os.getenv(ENV.APPIUM))
|
||||
})
|
||||
|
||||
try:
|
||||
res = requests.get("https://ipinfo.io")
|
||||
if res.ok:
|
||||
json_res = res.json()
|
||||
self.form_data.update({
|
||||
self.form_field[Device.FORM_CITY]: json_res[Device.FORM_CITY],
|
||||
self.form_field[Device.FORM_REGION]: json_res[Device.FORM_REGION],
|
||||
self.form_field[Device.FORM_COUNTRY]: json_res[Device.FORM_COUNTRY]
|
||||
})
|
||||
except requests.exceptions.RequestException as rer:
|
||||
self.logger.warning(rer)
|
||||
pass
|
||||
except KeyError as ke:
|
||||
self.logger.warning(ke)
|
||||
pass
|
||||
|
||||
def create(self) -> None:
|
||||
if self.user_behavior_analytics:
|
||||
self.logger.info("Sending user behavior analytics to improve the tool")
|
||||
try:
|
||||
form_url = f"https://docs.google.com/forms/d/e/{Device.FORM_ID}/formResponse"
|
||||
self._prepare_analytics_payload()
|
||||
requests.post(url=form_url, data=self.form_data)
|
||||
except requests.exceptions.RequestException as rer:
|
||||
self.logger.warning(rer)
|
||||
pass
|
||||
self.set_status(DEVICE.STATUS_CREATING)
|
||||
|
||||
def start(self) -> None:
|
||||
self.set_status(DEVICE.STATUS_STARTING)
|
||||
|
||||
def wait_until_ready(self) -> None:
|
||||
self.set_status(DEVICE.STATUS_BOOTING)
|
||||
|
||||
def reconfigure(self) -> None:
|
||||
self.set_status(DEVICE.STATUS_RECONFIGURING)
|
||||
|
||||
def keep_alive(self) -> None:
|
||||
self.set_status(DEVICE.STATUS_READY)
|
||||
self.logger.warning(f"{self.device_type} process will be kept alive to be able to get sigterm signal...")
|
||||
while True:
|
||||
time.sleep(2)
|
||||
|
||||
@abstractmethod
|
||||
def tear_down(self, *args) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class Genymotion(Device):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
|
||||
def get_data_from_template(self, filename: str) -> dict:
|
||||
path_template_json = os.path.join(get_env_value_or_raise(ENV.GENYMOTION_TEMPLATE_PATH), filename)
|
||||
data = {}
|
||||
if os.path.isfile(path_template_json):
|
||||
try:
|
||||
self.logger.info(path_template_json)
|
||||
with open(path_template_json, "r") as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError as fnf:
|
||||
self.shutdown_and_logout()
|
||||
self.logger.error(f"File cannot be found: {fnf}")
|
||||
except json.JSONDecodeError as jde:
|
||||
self.shutdown_and_logout()
|
||||
self.logger.error(f"Error Decoding Json: {jde}")
|
||||
except Exception as e:
|
||||
self.shutdown_and_logout()
|
||||
self.logger.error(e)
|
||||
else:
|
||||
self.shutdown_and_logout()
|
||||
raise RuntimeError(f"'{path_template_json}' cannot be found!")
|
||||
return data
|
||||
|
||||
@abstractmethod
|
||||
def login(self) -> None:
|
||||
pass
|
||||
|
||||
def create(self) -> None:
|
||||
super().create()
|
||||
self.login()
|
||||
|
||||
@abstractmethod
|
||||
def shutdown_and_logout(self) -> None:
|
||||
pass
|
||||
|
||||
def tear_down(self, *args) -> None:
|
||||
self.shutdown_and_logout()
|
||||
237
cli/src/device/emulator.py
Normal file
@ -0,0 +1,237 @@
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from src.device import Device, DeviceType
|
||||
from src.helper import convert_str_to_bool, get_env_value_or_raise, symlink_force
|
||||
from src.constants import ENV, UTF8
|
||||
|
||||
|
||||
class Emulator(Device):
|
||||
DEVICE = (
|
||||
"Nexus 4",
|
||||
"Nexus 5",
|
||||
"Nexus 7",
|
||||
"Nexus One",
|
||||
"Nexus S",
|
||||
"Samsung Galaxy S6",
|
||||
"Samsung Galaxy S7",
|
||||
"Samsung Galaxy S7 Edge",
|
||||
"Samsung Galaxy S8",
|
||||
"Samsung Galaxy S9",
|
||||
"Samsung Galaxy S10"
|
||||
)
|
||||
|
||||
API_LEVEL = {
|
||||
"9.0": "28",
|
||||
"10.0": "29",
|
||||
"11.0": "30",
|
||||
"12.0": "32",
|
||||
"13.0": "33"
|
||||
}
|
||||
|
||||
adb_name_id = 5554
|
||||
|
||||
class ReadinessCheck(Enum):
|
||||
BOOTED = "booted"
|
||||
RUN_STATE = "in running state"
|
||||
WELCOME_SCREEN = "in welcome screen"
|
||||
POP_UP_WINDOW = "pop up window"
|
||||
|
||||
def __init__(self, name: str, device: str, android_version: str, data_partition: str,
|
||||
additional_args: str, img_type: str, sys_img: str) -> None:
|
||||
super().__init__()
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.adb_name = f"emulator-{Emulator.adb_name_id}"
|
||||
self.device_type = DeviceType.EMULATOR.value
|
||||
self.name = name
|
||||
if device in self.DEVICE:
|
||||
self.device = device
|
||||
else:
|
||||
raise RuntimeError(f"device '{device}' is not supported!")
|
||||
if android_version in self.API_LEVEL.keys():
|
||||
self.android_version = android_version
|
||||
else:
|
||||
raise RuntimeError(f"android version '{android_version}' is not supported!")
|
||||
self.api_level = self.API_LEVEL[self.android_version]
|
||||
self.data_partition = data_partition
|
||||
self.additional_args = additional_args
|
||||
self.img_type = img_type
|
||||
self.sys_img = sys_img
|
||||
workdir = get_env_value_or_raise(ENV.WORK_PATH)
|
||||
self.path_device_profile_target = os.path.join(workdir, ".android", "devices.xml")
|
||||
self.path_emulator = os.path.join(workdir, "emulator")
|
||||
self.path_emulator_config = os.path.join(workdir, "emulator", "config.ini")
|
||||
self.path_emulator_profiles = os.path.join(workdir, "docker-android", "mixins",
|
||||
"configs", "devices", "profiles")
|
||||
self.path_emulator_skins = os.path.join(workdir, "docker-android", "mixins",
|
||||
"configs", "devices", "skins")
|
||||
self.file_name = self.device.replace(" ", "_").lower()
|
||||
self.no_skin = convert_str_to_bool(os.getenv(ENV.EMULATOR_NO_SKIN))
|
||||
self.interval_after_booting = 15
|
||||
Emulator.adb_name_id += 2
|
||||
self.form_data.update({
|
||||
self.form_field[Device.FORM_SCREEN_RESOLUTION]: f"{os.getenv(ENV.SCREEN_WIDTH)}x"
|
||||
f"{os.getenv(ENV.SCREEN_HEIGHT)}x"
|
||||
f"{os.getenv(ENV.SCREEN_DEPTH)}",
|
||||
self.form_field[Device.FORM_EMU_DEVICE]: self.device,
|
||||
self.form_field[Device.FORM_EMU_ANDROID_VERSION]: self.android_version,
|
||||
self.form_field[Device.FORM_EMU_NO_SKIN]: self.no_skin,
|
||||
self.form_field[Device.FORM_EMU_DATA_PARTITION]: self.data_partition,
|
||||
self.form_field[Device.FORM_EMU_ADDITIONAL_ARGS]: self.additional_args
|
||||
})
|
||||
|
||||
def is_initialized(self) -> bool:
|
||||
import re
|
||||
if os.path.exists(self.path_emulator_config):
|
||||
self.logger.info("Config file exists")
|
||||
with open(self.path_emulator_config, 'r') as f:
|
||||
if any(re.match(r'hw\.device\.name ?= ?{}'.format(self.device), line) for line in f):
|
||||
self.logger.info("Selected device is already created")
|
||||
return True
|
||||
else:
|
||||
self.logger.info("Selected device is not created")
|
||||
return False
|
||||
|
||||
self.logger.info("Config file does not exist")
|
||||
return False
|
||||
|
||||
def _add_profile(self) -> None:
|
||||
if "samsung" in self.device.lower():
|
||||
path_device_profile_source = os.path.join(self.path_emulator_profiles,
|
||||
"{fn}.xml".format(fn=self.file_name))
|
||||
symlink_force(path_device_profile_source, self.path_device_profile_target)
|
||||
self.logger.info("Samsung device profile is linked")
|
||||
|
||||
def _add_skin(self) -> None:
|
||||
device_skin_path = os.path.join(
|
||||
self.path_emulator_skins, "{fn}".format(fn=self.file_name))
|
||||
with open(self.path_emulator_config, "a") as cf:
|
||||
cf.write("hw.keyboard=yes\n")
|
||||
cf.write("disk.dataPartition.size={dp}\n".format(dp=self.data_partition))
|
||||
cf.write("skin.path={sp}\n".format(
|
||||
sp="_no_skin" if self.no_skin else device_skin_path))
|
||||
self.logger.info(f"Skin is added in: '{self.path_emulator_config}'")
|
||||
|
||||
def create(self) -> None:
|
||||
super().create()
|
||||
first_run = not self.is_initialized()
|
||||
if first_run:
|
||||
self.logger.info(f"Creating the {self.device_type}...")
|
||||
self._add_profile()
|
||||
creation_cmd = "avdmanager create avd -f -n {n} -b {it}/{si} " \
|
||||
"-k 'system-images;android-{al};{it};{si}' " \
|
||||
"-d {d} -p {pe}".format(n=self.name, it=self.img_type, si=self.sys_img,
|
||||
al=self.api_level, d=self.device.replace(" ", "\ "),
|
||||
pe=self.path_emulator)
|
||||
self.logger.info(f"Command to create emulator: '{creation_cmd}'")
|
||||
subprocess.check_call(creation_cmd, shell=True)
|
||||
self._add_skin()
|
||||
self.logger.info(f"{self.device_type} is created!")
|
||||
|
||||
def change_permission(self) -> None:
|
||||
kvm_path = "/dev/kvm"
|
||||
if os.path.exists(kvm_path):
|
||||
cmds = (f"sudo chown 1300:1301 {kvm_path}",
|
||||
"sudo sed -i '1d' /etc/passwd")
|
||||
for c in cmds:
|
||||
subprocess.check_call(c, shell=True)
|
||||
self.logger.info("KVM permission is granted!")
|
||||
else:
|
||||
raise RuntimeError("/dev/kvm cannot be found!")
|
||||
|
||||
def deploy(self):
|
||||
self.logger.info(f"Deploying the {self.device_type}")
|
||||
|
||||
basic_cmd = "emulator @{n}".format(n=self.name)
|
||||
basic_args = "-gpu swiftshader_indirect -accel on -writable-system -verbose"
|
||||
wipe_arg = "-wipe-data" if not self.is_initialized() else ""
|
||||
|
||||
start_cmd = f"{basic_cmd} {basic_args} {wipe_arg} {self.additional_args}"
|
||||
self.logger.info(f"Command to run {self.device_type}: '{start_cmd}'")
|
||||
subprocess.Popen(start_cmd.split())
|
||||
|
||||
def start(self) -> None:
|
||||
super().start()
|
||||
self.change_permission()
|
||||
self.deploy()
|
||||
|
||||
def check_adb_command(self, readiness_check_type: ReadinessCheck, bash_command: str,
|
||||
expected_keyword: str, max_attempts: int, interval_waiting_time: int,
|
||||
adb_action: str = None) -> None:
|
||||
success = False
|
||||
for _ in range(1, max_attempts):
|
||||
if success:
|
||||
break
|
||||
else:
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
bash_command.split()).decode(UTF8)
|
||||
if expected_keyword in str(output).lower():
|
||||
if readiness_check_type is self.ReadinessCheck.POP_UP_WINDOW:
|
||||
subprocess.check_call(adb_action, shell=True)
|
||||
else:
|
||||
self.logger.info(
|
||||
f"{self.device_type} is {readiness_check_type.value}!")
|
||||
success = True
|
||||
else:
|
||||
self.logger.info(f"[attempt: {_}] {self.device_type} is not {readiness_check_type.value}! "
|
||||
f"will check again in {interval_waiting_time} seconds")
|
||||
time.sleep(interval_waiting_time)
|
||||
except subprocess.CalledProcessError:
|
||||
self.logger.warning("command cannot be executed! will continue...")
|
||||
time.sleep(2)
|
||||
continue
|
||||
else:
|
||||
if readiness_check_type is self.ReadinessCheck.POP_UP_WINDOW:
|
||||
self.logger.info(f"Pop up windows '{expected_keyword}' is not found!")
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f"{readiness_check_type.value} is checked {_} times!")
|
||||
|
||||
def wait_until_ready(self) -> None:
|
||||
super().wait_until_ready()
|
||||
booting_cmd = f"adb -s {self.adb_name} wait-for-device shell getprop sys.boot_completed"
|
||||
focus_cmd = f"adb -s {self.adb_name} shell dumpsys window | grep -i mCurrentFocus"
|
||||
self.check_adb_command(self.ReadinessCheck.BOOTED,
|
||||
booting_cmd, "1", 60, self.interval_waiting)
|
||||
time.sleep(self.interval_after_booting)
|
||||
|
||||
interval_pop_up = 0
|
||||
max_attempt_pop_up = 3
|
||||
pop_up_system_ui = "Not Responding: com.android.systemui"
|
||||
system_ui_cmd = f"adb shell su root 'kill $(pidof com.android.systemui)'"
|
||||
pop_up_key_enter = {
|
||||
"Not Responding: com.google.android.gms",
|
||||
"Not Responding: system",
|
||||
"ConversationListActivity"
|
||||
}
|
||||
key_enter_cmd = "adb shell input keyevent KEYCODE_ENTER"
|
||||
self.check_adb_command(self.ReadinessCheck.POP_UP_WINDOW, focus_cmd, pop_up_system_ui,
|
||||
max_attempt_pop_up, interval_pop_up, system_ui_cmd)
|
||||
for pe in pop_up_key_enter:
|
||||
self.check_adb_command(self.ReadinessCheck.POP_UP_WINDOW, focus_cmd, pe, max_attempt_pop_up,
|
||||
interval_pop_up, key_enter_cmd)
|
||||
|
||||
self.check_adb_command(self.ReadinessCheck.WELCOME_SCREEN,
|
||||
focus_cmd, "launcheractivity", 60, self.interval_waiting)
|
||||
self.logger.info(f"{self.device_type} is ready to use")
|
||||
|
||||
def tear_down(self, *args) -> None:
|
||||
self.logger.warning("Sigterm is detected! Nothing to do!")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
try:
|
||||
return "Emulator(name={n}, device={d}, adb_name={an}, android_version={av}, api_level={al}, " \
|
||||
"data_partition={dp}, additional_args={aa}, img_type={it}, sys_img={si}, " \
|
||||
"path_device_profile_target={pdpt}, path_emulator={pe}, path_emulator_config={pec}, " \
|
||||
"file={f})".format(n=self.name, d=self.device, an=self.adb_name, av=self.android_version,
|
||||
al=self.api_level, dp=self.data_partition, aa=self.additional_args,
|
||||
it=self.img_type, si=self.sys_img, pdpt=self.path_device_profile_target,
|
||||
pe=self.path_emulator, pec=self.path_emulator_config, f=self.file_name)
|
||||
except AttributeError as ae:
|
||||
self.logger.error(ae)
|
||||
return ""
|
||||
223
cli/src/device/geny_aws.py
Normal file
@ -0,0 +1,223 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from src.device import Genymotion, DeviceType
|
||||
from src.helper import get_env_value_or_raise
|
||||
from src.constants import ENV, UTF8
|
||||
|
||||
|
||||
class GenyAWS(Genymotion):
|
||||
port = 5555
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.device_type = DeviceType.GENY_AWS.value
|
||||
self.workdir = get_env_value_or_raise(ENV.WORK_PATH)
|
||||
self.aws_credentials_path = os.path.join(self.workdir, ".aws")
|
||||
self.remove_cred_at_the_end = False # for logout
|
||||
self.geny_aws_template_path = os.path.join(self.workdir, "docker-android", "mixins",
|
||||
"templates", "genymotion", "aws")
|
||||
self.created_devices = {}
|
||||
|
||||
def login(self) -> None:
|
||||
aws_credentials_file = os.path.join(self.aws_credentials_path, "credentials")
|
||||
if os.path.exists(self.aws_credentials_path):
|
||||
self.logger.info(".aws is found! It will be used as credentials")
|
||||
else:
|
||||
self.logger.info(".aws cannot be found! the template will be used!")
|
||||
self.remove_cred_at_the_end = True
|
||||
aws_credentials_template_path = os.path.join(self.geny_aws_template_path, ".aws")
|
||||
shutil.move(aws_credentials_template_path, self.aws_credentials_path)
|
||||
|
||||
aws_key_id = get_env_value_or_raise(ENV.AWS_ACCESS_KEY_ID)
|
||||
aws_secret_key = get_env_value_or_raise(ENV.AWS_SECRET_ACCESS_KEY)
|
||||
replacements_cred = {
|
||||
f"<{ENV.AWS_ACCESS_KEY_ID.lower()}>": aws_key_id,
|
||||
f"<{ENV.AWS_SECRET_ACCESS_KEY.lower()}>": aws_secret_key
|
||||
}
|
||||
with open(aws_credentials_file, 'r+') as cred_file:
|
||||
cred_file_contents = cred_file.read()
|
||||
for old_str, new_str in replacements_cred.items():
|
||||
cred_file_contents = cred_file_contents.replace(old_str, new_str)
|
||||
cred_file.seek(0)
|
||||
cred_file.write(cred_file_contents)
|
||||
cred_file.truncate()
|
||||
self.logger.info("aws credentials is set!")
|
||||
|
||||
def create_ssh_key(self) -> None:
|
||||
subprocess.check_call('ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""', shell=True)
|
||||
self.logger.info("ssh key is created!")
|
||||
|
||||
def create_tf_files(self) -> None:
|
||||
try:
|
||||
for item in self.get_data_from_template(ENV.GENY_AWS_TEMPLATE_FILE_NAME):
|
||||
name = item["name"]
|
||||
region = item["region"]
|
||||
ami = item["ami"]
|
||||
instance_type = item["instance_type"]
|
||||
if "security_group" in item:
|
||||
sg = item["security_group"]
|
||||
tf_content = f'''
|
||||
provider "aws" {{
|
||||
alias = "provider_{name}"
|
||||
region = "{region}"
|
||||
}}
|
||||
|
||||
resource "aws_key_pair" "geny_key_{name}" {{
|
||||
provider = aws.provider_{name}
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}}
|
||||
|
||||
resource "aws_instance" "geny_aws_{name}" {{
|
||||
provider = aws.provider_{name}
|
||||
ami = "{ami}"
|
||||
instance_type = "{instance_type}"
|
||||
vpc_security_group_ids = ["{sg}"]
|
||||
key_name = aws_key_pair.geny_key_{name}.key_name
|
||||
tags = {{
|
||||
Name = "DockerAndroid-GenyAWS-{ami}.id}}"
|
||||
}}
|
||||
|
||||
provisioner "remote-exec" {{
|
||||
connection {{
|
||||
type = "ssh"
|
||||
user = "shell"
|
||||
host = self.public_ip
|
||||
private_key = file("~/.ssh/id_rsa")
|
||||
}}
|
||||
script = "/home/androidusr/docker-android/mixins/scripts/genymotion/aws/enable_adb.sh"
|
||||
}}
|
||||
}}
|
||||
|
||||
output "public_dns_{name}" {{
|
||||
value = aws_instance.geny_aws_{name}.public_dns
|
||||
}}
|
||||
'''
|
||||
else:
|
||||
ingress_rules = json.dumps(item["ingress_rules"])
|
||||
egress_rules = json.dumps(item["egress_rules"])
|
||||
tf_content = f'''
|
||||
locals {{
|
||||
ingress_rules = {ingress_rules}
|
||||
egress_rules = {egress_rules}
|
||||
}}
|
||||
|
||||
provider "aws" {{
|
||||
alias = "provider_{name}"
|
||||
region = "{region}"
|
||||
}}
|
||||
|
||||
resource "aws_security_group" "geny_sg_{name}" {{
|
||||
provider = aws.provider_{name}
|
||||
dynamic "ingress" {{
|
||||
for_each = local.ingress_rules
|
||||
content {{
|
||||
from_port = ingress.value.from_port
|
||||
to_port = ingress.value.to_port
|
||||
protocol = ingress.value.protocol
|
||||
cidr_blocks = ingress.value.cidr_blocks
|
||||
}}
|
||||
}}
|
||||
|
||||
dynamic "egress" {{
|
||||
for_each = local.egress_rules
|
||||
content {{
|
||||
from_port = egress.value.from_port
|
||||
to_port = egress.value.to_port
|
||||
protocol = egress.value.protocol
|
||||
cidr_blocks = egress.value.cidr_blocks
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
|
||||
resource "aws_key_pair" "geny_key_{name}" {{
|
||||
provider = aws.provider_{name}
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}}
|
||||
|
||||
resource "aws_instance" "geny_aws_{name}" {{
|
||||
provider = aws.provider_{name}
|
||||
ami = "{ami}"
|
||||
instance_type = "{instance_type}"
|
||||
vpc_security_group_ids = [aws_security_group.geny_sg_{name}.name]
|
||||
key_name = aws_key_pair.geny_key_{name}.key_name
|
||||
tags = {{
|
||||
Name = "DockerAndroid-GenyAWS-{ami}.id}}"
|
||||
}}
|
||||
|
||||
provisioner "remote-exec" {{
|
||||
connection {{
|
||||
type = "ssh"
|
||||
user = "shell"
|
||||
host = self.public_ip
|
||||
private_key = file("~/.ssh/id_rsa")
|
||||
}}
|
||||
script = "/home/androidusr/docker-android/mixins/scripts/genymotion/aws/enable_adb.sh"
|
||||
}}
|
||||
}}
|
||||
|
||||
output "public_dns_{name}" {{
|
||||
value = aws_instance.geny_aws_{name}.public_dns
|
||||
}}
|
||||
'''
|
||||
tf_deployment_filename = f"{name}.tf"
|
||||
self.created_devices[name] = GenyAWS.port
|
||||
GenyAWS.port += 1
|
||||
with open(tf_deployment_filename, "w") as df:
|
||||
df.write(tf_content)
|
||||
self.logger.info("Terraform files are created!")
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
self.shutdown_and_logout()
|
||||
|
||||
def deploy_tf(self) -> None:
|
||||
try:
|
||||
cmds = (
|
||||
"terraform init",
|
||||
"terraform plan",
|
||||
"terraform apply -auto-approve"
|
||||
)
|
||||
for c in cmds:
|
||||
subprocess.check_call(c, shell=True)
|
||||
self.logger.info("Genymotion-Device(s) are deployed on AWS")
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
self.logger.error(cpe)
|
||||
self.shutdown_and_logout()
|
||||
|
||||
def connect_with_local_adb(self) -> None:
|
||||
self.logger.info(f"created devices: {self.created_devices}")
|
||||
try:
|
||||
for d, p in self.created_devices.items():
|
||||
dns_cmd = f"terraform output public_dns_{d}"
|
||||
dns_ip = subprocess.check_output(dns_cmd.split()).decode(UTF8).replace('"', '')
|
||||
tunnel_cmd = f"ssh -i ~/.ssh/id_rsa -o ServerAliveInterval=60 -o StrictHostKeyChecking=no -q -NL " \
|
||||
f"{p}:localhost:5555 shell@{dns_ip}"
|
||||
subprocess.Popen(tunnel_cmd.split())
|
||||
time.sleep(10)
|
||||
subprocess.check_call(f"adb connect localhost:{p} >/dev/null 2>&1", shell=True)
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
self.shutdown_and_logout()
|
||||
|
||||
def create(self) -> None:
|
||||
super().create()
|
||||
self.create_ssh_key()
|
||||
self.create_tf_files()
|
||||
self.deploy_tf()
|
||||
self.connect_with_local_adb()
|
||||
|
||||
def shutdown_and_logout(self) -> None:
|
||||
try:
|
||||
subprocess.check_call("terraform destroy -auto-approve -lock=false", shell=True)
|
||||
self.logger.info("device(s) is successfully removed!")
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
self.logger.error(cpe)
|
||||
finally:
|
||||
if self.remove_cred_at_the_end:
|
||||
subprocess.check_call(f"rm -rf {self.aws_credentials_path}", shell=True)
|
||||
self.logger.info("successfully logged out!")
|
||||
72
cli/src/device/geny_saas.py
Normal file
@ -0,0 +1,72 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from src.device import Genymotion, DeviceType
|
||||
from src.helper import get_env_value_or_raise
|
||||
from src.constants import ENV, UTF8
|
||||
|
||||
|
||||
class GenySAAS(Genymotion):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.device_type = DeviceType.GENY_SAAS.value
|
||||
self.created_devices = []
|
||||
|
||||
def login(self) -> None:
|
||||
user = get_env_value_or_raise(ENV.GENY_SAAS_USER)
|
||||
password = get_env_value_or_raise(ENV.GENY_SAAS_PASS)
|
||||
subprocess.check_call(f"gmsaas auth login {user} {password} > /dev/null 2>&1", shell=True)
|
||||
self.logger.info("successfully logged in!")
|
||||
|
||||
def create(self) -> None:
|
||||
super().create()
|
||||
for item in self.get_data_from_template(ENV.GENY_SAAS_TEMPLATE_FILE_NAME):
|
||||
name = ""
|
||||
template = ""
|
||||
local_port = ""
|
||||
|
||||
# implement like this because local_port param is not a must
|
||||
for k, v in item.items():
|
||||
if k.lower() == "name":
|
||||
name = v
|
||||
elif k.lower() == "template":
|
||||
template = v
|
||||
elif k.lower() == "local_port":
|
||||
local_port = v
|
||||
else:
|
||||
self.logger.warning(f"'{k}' is not supported! Please check the documentation!")
|
||||
|
||||
if not name:
|
||||
import uuid
|
||||
name = str(uuid.uuid4())
|
||||
|
||||
if not template:
|
||||
self.shutdown_and_logout()
|
||||
raise RuntimeError(f"'template' is a must parameter and not given!")
|
||||
else:
|
||||
self.logger.info(f"name: {name}, template: {template}")
|
||||
creation_cmd = f"gmsaas instances start {template} {name}"
|
||||
try:
|
||||
instance_id = subprocess.check_output(creation_cmd.split()).decode(UTF8).replace("\n", "")
|
||||
created_device = {f"{name}": {instance_id}}
|
||||
self.created_devices.append(created_device)
|
||||
additional_args = ""
|
||||
if local_port:
|
||||
additional_args = f"--adb-serial-port {local_port}"
|
||||
connect_cmd = f"gmsaas instances adbconnect {instance_id} {additional_args}"
|
||||
subprocess.check_call(f"{connect_cmd}", shell=True)
|
||||
except Exception as e:
|
||||
self.shutdown_and_logout()
|
||||
self.logger.error(e)
|
||||
exit(1)
|
||||
|
||||
def shutdown_and_logout(self) -> None:
|
||||
if bool(self.created_devices):
|
||||
self.logger.info("Created device(s) will be removed!")
|
||||
for d in self.created_devices:
|
||||
for n, i in d.items():
|
||||
subprocess.check_call(f"gmsaas instances stop {i}", shell=True)
|
||||
self.logger.info(f"device '{n}' is successfully removed!")
|
||||
subprocess.check_call("gmsaas auth logout", shell=True)
|
||||
self.logger.info("successfully logged out!")
|
||||
56
cli/src/helper/__init__.py
Normal file
@ -0,0 +1,56 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
logger = logging.getLogger("helper")
|
||||
|
||||
|
||||
def convert_str_to_bool(given_str: str) -> bool:
|
||||
"""
|
||||
Convert String to Boolean value
|
||||
|
||||
:param given_str: given string
|
||||
:return: converted string in Boolean
|
||||
"""
|
||||
if given_str:
|
||||
if type(given_str) is str:
|
||||
return given_str.lower() in ("yes", "true", "t", "1")
|
||||
else:
|
||||
raise AttributeError
|
||||
else:
|
||||
logger.info(f"'{given_str}' is empty!")
|
||||
return False
|
||||
|
||||
|
||||
def get_env_value_or_raise(env_key: str) -> str:
|
||||
"""
|
||||
Get value of necessary environment variable.
|
||||
|
||||
:param env_key: given environment variable
|
||||
:return: env_value in String
|
||||
"""
|
||||
try:
|
||||
env_value = os.getenv(env_key)
|
||||
if not env_value:
|
||||
raise RuntimeError(f"'{env_key}' is missing.")
|
||||
elif env_value.isspace():
|
||||
raise RuntimeError(f"'{env_key}' contains only white space.")
|
||||
return env_value
|
||||
except TypeError as t_err:
|
||||
logger.error(t_err)
|
||||
|
||||
|
||||
def symlink_force(source: str, target: str) -> None:
|
||||
"""
|
||||
Create Symbolic link
|
||||
|
||||
:param source: source file
|
||||
:param target: target file
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
os.symlink(source, target)
|
||||
except FileNotFoundError as ffe_err:
|
||||
logger.error(ffe_err)
|
||||
except FileExistsError:
|
||||
os.remove(target)
|
||||
os.symlink(source, target)
|
||||
3
cli/src/logger/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
import os
|
||||
|
||||
LOGGING_FILE = os.path.join(os.path.dirname(__file__), 'logging.conf')
|
||||
@ -1,9 +1,7 @@
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
from src import LOGGING_FILE
|
||||
from src.logger import LOGGING_FILE
|
||||
|
||||
|
||||
def init():
|
||||
"""Init log."""
|
||||
logging.config.fileConfig(LOGGING_FILE)
|
||||
@ -1,5 +1,5 @@
|
||||
[loggers]
|
||||
keys=root, app
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=console
|
||||
@ -11,16 +11,11 @@ keys=formatter
|
||||
level=INFO
|
||||
handlers=console
|
||||
|
||||
[logger_app]
|
||||
level=INFO
|
||||
handlers=console
|
||||
propagate=0
|
||||
qualname=app
|
||||
|
||||
[handler_console]
|
||||
class=StreamHandler
|
||||
formatter=formatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[formatter_formatter]
|
||||
format=[%(process)2d] [%(levelname)5s] %(name)s - %(message)s
|
||||
format=%(asctime)s %(levelname)s %(name)s - %(message)s
|
||||
datefmt=%Y-%m-%d %H:%M:%S
|
||||
9
cli/src/tests/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
class BaseTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
def tearDown(self) -> None:
|
||||
pass
|
||||
21
cli/src/tests/device/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from src.constants import ENV
|
||||
from src.tests import BaseTest
|
||||
|
||||
|
||||
class BaseDeviceTest(BaseTest):
|
||||
DEVICE_ENVS = {
|
||||
ENV.WORK_PATH: "/home/androidusr",
|
||||
ENV.USER_BEHAVIOR_ANALYTICS: str(False),
|
||||
ENV.EMULATOR_NO_SKIN: str(False)
|
||||
}
|
||||
|
||||
def setUp(self) -> None:
|
||||
for k, v in self.DEVICE_ENVS.items():
|
||||
os.environ[k] = v
|
||||
|
||||
def tearDown(self) -> None:
|
||||
for k in self.DEVICE_ENVS.keys():
|
||||
if os.environ[k]:
|
||||
del os.environ[k]
|
||||
8
cli/src/tests/device/test_device.py
Normal file
@ -0,0 +1,8 @@
|
||||
from src.device import Device
|
||||
from src.tests.device import BaseDeviceTest
|
||||
|
||||
|
||||
class TestDevice(BaseDeviceTest):
|
||||
def test_create_device(self):
|
||||
with self.assertRaises(TypeError):
|
||||
Device()
|
||||
87
cli/src/tests/device/test_emulator.py
Normal file
@ -0,0 +1,87 @@
|
||||
import mock
|
||||
|
||||
from src.device.emulator import Emulator
|
||||
from src.tests.device import BaseDeviceTest
|
||||
|
||||
|
||||
class TestEmulator(BaseDeviceTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.name = "my_emu"
|
||||
self.device = "Nexus 4"
|
||||
self.a_version = "10.0"
|
||||
self.d_partition = "550m"
|
||||
self.additional_args = ""
|
||||
self.i_type = "google_apis"
|
||||
self.s_img = "x86"
|
||||
self.emu = Emulator(self.name, self.device, self.a_version, self.d_partition,
|
||||
self.additional_args, self.i_type, self.s_img)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
super().tearDown()
|
||||
|
||||
def test_adb_name(self):
|
||||
my_emu = Emulator("my_other_emu", self.device, self.a_version, self.d_partition,
|
||||
self.additional_args, self.i_type, self.s_img)
|
||||
self.assertNotEqual(self.emu.adb_name, my_emu.adb_name)
|
||||
|
||||
def test_invalid_device(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
Emulator("my_other_emu", "unknown device", self.a_version, self.d_partition,
|
||||
self.additional_args, self.i_type, self.s_img)
|
||||
with self.assertRaises(RuntimeError):
|
||||
Emulator("my_other_emu", "NEXUS 5", self.a_version, self.d_partition,
|
||||
self.additional_args, self.i_type, self.s_img)
|
||||
|
||||
def test_invalid_android_version(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
Emulator("my_other_emu", self.device, "0.0", self.d_partition,
|
||||
self.additional_args, self.i_type, self.s_img)
|
||||
|
||||
@mock.patch("os.path.exists", mock.MagicMock(return_value=False))
|
||||
def test_initialisation_config_not_exist(self):
|
||||
self.assertEqual(self.emu.is_initialized(), False)
|
||||
|
||||
@mock.patch("os.path.exists", mock.MagicMock(return_value=True))
|
||||
@mock.patch("builtins.open", mock.mock_open(read_data=""))
|
||||
def test_initialisation_device_not_exist(self):
|
||||
self.assertEqual(self.emu.is_initialized(), False)
|
||||
|
||||
@mock.patch("os.path.exists", mock.MagicMock(return_value=True))
|
||||
@mock.patch("builtins.open", mock.mock_open(read_data="hw.device.name=Nexus 4\n"))
|
||||
def test_initialisation_device_exists(self):
|
||||
self.assertEqual(self.emu.is_initialized(), True)
|
||||
|
||||
@mock.patch("src.device.Device.set_status")
|
||||
@mock.patch("src.device.emulator.Emulator._add_profile")
|
||||
@mock.patch("subprocess.check_call")
|
||||
@mock.patch("src.device.emulator.Emulator._add_skin")
|
||||
@mock.patch("src.device.emulator.Emulator.is_initialized", mock.MagicMock(return_value=False))
|
||||
def test_create_device_not_exist(self, mocked_status, mocked_profile, mocked_subprocess, mocked_skin):
|
||||
self.emu.create()
|
||||
self.assertEqual(mocked_status.called, True)
|
||||
self.assertEqual(mocked_profile.called, True)
|
||||
self.assertEqual(mocked_subprocess.called, True)
|
||||
self.assertEqual(mocked_skin.called, True)
|
||||
|
||||
@mock.patch("src.device.Device.set_status")
|
||||
@mock.patch("src.device.emulator.Emulator._add_profile")
|
||||
@mock.patch("subprocess.check_call")
|
||||
@mock.patch("src.device.emulator.Emulator._add_skin")
|
||||
@mock.patch("src.device.emulator.Emulator.is_initialized", mock.MagicMock(return_value=True))
|
||||
def test_create_device_exists(self, mocked_status, mocked_profile, mocked_subprocess, mocked_skin):
|
||||
self.emu.create()
|
||||
self.assertEqual(mocked_status.called, False)
|
||||
self.assertEqual(mocked_profile.called, False)
|
||||
self.assertEqual(mocked_subprocess.called, False)
|
||||
|
||||
def test_check_adb_command(self):
|
||||
with mock.patch("subprocess.check_output", mock.MagicMock(return_value="1".encode("utf-8"))):
|
||||
self.emu.check_adb_command(
|
||||
self.emu.ReadinessCheck.BOOTED, "mocked_command", "1", 3, 0)
|
||||
|
||||
def test_check_adb_command_out_of_attempts(self):
|
||||
with mock.patch("subprocess.check_output", mock.MagicMock(return_value=" ".encode("utf-8"))):
|
||||
with self.assertRaises(RuntimeError):
|
||||
self.emu.check_adb_command(
|
||||
self.emu.ReadinessCheck.BOOTED, "mocked_command", "1", 3, 0)
|
||||
73
cli/src/tests/helper/test_helper.py
Normal file
@ -0,0 +1,73 @@
|
||||
import os
|
||||
import mock
|
||||
|
||||
from src.helper import convert_str_to_bool, get_env_value_or_raise, symlink_force
|
||||
from src.tests import BaseTest
|
||||
|
||||
|
||||
class TestHelperMethods(BaseTest):
|
||||
def test_boolean_converter_with_valid_str(self):
|
||||
self.assertEqual(convert_str_to_bool("TRUE"), True)
|
||||
self.assertEqual(convert_str_to_bool("true"), True)
|
||||
self.assertEqual(convert_str_to_bool("T"), True)
|
||||
self.assertEqual(convert_str_to_bool("Yes"), True)
|
||||
self.assertEqual(convert_str_to_bool("1"), True)
|
||||
self.assertEqual(convert_str_to_bool("False"), False)
|
||||
self.assertEqual(convert_str_to_bool("f"), False)
|
||||
self.assertEqual(convert_str_to_bool("0"), False)
|
||||
|
||||
def test_boolean_converter_with_empty(self):
|
||||
self.assertEqual(convert_str_to_bool(None), False)
|
||||
self.assertEqual(convert_str_to_bool(""), False)
|
||||
|
||||
def test_boolean_converter_with_invalid_str(self):
|
||||
self.assertEqual(convert_str_to_bool(" "), False)
|
||||
self.assertEqual(convert_str_to_bool("test"), False)
|
||||
|
||||
def test_boolean_converter_with_invalid_format(self):
|
||||
with self.assertRaises(AttributeError):
|
||||
convert_str_to_bool(True)
|
||||
|
||||
def test_get_env_value_from_valid_key(self):
|
||||
env_key = "env_key01"
|
||||
os.environ[env_key] = "env_value01"
|
||||
get_env_value_or_raise(env_key)
|
||||
del os.environ[env_key]
|
||||
|
||||
def test_get_env_value_with_empty_string(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
env_key = "env_key01"
|
||||
os.environ[env_key] = " "
|
||||
get_env_value_or_raise(env_key)
|
||||
del os.environ[env_key]
|
||||
|
||||
def test_get_env_value_from_invalid_key(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
get_env_value_or_raise("env_key02")
|
||||
|
||||
def test_get_env_value_with_invalid_format(self):
|
||||
with mock.patch("src.logger"):
|
||||
get_env_value_or_raise(True)
|
||||
|
||||
def test_symlink(self):
|
||||
s = os.path.join("source.txt")
|
||||
t = os.path.join("target_file.txt")
|
||||
open(s, "a").close()
|
||||
symlink_force(s, t)
|
||||
os.remove(s)
|
||||
os.remove(t)
|
||||
|
||||
def test_symlink_already_exist(self):
|
||||
s = os.path.join("source.txt")
|
||||
t = os.path.join("target_file.txt")
|
||||
open(s, "a").close()
|
||||
open(t, "a").close()
|
||||
symlink_force(s, t)
|
||||
os.remove(s)
|
||||
os.remove(t)
|
||||
|
||||
def test_symlink_file_not_exists(self):
|
||||
s = os.path.join("source.txt")
|
||||
t = os.path.join("target_file.txt")
|
||||
symlink_force(s, t)
|
||||
os.remove(t)
|
||||
4
cli/test-results/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 53 KiB |
@ -1,59 +0,0 @@
|
||||
parts {
|
||||
device {
|
||||
display {
|
||||
width 720
|
||||
height 1280
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
}
|
||||
portrait {
|
||||
background {
|
||||
image port_back.png
|
||||
}
|
||||
onion {
|
||||
image port_fore.png
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
background {
|
||||
image land_back.png
|
||||
}
|
||||
onion {
|
||||
image land_fore.png
|
||||
}
|
||||
}
|
||||
}
|
||||
layouts {
|
||||
portrait {
|
||||
width 1101
|
||||
height 1709
|
||||
event EV_SW:0:1
|
||||
part1 {
|
||||
name portrait
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 192
|
||||
y 213
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
width 1847
|
||||
height 886
|
||||
event EV_SW:0:0
|
||||
part1 {
|
||||
name landscape
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 304
|
||||
y 788
|
||||
rotation 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 557 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 72 KiB |
@ -1,59 +0,0 @@
|
||||
parts {
|
||||
device {
|
||||
display {
|
||||
width 1600
|
||||
height 2560
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
}
|
||||
portrait {
|
||||
background {
|
||||
image port_back.png
|
||||
}
|
||||
onion {
|
||||
image port_fore.png
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
background {
|
||||
image land_back.png
|
||||
}
|
||||
onion {
|
||||
image land_fore.png
|
||||
}
|
||||
}
|
||||
}
|
||||
layouts {
|
||||
portrait {
|
||||
width 2330
|
||||
height 3136
|
||||
event EV_SW:0:1
|
||||
part1 {
|
||||
name portrait
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 366
|
||||
y 266
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
width 3340
|
||||
height 2176
|
||||
event EV_SW:0:0
|
||||
part1 {
|
||||
name landscape
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 388
|
||||
y 1866
|
||||
rotation 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 511 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 806 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 39 KiB |
@ -1,59 +0,0 @@
|
||||
parts {
|
||||
device {
|
||||
display {
|
||||
width 1080
|
||||
height 1920
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
}
|
||||
portrait {
|
||||
background {
|
||||
image port_back.png
|
||||
}
|
||||
onion {
|
||||
image port_fore.png
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
background {
|
||||
image land_back.png
|
||||
}
|
||||
onion {
|
||||
image land_fore.png
|
||||
}
|
||||
}
|
||||
}
|
||||
layouts {
|
||||
portrait {
|
||||
width 1370
|
||||
height 2446
|
||||
event EV_SW:0:1
|
||||
part1 {
|
||||
name portrait
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 147
|
||||
y 233
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
width 2497
|
||||
height 1234
|
||||
event EV_SW:0:0
|
||||
part1 {
|
||||
name landscape
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 278
|
||||
y 1143
|
||||
rotation 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 820 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 690 KiB |
|
Before Width: | Height: | Size: 221 KiB |
|
Before Width: | Height: | Size: 60 KiB |
@ -1,59 +0,0 @@
|
||||
parts {
|
||||
device {
|
||||
display {
|
||||
width 1440
|
||||
height 2560
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
}
|
||||
portrait {
|
||||
background {
|
||||
image port_back.png
|
||||
}
|
||||
onion {
|
||||
image port_fore.png
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
background {
|
||||
image land_back.png
|
||||
}
|
||||
onion {
|
||||
image land_fore.png
|
||||
}
|
||||
}
|
||||
}
|
||||
layouts {
|
||||
portrait {
|
||||
width 1896
|
||||
height 3054
|
||||
event EV_SW:0:1
|
||||
part1 {
|
||||
name portrait
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 229
|
||||
y 239
|
||||
}
|
||||
}
|
||||
landscape {
|
||||
width 3142
|
||||
height 1639
|
||||
event EV_SW:0:0
|
||||
part1 {
|
||||
name landscape
|
||||
x 0
|
||||
y 0
|
||||
}
|
||||
part2 {
|
||||
name device
|
||||
x 318
|
||||
y 1516
|
||||
rotation 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 779 KiB |