-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_android_dockerfile
192 lines (150 loc) · 7.19 KB
/
jenkins_android_dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# ====================================================================== #
# Dockerfile for Jenkins and Android project
# ====================================================================== #
# Base image
# ---------------------------------------------------------------------- #
# Jenkins master: jenkinsci/blueocean
# Jenkins agent: jenkins/jenkins
# Jenkins docker image with JDK-11 ready
#ARG JENKINS_TAG=lts-jdk11
FROM jenkins/jenkins:lts
# Author
# ---------------------------------------------------------------------- #
LABEL maintainer "[email protected]"
# set the environment variables
ENV TZ Asia/Shanghai
#ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
ARG javaUrl=https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz
ENV JAVA_URL ${javaUrl}
ENV JAVA_HOME /opt/java/openjdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
ARG GRADLE_VERSION=7.0.2
ENV GRADLE_USER_HOME /.gradle
ENV GRADLE_HOME /opt/gradle
ENV PATH ${PATH}:${GRADLE_HOME}/bin
# https://developer.android.com/studio#command-tools
ARG ANDROID_TOOLS_URL=https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip
ENV ANDROID_SDK_ROOT /opt/android-sdk
ENV ANDROID_VERSION 28
ENV ANDROID_TOOLS_VERSION 30.0.2
ENV SDKMANAGER_PROXY="--no_https --proxy=http --proxy_host=mirrors.neusoft.edu.cn --proxy_port=80"
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/platform-tools
#ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/emulator
ENV VIRTUAL_ENV=/opt/venv
ENV PATH ${PATH}:${VIRTUAL_ENV}/bin
ENV APK_PATH /opt/apkbuild/
USER root
## Install requirements
# RUN dpkg --add-architecture i386
# RUN rm -rf /var/lib/apt/list/* && apt-get update && apt-get install ca-certificates curl gnupg2 software-properties-common git unzip file apt-utils lxc procps apt-transport-https libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 -y
# support multiarch: i386 architecture
# install essential tools
# python3-dev python3-pip
RUN apt-get update \
&& apt-get --purge remove python \
&& apt-get install -y --no-install-recommends curl ca-certificates fontconfig locales unzip git wget procps vim python3-venv python3-pip \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.UTF-8 \
&& echo "root:admin" | chpasswd \
&& python3 -m venv ${VIRTUAL_ENV} \
&& echo "source ${VIRTUAL_ENV}/bin/activate" >> /etc/bash.bashrc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#ARG DEBIAN_FRONTEND=noninteractive
#RUN dpkg --add-architecture i386 && \
# apt-get update && \
# apt-get dist-upgrade -y && \
# echo 'debconf debconf/frontend select noninteractive' | debconf-set-selections && \
# apt-get install -y --no-install-recommends --assume-yes apt-utils sudo dialog && \
# apt-get install -y --no-install-recommends libncurses5:i386 libc6:i386 libstdc++6:i386 zlib1g:i386 && \
# apt-get install -y --no-install-recommends openjdk-${JDK_VERSION}-jdk && \
# apt-get install -y --no-install-recommends git curl wget unzip procps vim && \
# apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# download and install Java
RUN echo "Downloading Java..." \
&& curl -Lo jdk.tar.gz ${JAVA_URL} \
&& tar xzf jdk.tar.gz \
&& rm jdk.tar.gz \
&& mkdir -p /opt/java \
&& mv jdk-* ${JAVA_HOME}
# download and install Gradle
# https://services.gradle.org/distributions/
RUN set -o errexit -o nounset \
&& echo "Downloading Gradle..." \
&& curl -Lo gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip \
&& echo "Installing Gradle..." \
&& unzip gradle.zip \
&& rm gradle.zip \
&& mv "gradle-${GRADLE_VERSION}" "${GRADLE_HOME}/" \
# && ln --symbolic "${GRADLE_HOME}/bin/gradle" /usr/bin/gradle \
&& echo "Testing Gradle installation..." \
&& gradle --version
#RUN cd /opt && \
# wget -q https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-${GRADLE_DIST}.zip && \
# unzip gradle*.zip && \
# ls -d */ | sed 's/\/*$//g' | xargs -I{} mv {} gradle && \
# rm gradle*.zip
# .gradle and .android are a cache folders
RUN mkdir -p ${GRADLE_USER_HOME}/caches /.android \
&& chmod -R 777 ${GRADLE_USER_HOME} \
&& chmod 777 /.android
# download and install Android SDK
# https://developer.android.com/studio#command-tools
#RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools && \
# wget -q https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_TOOL_VERSION}_latest.zip && \
# unzip *tools*linux*.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && \
# mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/tools && \
# rm *tools*linux*.zip
# Download Android SDK\
RUN mkdir -p ${ANDROID_SDK_ROOT} && cd "$ANDROID_SDK_ROOT" \
&& curl -o sdk.zip $ANDROID_TOOLS_URL \
&& unzip sdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools \
&& mv cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/tools \
&& rm sdk.zip \
&& mkdir -p "$ANDROID_SDK_ROOT/licenses" || true \
&& echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_SDK_ROOT/licenses/android-sdk-license" \
&& sdkmanager --version \
&& yes | sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses \
&& sdkmanager "platforms;android-${ANDROID_VERSION}" \
&& sdkmanager "platform-tools" \
&& sdkmanager "build-tools;${ANDROID_TOOLS_VERSION}"
# Now download the android SDK stuff
#RUN $ANDROID_SDK_ROOT/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --update
#RUN $ANDROID_SDK_ROOT/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
# "platforms;android-${ANDROID_VERSION}" \
# "platform-tools"
# RUN echo $PATH
# accept the license agreements of the SDK components
# ADD license_accepter.sh /opt/
# RUN chmod +x /opt/license_accepter.sh && /opt/license_accepter.sh $ANDROID_SDK_ROOT
## Install Android SDK into Image
# ADD $GRADLE_ZIP_URL /opt/
# RUN unzip /opt/$GRADLE_ZIP -d /opt/ && rm /opt/$GRADLE_ZIP
# ADD $ANDROID_SDK_ZIP_URL /opt/
# RUN unzip -q /opt/$ANDROID_SDK_ZIP -d $ANDROID_SDK_ROOT && rm /opt/$ANDROID_SDK_ZIP
# RUN Hope Additional settings
# COPY agent.jar /opt/
# COPY entrypoint.sh /opt/
# RUN chown jenkins /opt/entrypoint.sh && chmod +x /opt/entrypoint.sh
## Install Jenkins plugin
#RUN /bin/bash -c "source /etc/profile"
#RUN echo "source /etc/profile" >> ~/.bashrc
RUN chown -R jenkins $ANDROID_SDK_ROOT \
&& mkdir -p ${APK_PATH} \
&& mkdir -p /var/jenkins_home/backup \
&& chmod -R 777 /var/jenkins_home/backup \
&& chmod -R 777 ${APK_PATH} \
&& chown -R jenkins ${APK_PATH} \
&& chown -R jenkins ${VIRTUAL_ENV}
USER jenkins
#RUN /usr/local/bin/install-plugins.sh git gradle ws-cleanup embeddable-build-status jacoco locale
RUN jenkins-plugin-cli --plugins git gradle ws-cleanup jacoco gitee thinBackup
WORKDIR $JENKINS_HOME
## Connect Jenkins agent to Jenkins master
# ARG JENKINS_JNLPURL http://10.24.61.200:8080/computer/SH-ZNZC-1/jenkins-agent.jnlp
# ARG JENKINS_KEY a555e3076e55b58579bf83cc64124fa0247c9a77e85bb064910cae534340bcb8
# ARG JENKINS_DIR /var/jenkins_home/workspace
#ENTRYPOINT "/opt/entrypoint.sh"
#RUN java -jar /opt/agent.jar -jnlpUrl ${JENKINS_JNLPURL} -secret ${JENKINS_KEY} -workDir ${JENKINS_DIR} >${JENKINS_DIR}/agent.log 2>&1 &