SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
© Atos
Mando Stamelaki
software engineer | mobile application developer
Build in Docker with
Jenkins
Automate your android application build inside a docker container
How it was
| © Atos
How it was…
- Linux Production machine carrying
the Android NDK (low level) Build
environment
- Triggered by a Windows VM, that
also built the high level code
- Manual upload to the Nexus
repository
rsync apk to
Linux m
achine maven upload
to nexus
3
Android Studio
Android SDK & tools
Android NDK
Gradle SSH plugin
get .so build libs
| © Atos
Why change it?
- Slow
- Multiple manual steps, significant effort
- Prune to human mistakes.
- Multiply building effort for rebuilds and privates.
- Regular upgrade of libraries
- Maintenance of two building machines
- No option to add build verifications in Gerrit (code review tool)
4
The idea
| © Atos
First idea
Use just the remote Linux machine to
build Android
Problems:
- need ssh root control to building machine
- no expertise on managing remotely
android tools
- always have in mind to check what tools
we have and update them responsively
- no easy way to manage the machine
environment or version control its status
Our build environment will remain linked
with a dedicated machine for building
6
| © Atos
software container platform
- Can package an application
and its dependencies in a
virtual container
- Enable flexibility and
portability on where the
application can run
- automates the deployment of
applications inside software
containers
7
| © Atos
Applying to our case...
Have a machine with only docker in it,
…
Looks like a great idea!
...
We can then have multiple machines
with only docker in them.
- Easy check of the tools we have
installed in production
- Everyone will be able to edit and
maintain the dockerfiles that will have
our environment
- Dockerfiles can be in version control
and will check changed and updates
with git
- We don’t have any real machine so no
need for ssh access
8
| © Atos
Jenkins
- Continuous integration
- Continuous delivery
- Build and test your software
projects continuously
- Multiple plugins
continuous integration
software
9
| © Atos
Jenkins will use as slaves dummy
machines that will only have
docker in them.
For security purposes and to keep
dockerfiles simple we can also add
git and maven in these machines.
10
| © Atos
Docker problems
- Decide where we are going to build our images described in dockerfiles
- Store the builded images so as to avoid rebuilds
(Android SDK and NDK take too long to download)
- How to use docker and jenkins as a team?
11
| © Atos
Registry?
We need someplace to host
our images
Decided to use docker hub as we
are not planning to add something
confidential in them.
Docker build performed by docker
hub.
12
Let's make this work
| © Atos
Write our dockerfiles
Oracle Java Development Kit (JDK) docker pull playmobils/oracle-jdk:8
Android Software Development Kit (SDK) docker pull playmobils/android-sdk:23
Android Native Development Kit (NDK) docker pull playmobils/android-ndk:14b
Additional tools that may missing docker pull playmobils/android
https://github.com/PlayMOBils/android-environment
14
# Oracle JDK 8
# Pull base image.
FROM debian:jessie
# Set the locale, avoid warnings in regular expressions
RUN 
apt-get update && 
apt-get install -qqy --no-install-recommends locales && 
rm -rf /var/lib/apt/lists/* 
/var/cache/apt/archives/* 
/var/cache/debconf/*-old &&
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
# Install Deps
# - http://www.oracle.com/technetwork/java/javase/jre-8-readme-2095710.html
RUN 
echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main | tee /etc/apt/sources.list.d/webupd8team-java.list
&&
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 &&
apt-get update &&
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections &&
apt-get -qqy --no-install-recommends install oracle-java8-installer unzip &&
rm -rf ...
# Android SDK
FROM playmobils/oracle-jdk:8
ARG DEBIAN_FRONTEND=noninteractive
ENV SDK_HOME /usr/local
# Prerequisite packages libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
RUN dpkg --add-architecture i386 && 
apt-get -qq update && 
apt-get install -qqy --no-install-recommends 
curl libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 && 
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old
ENV ANDROID_HOME "${SDK_HOME}/sdk"
ENV PATH "$PATH:${ANDROID_HOME}/tools"
# Accept License
RUN mkdir -p $ANDROID_HOME/licenses/ && 
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license && 
echo "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_HOME/licenses/android-sdk-preview-license
ENV VERSION_SDK_TOOLS "25.2.5"
ENV VERSION_BUILD_TOOLS "23.0.3"
ENV VERSION_TARGET_SDK "23"
ENV SDK_PACKAGES "build-tools-${VERSION_BUILD_TOOLS},android-${VERSION_TARGET_SDK},
addon-google_apis-google-${VERSION_TARGET_SDK},platform-tools,extra-android-m2repository,extra-android-support,
extra-google-google_play_services,extra-google-m2repository"
ENV ANDROID_TOOLS_URL http://dl.google.com/android/repository/tools_r${VERSION_SDK_TOOLS}-linux.zip
RUN curl -L "${ANDROID_TOOLS_URL}" -o tools.zip && unzip /tools.zip -d ${ANDROID_HOME} && rm -vrf /tools.zip
RUN (while [ 1 ]; do sleep 5; echo y; done) | ${ANDROID_HOME}/tools/android update sdk no-ui all filter ${SDK_PACKAGES}
# Android NDK
FROM playmobils/android-sdk:23
ARG DEBIAN_FRONTEND=noninteractive
ENV SDK_HOME /usr/local
# Install dependencies
RUN dpkg --add-architecture i386 && 
apt-get -qq update && 
apt-get -qqy install --no-install-recommends file && 
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old
ENV ANDROID_NDK_VERSION r14b
ENV ANDROID_NDK_URL http://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
# Download and unzip Android NDK
RUN curl -L "${ANDROID_NDK_URL}" -o android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip 
&& unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip -d ${SDK_HOME} 
&& rm -rf android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
ENV ANDROID_NDK_HOME ${SDK_HOME}/android-ndk-${ANDROID_NDK_VERSION}
ENV PATH ${ANDROID_NDK_HOME}:$PATH
# Add some missing dependencies
FROM playmobils/android-ndk:14b
ARG DEBIAN_FRONTEND=noninteractive
# How to use
# In order to use it, you need to run it with:
# docker run -v <path to your source>:/src playmobils/android <file to run>
# The command above mounts your directory to where the container expects the source to be and builds it.
# Install dependencies
RUN apt-get -qq update && 
apt-get -qqy install --no-install-recommends gawk bc make git zip &&
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old
# User Sources for Android SDK Manager, to avoid any warnings
RUN echo "count=0" > ~/.android/repositories.cfg
Environment set!
Let's build it …
| © Atos
docker run -it -v $PWD/osmo:/osmo playmobils/android-ndk:r14b
# cd osmo/Android
# ./gradlew cleanAll
# ./gradlew buildNative
# ./gradlew assembleRelease
interactive terminal mount volume
commands to run inside docker Build Failed: The input device is not a TTY.
“You cannot have interactive console!”
20
open an interactive console with docker and run all
build commands like we do locally
| © Atos
docker run -i -v $PWD/osmo playmobils/android-ndk:r14b
sh scripts/android/build.sh
Keep STDIN open
even if not
attached mount volume
a bash file containing all build commands
Build Failed: exec: "scripts/android/build.sh": stat scripts/android/build.sh:
no such file or directory
21
we need a single build command
| © Atos
docker run -i -v $PWD/osmo -w /osmo playmobils/android-ndk:r14b
sh scripts/android/build.sh
Keep STDIN open
even if not
attached mount volume
a bash file containing all build commands
Build timed out (after 3 minutes). Marking the build as aborted.
workspace
Jenkins configure:
“Remove the build
timeout if task doesn’t
respond after 3
minutes”
22
use workspace in order to navigate in proper
location in container
| © Atos
Build Failed: Gradle cannot read the environment variables that defined in dockerfiles.
ie $ANDROID_HOME, $ANDROID_NDK_HOME
23
single build command with workspace
docker run -i -v $PWD/osmo -w /osmo playmobils/android-ndk:r14b
sh scripts/android/build.sh
Keep STDIN open
even if not
attached mount volume
a bash file containing all build commands
workspace
| © Atos
Define them in local.properties,
read them from there
#!/bin/bash
cd OSMO/Android
# create a local.properties file with ndk and sdk in order to used by gradle
echo "sdk.dir=$ANDROID_HOME" > local.properties
echo "ndk.dir=$ANDROID_NDK_HOME" >> local.properties
proxyArgs="-Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>"
echo -e "n ------------- START BUILD ------------- n"
./gradlew $proxyArgs allCleanBuildReleaseApk
echo -e "n ------------- END BUILD ------------- n"
echo -e "n ------------- START TESTS ------------- n"
./gradlew $proxyArgs test # run the unit tests
echo -e "n ------------- END TESTS ------------- n"
24
| © Atos
We download gradle wrapper in each run...
We can add the gradle download step in a dockerfile and use docker cache for that!
Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................................................................................................................
...........................
Unzipping /usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7/gradle-2.14.1-all.zip to
/usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7
Set executable permissions for:
/usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7/gradle-2.14.1/bin/gradle
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon:
https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
25
| © Atos
Local dockerfile for gradle dependencies
FROM playmobils/android:latest
COPY gradlew gradlew
COPY gradle/ gradle
COPY gradle.properties gradle.properties
RUN chmod 755 gradlew
# Run gradle once to download dependencies
RUN ./gradlew -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>
26
| © Atos
Lesson learned with local dockerfile
Build
docker build -t playmobils/osmo OSMO/Android
Dockerfile must be on the root level of project in order to
access files in it.
We can improve build time by using dockerignore and
ignore files not needed for building our dockerfile.
27
| © Atos
Builded docker images need a lot of space!!!
- about 5GB, our repository
- Docker images downloaded:
- Suggested 30GB
Trying to rebuild
Builder machine with docker run out of space!!!
REPOSITORY TAG IMAGE ID CREATED SIZE
playmobils/osmo latest 19b78d68ee15 6 weeks ago 4.57 GB
<none> <none> 6f3a5e8e76e1 6 weeks ago 4.57 GB
playmobils/android latest af3b4e8d0d15 6 weeks ago 4.35 GB
older
state of
image
layers
28
| © Atos
if [[ $(docker ps -qa --no-trunc --filter "status=exited") ]]; then
echo -e "n Delete old unused containers.n"
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
else
echo -e "n No containers for cleanup.n"
fi
29
Clean docker containers after or before each build
docker run --rm -i -v $PWD/osmo playmobils/android-ndk:r14b
sh scripts/android/build.sh
| © Atos
- Solution 1: Jenkins user be a root user.
- we don’t even want to try this one
When building in docker we build as root user
- Problem: Jenkins user cannot delete “root” files it has NO PERMISSIONS…
- Solution 2: Find a way to build in docker with jenkins user.
- use our local dockerfile to define the build user
- change permissions of running gradle file
- build with this user
30
Cannot create file/directory.
| © Atos
Local dockerfile for gradle dependencies
FROM playmobils/android:latest
ENV BUILD_USER jenkins_user
RUN useradd -ms /bin/bash -u 1001 $BUILD_USER
WORKDIR /home/$BUILD_USER
COPY gradlew gradlew
COPY gradle/ gradle
COPY gradle.properties gradle.properties
RUN chmod 755 gradlew && chown $BUILD_USER: gradlew && 
chown $BUILD_USER: gradle.properties && chown -R $BUILD_USER: gradle
USER $BUILD_USER
RUN ./gradlew # Run gradle once to download dependencies
31
Improvements
| © Atos
We noticed that failed statuses from docker not
passed in Jenkins
33
./gradlew $proxyArgs allCleanBuildReleaseApk; gradlew_return_code=$?
if (( gradlew_return_code != 0 )); then
echo "GRADLE BUILD FAILED!"
exit 1
fi
| © Atos
▶ Created a folder for GRADLE_HOME in the host machine
▶ Passed this folder as volume to docker
– Build time dropped to 9 min
– We noticed a couple of problems though that are due to fileHashes.lock
but this only happens when CI and release run in parallel
Cache the .gradle dependencies
34
docker run --rm -i -v $GRADLE_HOME:/home/jenkins_user/.gradle
-v $PWD/osmo
playmobils/android-ndk:r14b sh scripts/android/build.sh
| © Atos
▶ Save them to a file
▶ Pass this parameters in docker
Jenkins parameters needed inside docker
35
docker run --rm -i --env-file=env_vars.txt
-v $GRADLE_HOME:/home/jenkins_user/.gradle
-v $PWD/osmo
playmobils/android-ndk:r14b sh scripts/android/build.sh
env | grep GIT_ > env_vars.txt
| © Atos
▶ Changed all docker images to use the version tag
– SDK: playmobils/android-sdk:26
– NDK: playmobils/android-ndk:26_14b
– Tools: playmobils/android:26_14b
– Local: playmobils/osmo:26_14b
Build for different API versions
36
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
playmobils/osmo 26_14b 6c47fdd2ad7a 8 days ago 5.09GB
playmobils/osmo 27_14b d2b7addfed45 10 days ago 5.09GB
playmobils/android 27_14b 495a6cb3a3ab 10 days ago 4.84GB
playmobils/android 26_14b f5609b45b666 10 days ago 4.84GB
Putting it all together
| © Atos
VERSION=26_14b or VERSION=27_14b
- docker pull playmobils/android:$VERSION
- docker build -t playmobils/osmo:$VERSION OSMO/Android
- docker run --rm -i --env-file=env_vars.txt -v $PWD:$DWORKSPACE
-v $GRADLE_HOME:/home/jenkins_user/.gradle
-w /home/jenkins_user/osmo/
playmobils/osmo:$VERSION
/bin/bash scripts/android/BuildAndroidApp.sh
38
Full Jenkins shell script
some successful
basic commands
First & second
successful build
After manually
deleting files
two in a row builds
without any
intervene user
jenkins build
success
39
30-40 min
the image is not downloaded.
10-20 min
the image is present.
9-13 min
with the cache usage
Build time diagram
| © Atos
What we learned!
▶ Docker may need more disk space than expected.
▶ Dockerfiles and the kernel used for base images is minimal without the
essential tools be prepared to add anything missing from your build.
▶ A dockerfile that copy / add external files during build have to be in root
directory (symbolic links or relative paths to parents are not accepted).
▶ In jenkins you cannot build as root, create your jenkins user in dockerfile.
▶ In jenkins you don't have interactive console use a single line script including
your code.
▶ When you have dependable dockerfiles pulling / building the latest doesn't
mean that changes in other files will pulled / build.
41
| © Atos
References
- https://www.docker.com/
- https://docs.docker.com/
- http://blog.zot24.com/tips-tricks-docker/
- https://jenkins-ci.org/
42
- https://github.com/PlayMOBils/android-environment
- https://hub.docker.com/r/playmobils/
Dockerfiles and images:
Questions ?
© Atos
Thank you!
Mando Stamelaki
software engineer | mobile application developer
adamantia-eleni.stamelaki@atos.net

Weitere ähnliche Inhalte

Was ist angesagt?

Joomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJoomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJirayut Nimsaeng
 
Locally it worked! virtualizing docker
Locally it worked! virtualizing dockerLocally it worked! virtualizing docker
Locally it worked! virtualizing dockerSascha Brinkmann
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with DockerPatrick Mizer
 
Perspectives on Docker
Perspectives on DockerPerspectives on Docker
Perspectives on DockerRightScale
 
[DockerCon 2019] Hardening Docker daemon with Rootless mode
[DockerCon 2019] Hardening Docker daemon with Rootless mode[DockerCon 2019] Hardening Docker daemon with Rootless mode
[DockerCon 2019] Hardening Docker daemon with Rootless modeAkihiro Suda
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned RightScale
 
Docker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureTerry Chen
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPChris Tankersley
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...Jérôme Petazzoni
 
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewireIntroduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewiredotCloud
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsMicael Gallego
 
Build and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldBuild and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldJorge Morales
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochranedotCloud
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017Chris Tankersley
 
Dockerize the World
Dockerize the WorldDockerize the World
Dockerize the Worlddamovsky
 
DCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDocker, Inc.
 
Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Maciej Lasyk
 
Dockerize Laravel Application
Dockerize Laravel ApplicationDockerize Laravel Application
Dockerize Laravel ApplicationAfrimadoni Dinata
 
Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker AgileDenver
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsFrancesco Bruni
 

Was ist angesagt? (20)

Joomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJoomla Continuous Delivery with Docker
Joomla Continuous Delivery with Docker
 
Locally it worked! virtualizing docker
Locally it worked! virtualizing dockerLocally it worked! virtualizing docker
Locally it worked! virtualizing docker
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
 
Perspectives on Docker
Perspectives on DockerPerspectives on Docker
Perspectives on Docker
 
[DockerCon 2019] Hardening Docker daemon with Rootless mode
[DockerCon 2019] Hardening Docker daemon with Rootless mode[DockerCon 2019] Hardening Docker daemon with Rootless mode
[DockerCon 2019] Hardening Docker daemon with Rootless mode
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
Docker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT culture
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewireIntroduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and Jenkins
 
Build and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldBuild and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes world
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken Cochrane
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
 
Dockerize the World
Dockerize the WorldDockerize the World
Dockerize the World
 
DCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on KubernetesDCSF 19 Deploying Rootless buildkit on Kubernetes
DCSF 19 Deploying Rootless buildkit on Kubernetes
 
Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)
 
Dockerize Laravel Application
Dockerize Laravel ApplicationDockerize Laravel Application
Dockerize Laravel Application
 
Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and Jenkins
 

Ähnlich wie GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins

Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday developmentJustyna Ilczuk
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windowsDocker, Inc.
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 applicationRoman Rodomansky
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'acorehard_by
 
Deploy django apps using docker
Deploy django apps using dockerDeploy django apps using docker
Deploy django apps using dockerThomas Kremmel
 
DevAssistant, Docker and You
DevAssistant, Docker and YouDevAssistant, Docker and You
DevAssistant, Docker and YouBalaBit
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Ben Hall
 
Docker module 1
Docker module 1Docker module 1
Docker module 1Liang Bo
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET DevelopersTaswar Bhatti
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environmentSumedt Jitpukdebodin
 
20170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 201720170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 2017Takayoshi Tanaka
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020CloudHero
 
Delivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devicesDelivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devicesAjeet Singh Raina
 
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth RushgroveThe Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth RushgroveDocker, Inc.
 

Ähnlich wie GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins (20)

Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 
Docker+java
Docker+javaDocker+java
Docker+java
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
Deploy django apps using docker
Deploy django apps using dockerDeploy django apps using docker
Deploy django apps using docker
 
DevAssistant, Docker and You
DevAssistant, Docker and YouDevAssistant, Docker and You
DevAssistant, Docker and You
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET Developers
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Docker as development environment
Docker as development environmentDocker as development environment
Docker as development environment
 
20170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 201720170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 2017
 
Docker
DockerDocker
Docker
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
Delivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devicesDelivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devices
 
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth RushgroveThe Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
 

Kürzlich hochgeladen

miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxCarrieButtitta
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comsaastr
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxaryanv1753
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...漢銘 謝
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGYpruthirajnayak525
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !risocarla2016
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Escort Service
 
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.KathleenAnnCordero2
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...marjmae69
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 

Kürzlich hochgeladen (20)

miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptx
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptx
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170
 
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 

GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins

  • 1. © Atos Mando Stamelaki software engineer | mobile application developer Build in Docker with Jenkins Automate your android application build inside a docker container
  • 3. | © Atos How it was… - Linux Production machine carrying the Android NDK (low level) Build environment - Triggered by a Windows VM, that also built the high level code - Manual upload to the Nexus repository rsync apk to Linux m achine maven upload to nexus 3 Android Studio Android SDK & tools Android NDK Gradle SSH plugin get .so build libs
  • 4. | © Atos Why change it? - Slow - Multiple manual steps, significant effort - Prune to human mistakes. - Multiply building effort for rebuilds and privates. - Regular upgrade of libraries - Maintenance of two building machines - No option to add build verifications in Gerrit (code review tool) 4
  • 6. | © Atos First idea Use just the remote Linux machine to build Android Problems: - need ssh root control to building machine - no expertise on managing remotely android tools - always have in mind to check what tools we have and update them responsively - no easy way to manage the machine environment or version control its status Our build environment will remain linked with a dedicated machine for building 6
  • 7. | © Atos software container platform - Can package an application and its dependencies in a virtual container - Enable flexibility and portability on where the application can run - automates the deployment of applications inside software containers 7
  • 8. | © Atos Applying to our case... Have a machine with only docker in it, … Looks like a great idea! ... We can then have multiple machines with only docker in them. - Easy check of the tools we have installed in production - Everyone will be able to edit and maintain the dockerfiles that will have our environment - Dockerfiles can be in version control and will check changed and updates with git - We don’t have any real machine so no need for ssh access 8
  • 9. | © Atos Jenkins - Continuous integration - Continuous delivery - Build and test your software projects continuously - Multiple plugins continuous integration software 9
  • 10. | © Atos Jenkins will use as slaves dummy machines that will only have docker in them. For security purposes and to keep dockerfiles simple we can also add git and maven in these machines. 10
  • 11. | © Atos Docker problems - Decide where we are going to build our images described in dockerfiles - Store the builded images so as to avoid rebuilds (Android SDK and NDK take too long to download) - How to use docker and jenkins as a team? 11
  • 12. | © Atos Registry? We need someplace to host our images Decided to use docker hub as we are not planning to add something confidential in them. Docker build performed by docker hub. 12
  • 14. | © Atos Write our dockerfiles Oracle Java Development Kit (JDK) docker pull playmobils/oracle-jdk:8 Android Software Development Kit (SDK) docker pull playmobils/android-sdk:23 Android Native Development Kit (NDK) docker pull playmobils/android-ndk:14b Additional tools that may missing docker pull playmobils/android https://github.com/PlayMOBils/android-environment 14
  • 15. # Oracle JDK 8 # Pull base image. FROM debian:jessie # Set the locale, avoid warnings in regular expressions RUN apt-get update && apt-get install -qqy --no-install-recommends locales && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* /var/cache/debconf/*-old && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 # Define commonly used JAVA_HOME variable ENV JAVA_HOME /usr/lib/jvm/java-8-oracle # Install Deps # - http://www.oracle.com/technetwork/java/javase/jre-8-readme-2095710.html RUN echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main | tee /etc/apt/sources.list.d/webupd8team-java.list && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && apt-get update && echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && apt-get -qqy --no-install-recommends install oracle-java8-installer unzip && rm -rf ...
  • 16. # Android SDK FROM playmobils/oracle-jdk:8 ARG DEBIAN_FRONTEND=noninteractive ENV SDK_HOME /usr/local # Prerequisite packages libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 RUN dpkg --add-architecture i386 && apt-get -qq update && apt-get install -qqy --no-install-recommends curl libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old ENV ANDROID_HOME "${SDK_HOME}/sdk" ENV PATH "$PATH:${ANDROID_HOME}/tools" # Accept License RUN mkdir -p $ANDROID_HOME/licenses/ && echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license && echo "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_HOME/licenses/android-sdk-preview-license ENV VERSION_SDK_TOOLS "25.2.5" ENV VERSION_BUILD_TOOLS "23.0.3" ENV VERSION_TARGET_SDK "23" ENV SDK_PACKAGES "build-tools-${VERSION_BUILD_TOOLS},android-${VERSION_TARGET_SDK}, addon-google_apis-google-${VERSION_TARGET_SDK},platform-tools,extra-android-m2repository,extra-android-support, extra-google-google_play_services,extra-google-m2repository" ENV ANDROID_TOOLS_URL http://dl.google.com/android/repository/tools_r${VERSION_SDK_TOOLS}-linux.zip RUN curl -L "${ANDROID_TOOLS_URL}" -o tools.zip && unzip /tools.zip -d ${ANDROID_HOME} && rm -vrf /tools.zip RUN (while [ 1 ]; do sleep 5; echo y; done) | ${ANDROID_HOME}/tools/android update sdk no-ui all filter ${SDK_PACKAGES}
  • 17. # Android NDK FROM playmobils/android-sdk:23 ARG DEBIAN_FRONTEND=noninteractive ENV SDK_HOME /usr/local # Install dependencies RUN dpkg --add-architecture i386 && apt-get -qq update && apt-get -qqy install --no-install-recommends file && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old ENV ANDROID_NDK_VERSION r14b ENV ANDROID_NDK_URL http://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip # Download and unzip Android NDK RUN curl -L "${ANDROID_NDK_URL}" -o android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip && unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip -d ${SDK_HOME} && rm -rf android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip ENV ANDROID_NDK_HOME ${SDK_HOME}/android-ndk-${ANDROID_NDK_VERSION} ENV PATH ${ANDROID_NDK_HOME}:$PATH
  • 18. # Add some missing dependencies FROM playmobils/android-ndk:14b ARG DEBIAN_FRONTEND=noninteractive # How to use # In order to use it, you need to run it with: # docker run -v <path to your source>:/src playmobils/android <file to run> # The command above mounts your directory to where the container expects the source to be and builds it. # Install dependencies RUN apt-get -qq update && apt-get -qqy install --no-install-recommends gawk bc make git zip && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/* /var/cache/debconf/*-old # User Sources for Android SDK Manager, to avoid any warnings RUN echo "count=0" > ~/.android/repositories.cfg
  • 20. | © Atos docker run -it -v $PWD/osmo:/osmo playmobils/android-ndk:r14b # cd osmo/Android # ./gradlew cleanAll # ./gradlew buildNative # ./gradlew assembleRelease interactive terminal mount volume commands to run inside docker Build Failed: The input device is not a TTY. “You cannot have interactive console!” 20 open an interactive console with docker and run all build commands like we do locally
  • 21. | © Atos docker run -i -v $PWD/osmo playmobils/android-ndk:r14b sh scripts/android/build.sh Keep STDIN open even if not attached mount volume a bash file containing all build commands Build Failed: exec: "scripts/android/build.sh": stat scripts/android/build.sh: no such file or directory 21 we need a single build command
  • 22. | © Atos docker run -i -v $PWD/osmo -w /osmo playmobils/android-ndk:r14b sh scripts/android/build.sh Keep STDIN open even if not attached mount volume a bash file containing all build commands Build timed out (after 3 minutes). Marking the build as aborted. workspace Jenkins configure: “Remove the build timeout if task doesn’t respond after 3 minutes” 22 use workspace in order to navigate in proper location in container
  • 23. | © Atos Build Failed: Gradle cannot read the environment variables that defined in dockerfiles. ie $ANDROID_HOME, $ANDROID_NDK_HOME 23 single build command with workspace docker run -i -v $PWD/osmo -w /osmo playmobils/android-ndk:r14b sh scripts/android/build.sh Keep STDIN open even if not attached mount volume a bash file containing all build commands workspace
  • 24. | © Atos Define them in local.properties, read them from there #!/bin/bash cd OSMO/Android # create a local.properties file with ndk and sdk in order to used by gradle echo "sdk.dir=$ANDROID_HOME" > local.properties echo "ndk.dir=$ANDROID_NDK_HOME" >> local.properties proxyArgs="-Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>" echo -e "n ------------- START BUILD ------------- n" ./gradlew $proxyArgs allCleanBuildReleaseApk echo -e "n ------------- END BUILD ------------- n" echo -e "n ------------- START TESTS ------------- n" ./gradlew $proxyArgs test # run the unit tests echo -e "n ------------- END TESTS ------------- n" 24
  • 25. | © Atos We download gradle wrapper in each run... We can add the gradle download step in a dockerfile and use docker cache for that! Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................... Unzipping /usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7/gradle-2.14.1-all.zip to /usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7 Set executable permissions for: /usr/local/gradle-2.14.1/wrapper/dists/gradle-2.14.1-all/4cj8p00t3e5ni9e8iofg8ghvk7/gradle-2.14.1/bin/gradle To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html. 25
  • 26. | © Atos Local dockerfile for gradle dependencies FROM playmobils/android:latest COPY gradlew gradlew COPY gradle/ gradle COPY gradle.properties gradle.properties RUN chmod 755 gradlew # Run gradle once to download dependencies RUN ./gradlew -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port> 26
  • 27. | © Atos Lesson learned with local dockerfile Build docker build -t playmobils/osmo OSMO/Android Dockerfile must be on the root level of project in order to access files in it. We can improve build time by using dockerignore and ignore files not needed for building our dockerfile. 27
  • 28. | © Atos Builded docker images need a lot of space!!! - about 5GB, our repository - Docker images downloaded: - Suggested 30GB Trying to rebuild Builder machine with docker run out of space!!! REPOSITORY TAG IMAGE ID CREATED SIZE playmobils/osmo latest 19b78d68ee15 6 weeks ago 4.57 GB <none> <none> 6f3a5e8e76e1 6 weeks ago 4.57 GB playmobils/android latest af3b4e8d0d15 6 weeks ago 4.35 GB older state of image layers 28
  • 29. | © Atos if [[ $(docker ps -qa --no-trunc --filter "status=exited") ]]; then echo -e "n Delete old unused containers.n" docker rm $(docker ps -qa --no-trunc --filter "status=exited") else echo -e "n No containers for cleanup.n" fi 29 Clean docker containers after or before each build docker run --rm -i -v $PWD/osmo playmobils/android-ndk:r14b sh scripts/android/build.sh
  • 30. | © Atos - Solution 1: Jenkins user be a root user. - we don’t even want to try this one When building in docker we build as root user - Problem: Jenkins user cannot delete “root” files it has NO PERMISSIONS… - Solution 2: Find a way to build in docker with jenkins user. - use our local dockerfile to define the build user - change permissions of running gradle file - build with this user 30 Cannot create file/directory.
  • 31. | © Atos Local dockerfile for gradle dependencies FROM playmobils/android:latest ENV BUILD_USER jenkins_user RUN useradd -ms /bin/bash -u 1001 $BUILD_USER WORKDIR /home/$BUILD_USER COPY gradlew gradlew COPY gradle/ gradle COPY gradle.properties gradle.properties RUN chmod 755 gradlew && chown $BUILD_USER: gradlew && chown $BUILD_USER: gradle.properties && chown -R $BUILD_USER: gradle USER $BUILD_USER RUN ./gradlew # Run gradle once to download dependencies 31
  • 33. | © Atos We noticed that failed statuses from docker not passed in Jenkins 33 ./gradlew $proxyArgs allCleanBuildReleaseApk; gradlew_return_code=$? if (( gradlew_return_code != 0 )); then echo "GRADLE BUILD FAILED!" exit 1 fi
  • 34. | © Atos ▶ Created a folder for GRADLE_HOME in the host machine ▶ Passed this folder as volume to docker – Build time dropped to 9 min – We noticed a couple of problems though that are due to fileHashes.lock but this only happens when CI and release run in parallel Cache the .gradle dependencies 34 docker run --rm -i -v $GRADLE_HOME:/home/jenkins_user/.gradle -v $PWD/osmo playmobils/android-ndk:r14b sh scripts/android/build.sh
  • 35. | © Atos ▶ Save them to a file ▶ Pass this parameters in docker Jenkins parameters needed inside docker 35 docker run --rm -i --env-file=env_vars.txt -v $GRADLE_HOME:/home/jenkins_user/.gradle -v $PWD/osmo playmobils/android-ndk:r14b sh scripts/android/build.sh env | grep GIT_ > env_vars.txt
  • 36. | © Atos ▶ Changed all docker images to use the version tag – SDK: playmobils/android-sdk:26 – NDK: playmobils/android-ndk:26_14b – Tools: playmobils/android:26_14b – Local: playmobils/osmo:26_14b Build for different API versions 36 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE playmobils/osmo 26_14b 6c47fdd2ad7a 8 days ago 5.09GB playmobils/osmo 27_14b d2b7addfed45 10 days ago 5.09GB playmobils/android 27_14b 495a6cb3a3ab 10 days ago 4.84GB playmobils/android 26_14b f5609b45b666 10 days ago 4.84GB
  • 37. Putting it all together
  • 38. | © Atos VERSION=26_14b or VERSION=27_14b - docker pull playmobils/android:$VERSION - docker build -t playmobils/osmo:$VERSION OSMO/Android - docker run --rm -i --env-file=env_vars.txt -v $PWD:$DWORKSPACE -v $GRADLE_HOME:/home/jenkins_user/.gradle -w /home/jenkins_user/osmo/ playmobils/osmo:$VERSION /bin/bash scripts/android/BuildAndroidApp.sh 38 Full Jenkins shell script
  • 39. some successful basic commands First & second successful build After manually deleting files two in a row builds without any intervene user jenkins build success 39
  • 40. 30-40 min the image is not downloaded. 10-20 min the image is present. 9-13 min with the cache usage Build time diagram
  • 41. | © Atos What we learned! ▶ Docker may need more disk space than expected. ▶ Dockerfiles and the kernel used for base images is minimal without the essential tools be prepared to add anything missing from your build. ▶ A dockerfile that copy / add external files during build have to be in root directory (symbolic links or relative paths to parents are not accepted). ▶ In jenkins you cannot build as root, create your jenkins user in dockerfile. ▶ In jenkins you don't have interactive console use a single line script including your code. ▶ When you have dependable dockerfiles pulling / building the latest doesn't mean that changes in other files will pulled / build. 41
  • 42. | © Atos References - https://www.docker.com/ - https://docs.docker.com/ - http://blog.zot24.com/tips-tricks-docker/ - https://jenkins-ci.org/ 42 - https://github.com/PlayMOBils/android-environment - https://hub.docker.com/r/playmobils/ Dockerfiles and images:
  • 44. © Atos Thank you! Mando Stamelaki software engineer | mobile application developer adamantia-eleni.stamelaki@atos.net