I’m currently developing a GitLab CI/CD Pipeline which compiles, tests and builds a standard Spring Boot application. I want to package it in a docker image and publish that to the GitLab registry to use it later on. Spring Boot recently added the build-image goal to its maven plugin which also has the ability to publish the image to a registry. My problem is, that I can’t get the auth to work. I’m using a maven:3.6.3-jdk-11-slim image for the job with the docker:dind service to have access to a docker daemon. Building the image runs fine, but publishing fails. I configured the maven plugin in the project pom to use properties for auth, which will be overwritten by the CLI in my CI/CD Job as follows:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<publishRegistry>
<username>${CI_REGISTRY_USER}</username>
<password>${CI_REGISTRY_PASSWORD}</password>
<url>${CI_REGISTRY}</url>
</publishRegistry>
</docker>
</configuration>
</plugin>
Properties defined in the POM with no value (Will be filled in by CLI call):
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<CI_REGISTRY/>
<CI_REGISTRY_USER/>
<CI_REGISTRY_PASSWORD/>
</properties>
My maven CLI call in the Pipeline/Job uses the GitLab registry variables:
docker image job:
stage: Build
image: maven:3.6.3-jdk-11-slim
services:
- docker:dind
script:
- echo "java.runtime.version=11" > system.properties
- mvn spring-boot:build-image -DCI_REGISTRY=$CI_REGISTRY -DCI_REGISTRY_USER=$CI_REGISTRY_USER -DCI_REGISTRY_PASSWORD=$CI_REGISTRY_PASSWORD -Dspring-boot.build-image.imageName=SpringBootImage_${CI_JOB_ID} -Dspring-boot.build-image.publish=true
I was following the instructions via GitLab and Spring Boot documentation, but cant seem to identify my problem GitLab Registry Auth documentation Spring Boot Maven Plugin image publishing documentation
If you need further information please let me know. I appreciate any kind of directions and ideas.