Skip to content

Commit b004fa1

Browse files
committed
Add Reame.md
Added Docker section to the readme.md file
1 parent 2f93bea commit b004fa1

11 files changed

+158
-0
lines changed

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Android CI tutorial for Docker and GitLab
2+
3+
The projects presents Android CI tutorial covering Docker and GitLab
4+
5+
6+
7+
## Docker Image
8+
9+
Goal: To create a Docker image that contains the Android SDK command line tools installed in it.
10+
11+
- Create a account in [Docker](https://www.docker.com/). Then go to [Docker hub](https://hub.docker.com).
12+
13+
- Next, link your Github or Bitbucket account to your Docker account.
14+
15+
![linking github account](./images/github-link-accounts.png)
16+
17+
- Then, go to Github or Bitbucket to create a new repository that contains Docker file. Because, Docker currently supports only Github and Bitbucket for creating automation builds.
18+
19+
![creating a project in Github](./images/github-project-creation.png)
20+
21+
- After creating a repository in Github or Bitbucket. Create a new file. Name the file as
22+
23+
Dockerfile
24+
25+
without any extensions.
26+
27+
![](./images/adding-dockerfile.png)
28+
29+
Here is the code for Dockerfile
30+
31+
```Docker
32+
#
33+
# GitLab CI: Android
34+
# Version: 1.0.0
35+
#
36+
# https://hub.docker.com/r/sakarsh/gitlab-ci-android-akarsh-seggemu/
37+
#
38+
39+
FROM ubuntu:18.04
40+
MAINTAINER Akarsh Seggemu <sakarshkumar@gmail.com>
41+
42+
ENV VERSION_SDK_TOOLS "3859397"
43+
44+
ENV ANDROID_HOME "/sdk"
45+
ENV PATH "$PATH:${ANDROID_HOME}/tools"
46+
ENV DEBIAN_FRONTEND noninteractive
47+
48+
RUN apt-get -qq update && \
49+
apt-get install -qqy --no-install-recommends \
50+
bzip2 \
51+
curl \
52+
git-core \
53+
html2text \
54+
openjdk-8-jdk \
55+
libc6-i386 \
56+
lib32stdc++6 \
57+
lib32gcc1 \
58+
lib32ncurses5 \
59+
lib32z1 \
60+
unzip \
61+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
62+
63+
RUN rm -f /etc/ssl/certs/java/cacerts; \
64+
/var/lib/dpkg/info/ca-certificates-java.postinst configure
65+
66+
RUN curl -s https://dl.google.com/android/repository/sdk-tools-linux-${VERSION_SDK_TOOLS}.zip > /sdk.zip && \
67+
unzip /sdk.zip -d /sdk && \
68+
rm -v /sdk.zip
69+
70+
RUN mkdir -p $ANDROID_HOME/licenses/ \
71+
&& echo "8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license \
72+
&& echo "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_HOME/licenses/android-sdk-preview-license
73+
74+
ADD packages.txt /sdk
75+
RUN mkdir -p /root/.android && \
76+
touch /root/.android/repositories.cfg && \
77+
${ANDROID_HOME}/tools/bin/sdkmanager --update
78+
79+
RUN while read -r package; do PACKAGES="${PACKAGES}${package} "; done < /sdk/packages.txt && \
80+
${ANDROID_HOME}/tools/bin/sdkmanager ${PACKAGES}
81+
```
82+
83+
The Dockerfile code contains the following,
84+
85+
- The base OS image is defined in **FROM**
86+
- The maintainer of the docker in **MAINTAINER**
87+
- The Android SDK tools is update after evey new release. With every new update the version number in the download link is updated. Having a variable **ENV VERSION_SDK_TOOLS** for the version number reduces the effort in long run for maintaining the Dockerfile.
88+
- **ENV ANDROID_HOME** is used for storing sdk folder name.
89+
- **ENV PATH** is used for storing the android sdk tools path.
90+
- **DEBIAN_FRONTEND** is used for installing the packages in Docker.
91+
- **RUN apt-get -qq update** and the consecutive commands are used to update the packages and install packages.
92+
- **RUN rm -f /etc/ssl/certs/java/cacerts;** is used for java ceritifcate.
93+
- **RUN curl -s https://dl.google.com/android/repository/sdk-tools-linux-${VERSION_SDK_TOOLS}.zip** for downloading the Android SDK tools
94+
- **RUN mkdir -p $ANDROID_HOME/licenses/** is used for creating a directory to accept Android SDK license during installation of Android SDK Tools.
95+
- **ADD packages.txt /sdk** this command adds the file packages.txt ti the sdk folder.
96+
97+
- The packages.txt contains the additional packages such as Google play services to be installed.
98+
99+
- Create a new file in the repository and name it as
100+
101+
packages.txt
102+
103+
and add the following code,
104+
105+
```Docker
106+
add-ons;addon-google_apis-google-24
107+
build-tools;26.0.2
108+
extras;android;m2repository
109+
extras;google;m2repository
110+
extras;google;google_play_services
111+
extras;m2repository;com;android;support;constraint; constraint-layout;1.0.2
112+
extras;m2repository;com;android;support;constraint; constraint-layout-solver;1.0.2
113+
platform-tools
114+
platforms;android-26
115+
```
116+
- **RUN mkdir -p /root/.android &&** is used to create a folder and the subsequent commands are used to update the Android SDK.
117+
118+
- **RUN while read -r package; do PACKAGES="${PACKAGES}${package}** is used to run the packages.txt file. Next, the packages are downloaded and installed.
119+
120+
- After the creating the Dockerfile and adding the mentioned code above. Next, go to [Docker hub](https://hub.docker.com) and click on **create a automated build**
121+
122+
![](./images/create-automate-build.png)
123+
124+
- Select the linked Github or bitbucket account to access the Github or Bitbucket repository.
125+
126+
![select the linked github account to access the github repository](./images/link-github-ro-bitbucket.png)
127+
128+
- Select the Github or Bitbucket repository.
129+
130+
![select the github repository file](./images/select-the-github-repository-in-docker.png)
131+
132+
- Add a short description for the automated build and click on create.
133+
134+
![creation of automated build in docker](./images/docker-automated-build-creation.png)
135+
136+
- Build page will be shown after completing the creation of automated build.
137+
138+
![build overview page](./images/donw-creating-automated-build.png)
139+
140+
- Next, click on **Build Settings** tab and click on **trigger** to **trigger** a build job.
141+
142+
![](./images/trigger-a-build-job.png)
143+
144+
- When the build job is completed. Click on **Build Details** to see the status of the build. **Success** indicated the build is successfully built the docker image.
145+
146+
![](./images/build-details.png)
147+
148+
## GitLab
149+
150+
151+
152+
### Tutorials
153+
154+
- [Dockerfile project](http://dockerfile.github.io/)
155+
156+
### References to Dockerfiles
157+
158+
- [dockerfiles](https://github.com/jessfraz/dockerfiles) - contains various Dockerfiles.

images/adding-dockerfile.png

151 KB
Loading

images/build-details.png

53.7 KB
Loading

images/create-automate-build.png

268 KB
Loading
41.2 KB
Loading
77.6 KB
Loading

images/github-link-accounts.png

77.3 KB
Loading

images/github-project-creation.png

69.1 KB
Loading

images/link-github-ro-bitbucket.png

149 KB
Loading
Loading

0 commit comments

Comments
 (0)