1、官方镜像
github:https://github.com/jenkinsci/jenkins
官网下载地址:https://www.jenkins.io/download/
docker官方仓库:https://hub.docker.com/r/jenkins/jenkins/tags
2、jenkins访问主机docker
1 | docker pull jenkins/jenkins:lts-alpine |
alpine镜像仓库:
https://pkgs.alpinelinux.org/packages
1 | mkdir -p /etc/docker |
2.1、Dockerfile
1 | FROM jenkins/jenkins:lts-alpine |
2.2、构建镜像
1 | docker build --build-arg dockerGid=`cat /etc/group | grep docker | cut -d ':' -f3` -t cz-jenkins:lts-alpine . |
3、jenkins-slave访问主机docker
3.1、构建Jenkins Slave镜像环境准备
构建Jenkins Slave镜像环境准备:
代码拉取:git,安装git命令
单元测试:忽略,这不是我们擅长的,如果公司有可以写进来
代码编译:maven,安装maven包
构建镜像:Dockerfile文件、docker命令(通过挂载宿主机docker)
推送镜像:docker命令(通过挂载宿主机docker)
镜像启动后支持slave: 下载官方slave.jar包(获取:http://10.40.6.213:30006/jnlpJars/slave.jar)
启动 slave.ja包:jenkins-slave启动脚步(通过参考文档URL)
maven配置文件:settings.xml (这里配置阿里云的仓库源)
获取相关文件:
Dockerfile
jenkins-slave 启动脚步
settings.xml
slave.jar
1 | mkdir -p /data/jenkins-slave && cd /data/jenkins-slave |
3.2、jenkins-slave启动脚本
1 | [root@centos7cz jenkins-slave]# vi jenkins-slave |
1 | cat jenkins-slave |
3.3、maven源配置文件settings.xml
maven源配置文件settings.xml,这里配置阿里云的源。
1 | [root@centos7cz jenkins-slave]# vi settings.xml |
1 | cat settings.xml |
3.4、Dockerfile
1 | [root@centos7cz jenkins-slave]# vi Dockerfile |
1 | FROM alpine:latest |
3.5、构建镜像
1 | docker build --build-arg dockerGid=`cat /etc/group | grep docker | cut -d ':' -f3` -t cz-jenkins-slave:lts-alpine . |
4、定制maven镜像
4.1、Dockerfile
1 | FROM alpine:latest |
为了调用protoc,一定要安装glibc
https://github.com/sgerrand/alpine-pkg-glibc
否则会碰到如下问题:
用Alpine跑了JDK8的镜像结果发现,JDK还是无法执行.后来翻阅文档才发现
Java是基于GUN Standard C library(glibc)
Alpine是基于MUSL libc(mini libc)所以Alpine需要安装glibc的库,以下是官方给出wiki
https://wiki.alpinelinux.org/wiki/Running_glibc_programs
1
2 > [ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.6.1:compile (default) on project nacos-grpc-iface: An error occurred while invoking protoc: Error while executing process.: Cannot run program "/var/jenkins_home/workspace/nacos-grpc-k8s@2/nacos-grpc-iface/target/protoc-plugins/protoc-3.12.2-linux-x86_64.exe": error=2, No such file or directory -> [Help 1]
>
1 | docker build -t czharbor.com/devops/cz-maven:3.6.3-alpine . |
1