The lightest configuration of Jenkins + docker + dockerfile Maven plugin + harbor CI / CD spring boot project

explain

This paper is only for future reference, recording some key steps and stepping on the pit

Dockerfile Maven plugin building image 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} image warehouse address
${docker.image.prefix} image library prefix / distinguished item classification
${project.artifactId} package Id / unique image name
1  <properties>
2         <java.version>8</java.version>
3         <docker.image.prefix>yourprefix</docker.image.prefix>
4         <docker.repository>yourrepositoryurl</docker.repository>
5     </properties>
Image warehouse configuration

 

maven configuration in jenkins setting.xml - set the address and account password to log in to harbor

You need to push the image in the previous step

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 creates a new job and builds it with maven

Connect git

 

 

Plug in version number generates build version number

${BUILD_DATE_FORMATTED,"yyyyMMdd"}.${BUILDS_TODAY}

 

 

Execute maven build command

clean package -Dmaven.test.skip=true -P dev

 

Use the version number tag to create a new image and push it to harbor

Execute the script to push the image to the private registry and report the error without permission

 

 

 

 

Solution: login private registry is required (execute login command in Jenkins container)

After successful execution, the config.json file will be generated in the root/.docker folder (with the credentials of login private registry)

 

ssh specifies the server to pull the image and run - plug in Publish Over SSH

 




Keywords: Java Docker Maven jenkins

Added by matthewc on Fri, 20 Dec 2019 16:06:33 +0200