Explanation
This article is only for the convenience of future reference, record some of the key steps and step on the situation pit.
Construction dockerfile-maven-plugin mirroring configuration
<plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.10</version> <executions> <execution> <id>default</id> <goals> <goal>build</goal> <goal>push</goal> </goals> </execution> </executions> <configuration> <!--<username>***</username> <password>*******</password>--> <repository>${docker.repository}/${docker.image.prefix}/${project.artifactId}</repository> <tag>latest</tag> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> </configuration> </plugin>
Parameter Description
$ {docker.repository} mirror warehouse address
$ {docker.image.prefix} image library prefix / classification item distinguish
$ {project.artifactId} packet Id / image name unique
1 <properties> 2 <java.version>8</java.version> 3 <docker.image.prefix>yourprefix</docker.image.prefix> 4 <docker.repository>yourrepositoryurl</docker.repository> 5 </properties>
jenkins in maven configuration settings login harbor setting.xml- address and account password
Previous push in the mirror when needed
File Location: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/mvn3.6.3/conf
New Server Node
<server> <id>yourrepositoryurl</id> <username>admin</username> <password>*******</password> </server>
dockerfile Configuration
FROM openjdk:8u181-jdk-alpine
ARG workdir=/app
VOLUME ${workdir}
WORKDIR ${workdir}
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
System Settings - Global tool configuration jdk maven
jenkins新建一个job 使用maven构建
连接git
插件version number生成构建版本号
${BUILD_DATE_FORMATTED,"yyyyMMdd"}.${BUILDS_TODAY}
执行maven构建命令
clean package -Dmaven.test.skip=true -P dev
使用版本号tag新的镜像并push到harbor上
执行脚本push镜像到私有registry报没有权限的错
解决方法:需要login私有registry(在Jenkins容器内执行login命令)
执行成功后会在root/.docker文件夹下生成config.json文件(含有login私有registry的凭证)
ssh指定服务器pull镜像并run - 插件Publish Over SSH