Ubuntu下搭建jenkins与docker持续集成
安装 Docker
安装 JDK 环境
安装 Android SDK
安装 Android NDK
安装 Gradle
安装 git
本文中操作环境已经是Ubuntu16.04,所以就跳过1、2步骤。而安装Docker可以到
Ubuntu16.04安装Docker查看。
1.使用 Dockerfile 制做Ubuntu16.04镜像
FROM scratch
ADD ubuntu-xenial-core-cloudimg-amd64-root.tar.gz /
# a few minor docker-specific tweaks
# see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap
RUN set -xe \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L40-L48
&& echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
&& chmod +x /usr/sbin/policy-rc.d \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L54-L56
&& dpkg-divert --local --rename --add /sbin/initctl \
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L71-L78
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L85-L105
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L109-L115
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L118-L130
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
\
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L134-L151
&& echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
# delete all the apt list files since they're big and get stale quickly
RUN rm -rf /var/lib/apt/lists/*
# this forces "apt-get update" in dependent images, which is also good
# enable the universe
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
# make systemd-detect-virt return "docker"
# See: https://github.com/systemd/systemd/blob/aa0c34279ee40bce2f9681b496922dedbadfca19/src/basic/virt.c#L434
RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container
# overwrite this with 'CMD []' in a dependent Dockerfile
CMD ["/bin/bash"]
下载 ubuntu-xenial-core-cloudimg-amd64-root.tar.gz
放到和Dockerfile同一个文件夹下,执行docker build命令:
$ docker build -t ubuntu16.04:v1 .
Sending build context to Docker daemon 2.048 kB
...
等待完毕!
$ docker images
可以看到ubuntu16.04:v1镜像
2.启动ubuntu16.04镜像
$ docker run --name ubuntu -i -t ubuntu16.04:v1
root@af8bae53bdd3:/#
root@af8bae53bdd3:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
3.Ubuntu16.04安装Oracle JDK
1.去oracle官网下载。也可以使用安装包在你执行这个命令时所在的文件夹位置。
wget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
2.解压
tar -zxvf jdk-8u111-linux-x64.tar.gz
3.移动到自己想放的位置:
mkdir /usr/lib/jdk
mv jdk1.8.0_111 /usr/lib/jdk/jdk1.8
4.设置环境变量:
方案一:修改全局配置文件,作用于所有用户:
vim /etc/profile
export JAVA_HOME=/usr/lib/jdk/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=.:${JAVA_HOME}/bin:$PATH
方案二:修改当前用户配置文件,只作用于当前用户:vim ~/.bashrc 设置与上一样
5.使修改的配置立刻生效:执行source /etc/profile
或者 source ~/.bashrc
6.检查是否安装成功:java -version
mkdir "$ANDROID_HOME/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
4.Ubuntu16.04安装Android SDK
1.下载地址:https://developer.android.com/studio/index.html#downloads使用wget 去官方下载最新的linux下android SDK包
wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
2.android sdk 工具包的一些命令行工具是基于32位系统的,在64为平台运行32程序必须安装 i386 的一些依赖库,方法如下:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1
3.解压
tar xvzf android-sdk_r24.4.1-linux.tgz
4.移动到自己想放的位置:
mkdir /usr/lib/android-sdk
mv android-sdk-linux /usr/lib/android-sdk
5.设置环境变量
编辑 .profile 或者 .bash_profile,参照jdk环境变量设置
export ANDROID_HOME=/usr/lib/android-sdk/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
6.使修改的配置立刻生效:执行source /etc/profile
或者 source ~/.bashrc
7.检查是否安装成功:
android list sdk --all
输出:
1- Android SDK Tools, revision 24.4.1
2- Android SDK Platform-tools, revision 21
3- Android SDK Build-tools, revision 21.1.2
4- Android SDK Build-tools, revision 21.1.1
5- Android SDK Build-tools, revision 21.1
6- Android SDK Build-tools, revision 21.0.2
7- Android SDK Build-tools, revision 21.0.1
8- Android SDK Build-tools, revision 21
9- Android SDK Build-tools, revision 20
10- Android SDK Build-tools, revision 19.1
11- Android SDK Build-tools, revision 19.0.3
12- Android SDK Build-tools, revision 19.0.2
13- Android SDK Build-tools, revision 19.0.1
14- Android SDK Build-tools, revision 19
15- Android SDK Build-tools, revision 18.1.1
16- Android SDK Build-tools, revision 18.1
17- Android SDK Build-tools, revision 18.0.1
18- Android SDK Build-tools, revision 17
19- Documentation for Android SDK, API 21, revision 1
20- SDK Platform Android 5.0.1, API 21, revision 2
21- SDK Platform Android 4.4W.2, API 20, revision 2
22- SDK Platform Android 4.4.2, API 19, revision 4
23- SDK Platform Android 4.3.1, API 18, revision 3
24- SDK Platform Android 4.2.2, API 17, revision 3
....
这里包括不同的Android API 版本和不同的构建工具,选择你想要安装项目的序号,这里我想安装 build tools 19.1 ,build tools 21 及 android 4.2.2以上的SDK所以选择序号 1,2,3,20,21,22,23
android update sdk -u -a -t 1,2,3,10,20,21,22,23
5.Ubuntu16.04安装Android NDK
1.下载地址:https://developer.android.com/ndk/downloads/index.html
wget -c http://dl.google.com/android/ndk/android-ndk-r14b-linux-x86_64.zip
2.解压
unzip android-ndk-r14b-linux-x86_64.zip
3.移动到自己想放的位置:
mkdir /usr/lib/ndk
mv ndk-r14b /usr/lib/ndk
4.设置环境变量
编辑 .profile 或者 .bash_profile,参照jdk环境变量设置
export ANDROID_NDK=/usr/lib/ndk/ndk-r14b
export PATH=$ANDROID_NDK:$PATH
5.使修改的配置立刻生效:执行source /etc/profile
或者 source ~/.bashrc
6.检查是否安装成功:
ndk-build -C
若返回下面的信息表示NDK有效