Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android meets Docker

Android meets Docker

Presented at Mobile Optimized 2017

Jing Li

July 15, 2017
Tweet

More Decks by Jing Li

Other Decks in Programming

Transcript

  1. Flashback The story started... The Android robot is reproduced or

    modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. Docker Whale (https://www.docker.com/) by Docker, Inc
  2. Where the problem comes Infer - A tool to detect

    bugs in Java and ... code before it ships. Infer (http://fbinfer.com/) by Facebook, Inc. Running Android SDK update in Docker container The default filesystem used by Docker doesn't support some file operations. And Android SDK update involves hardlink moving, which leads to failure.
  3. Why Docker? Docker Vagrant Resource Isolation Low Extreme Supported OS

    Linux * Boot / Stop Time Seconds Minutes Size MB GB
  4. Docker ABC • image vs container • build vs pull

    • That’s enough, let’s go!
  5. Dockerfile Best Practices • Single responsibility ◦ use compose for

    orchestration • Minimize the number of layers ◦ layer = intermediate image, supports caching • Size matters, use what you have ◦ Install & un- by separated steps will ⇧ image size • Readability
  6. Solution for SDK update Mount SDK volume in container •

    Support update • Minimal & Flexible: install on demand • Persist data: save download time • Share SDK among many containers Easy to maintain
  7. SSH • Mind your language ◦ locale-gen en en_US en_US.UTF-8

    • Set up env ◦ /root/.ssh/environment • Authorization ◦ /root/.ssh/authorized_keys
  8. Jenkins Environment variables are never easy • Global level ◦

    Configure System -> Global properties -> Environment variables • Node level ◦ Manage Nodes -> Configure Node -> Node Properties -> Environment variables • Job level ◦ Configure Job -> Build -> Build Step -> Execute shell ◦ Plugin: Environment Injector -> Inject variables to the build process / as a build step
  9. Performance Comparison 2 build types, 107 unit tests ( x2

    = 214 ), 2 UI tests ./gradlew clean check :demo:connectedAndroidTest Docker (w/ cached AndroidSDK) 6 mins 48.0 secs Other online CI solutions (w/o optimization) > 10 mins
  10. And better? • Gradle caches ◦ Time Is Money -

    download dependencies makes you SLEEPY ◦ ~/.gradle/caches/ Compiling (https://xkcd.com/303/) by xkcd
  11. Gradle distributions mirror server • gradle/wrapper/gradle-wrapper.properties ◦ distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip • /root/.gradle/wrapper/dists

    • SSL certificate - needs to be trusted by Java keystore ◦ $JAVA_HOME/bin/keytool -import -trustcacerts -file /home/apache.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt • https -> http • /etc/hosts
  12. Pitfalls & Restrictions • Emulator is slow • USB devices

    ◦ Unfortunately it is not possible to pass through a USB device (or a serial port) to a container on Mac • Docker daemon memory limit & JVM heap size 2 UI tests ( connectedAndroidTest ) ARM emulator @Docker 2 mins 4.615 secs Genymotion 25.335 secs
  13. Reveal machine-dependent problem • Encoding problem ◦ expected:<Hall[��]chen> but was:<Hall[ö]chen>

    • Hard coded Timezone in test ◦ expected:2099-12-31T00:00:00.0000+0200 but was: 2099-12-31T00:00:00.0000+0000 • File & Path ◦ File#listFiles() -> File[] (sort order might be different per OS)
  14. What else for mobile • Integration API Test ◦ Live

    API: flaky test / unreliable network / unpredictable content ◦ VCR: re-record network interactions on every change ◦ Docker: run backend service out of the box for mobile dev • API Test ◦ Test API / content provider - reuse the app’s code ◦ Serverless ( Kotlin, Swift )
  15. We are hiring in Warsaw & Berlin • viacom.tech/link/mobileoptimized/2017/careers •

    Lead Software Engineer – Mobile • Senior Software Engineer - Android • Senior Software Engineer - iOS • Software Architect • Unity Developer • Software Engineer - Frontend • Agile Team Coach and etc.