DevOps Lab Setup - Jenkins and Docker for Auto Android App build and Lint code check

I have used Jenkins extensively few years ago. We used it for auto code check (compile error check, static code analyse, automate test report) and scheduled build.

I enjoyed the time of using Jenkins, but not aware of the concept of DevOps which is kind of popular these days until recently. And this week, I decided to migrate my AWS gitlab server to US based VPS from BuyVM (the 4096GB one) which is amazingly cheap for their service quality. I have used BuyVM for few years for other services and they have never let me down.

Docker is amazing technology always be mentioned when people talk about DevOps. When I decide to set Jenkins up for my CI/CD lab, I thought Jenkins + Docker would be a great solution for easy maintenance and future scale. However, I only aware of the concept of Docker and had some hello-world experience, that's all. Can I make it?

I went through this process yesterday, and get my jenkins with docker master/slave setup in around 8 hours! I was exhausted for doing this after work but it was tons of fun, and the result was totally worth it!

First of all, I setup a Jenkins instance in Debian 7 on my home-lab VM, and it's fairly easy :

wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -  
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'  
sudo apt-get update  
sudo apt-get install jenkins  

I tested for a while and mess around the settings to see if everything works well, and It turned out perfect.
Then I started research on Docker Jenkins solutions, and found terms like DooD, DinD, etc.
One video caught my eye when I search Docker and Jenkins on Youtube:Run Jenkins in Slave Master Config in Docker and It is exactly what I what. I followed along the video and he's website.

However, the first problem I met was how to install docker on Debian 7 with kernel 3.2. It's not hard to do but it's confusing due to lack of error sign. when I installed Docker and lunched it as daemon, there's was no notification say kernel need update and docker quit etc. It's just gone, and all other docker command report no daemon running. I found out only after I checked docker log.

Debian 7 kernel update:

#add deb http://ftp.debian.org/debian/ wheezy-backports main non-free contrib 
sudo apt-get install -t wheezy-backports linux-image-amd64  

Docker Install:

sudo apt-get update  
sudo apt-get install apt-transport-https ca-certificates  
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D  
# Add deb https://apt.dockerproject.org/repo debian-wheezy main
sudo apt-get update  
sudo apt-get install docker-engine  

After all these, it's time to follow the video and setup Jenkins. The setup up process was fairly easy, noting tricky. However the architecture of this setup is beyond my knowledge of Docker best practice - it's store all key config and data in a docker data container mapped host volume which I feel is not safe and convenient for easier backup and access settings. Other than that this is prefect for my needs.
PS. after more reseatch

Next step is setup android build env in slave docker, this was a challenge and where I spent most of my time in the whole process.

At beginning, I attached to one slave container, and downloaded Oracle JAVA, Android SDK. Then I found the container lack of some key system package to preform the build, and apt-get was not available within the container. I screwed!

2 hours later....

I started writing my first Dockerfile based on the jenkins image I was using.

FROM appcontainers/jenkins:debian

MAINTAINER Edison "e@edison.nz"

# Install Deps
RUN dpkg --add-architecture i386 && apt-get update && apt-get install -y --force-yes expect git wget libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 lib32z1 python curl && apt-get clean && rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Cleaning
RUN apt-get clean  

The problem for this solution was I still have to manually cp all the JAVA bins and Android SDK into the container, but it works!

Still need lots of work to optimise the dockerfile and docker host add supervisor etc. but it's good enough for today and that's the work for another day.

Jenkins Main Page

Jenkins Slave Nodes View

Android build Job Overview with final APK

Android Lint Issues Report

comments powered by Disqus