jenkins中的slave镜像制作
需求
jdk 1.8
maven 3
docker 可以执行docker文件
kubectl 可以执行kubectl命令
制作步骤
目录结构
# tree -L 1
.
├── apache-maven-3.5.4
├── apache-maven-3.5.4-bin.tar.gz
├── docker
├── Dockerfile
├── Dockerfile.1
├── Dockerfile.2
├── Dockerfile.3
├── jdk1.8.0_91
├── jdk-8u91-linux-x64.gz
├── jenkins-slave
├── kubectl
├── settings.xml
└── slave.jar
dockerfile
FROM centos:7
RUN echo "${TIMEZONE}" > /etc/timezone \
&& echo "$LANG UTF-8" > /etc/locale.gen \
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
COPY jenkins-slave /usr/local/bin/jenkins-slave
COPY slave.jar /usr/share/jenkins/
RUN chmod a+x /usr/local/bin/jenkins-slave
RUN yum install -y curl net-tools jq unzip zip git ca-certificates dialog iputils sysstats wget telnet
COPY docker /usr/bin/docker
COPY kubectl /usr/bin/kubectl
COPY jdk1.8.0_91 /opt/jdk1.8.0_91/
COPY apache-maven-3.5.4 /opt/apache-maven-3.5.4/
RUN chmod a+x /usr/bin/docker
RUN chmod a+x /usr/bin/kubectl
ENV JAVA_HOME /opt/jdk1.8.0_91/
ENV MAVEN_HOME /opt/apache-maven-3.5.4
ENV PATH "$PATH:/usr/local/bin:$JAVA_HOME/bin:$MAVEN_HOME"
ADD settings.xml /root
ADD settings.xml /home/jenkins
WORKDIR /root
ENTRYPOINT ["jenkins-slave"]
Dockerfile说明
- slave.jar jenkins的slave运行的jar包
- jenkins-slave jenkins的slave运行的endpoint
- yum install 安装基础软件包
- COPY docker 拷贝docker命令
- COPY kubectl 拷贝kubectl命令
- COPY jdk1.8 安装jdk
- COPY apache-maven 安装maven
- RUN chmod 添加执行权限
- ENV 添加环境变量
- ADD settings.xml 添加maven配置