5

Using Spring Boot 2.4.0, I'm trying to configure the spring-boot:build-image task to push an image to my private GitHub container registry.

I used these instructions to configure my POM as follows:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <name>ghcr.io/abc/${project.artifactId}:${project.version}</name>
                        <publish>true</publish>
                    </image>
                    <docker>
                        <publishRegistry>
                            <username>abc</username>
                            <token>mytoken</token>
                            <url>https://ghcr.io</url>
                        </publishRegistry>
                    </docker>
                </configuration>
            </plugin>

When I execute the spring-boot:build-image task, it builds the image but I get the following error when it tries to push:

[INFO] Successfully built image 'ghcr.io/abc/def:1.5.0'
[INFO]
[INFO]  > Pushing image 'ghcr.io/abc/def:1.5.0' 100%
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image failed: Error response received when pushing image: error parsing HTTP 405 response body: unexpected end of JSON input: "" -> [Help 1]

I can manually push the image using docker push, and I have tried doing a docker login which doesn't help either. I am also not behind any firewall or proxy.

Mike
  • 4,722
  • 1
  • 27
  • 40

1 Answers1

3

In case anyone else finds this, the problem ended up being a typo in the maven plugin configuration. I was using <token> instead of <password>. Below is the correct XML that works:

                <docker>
                    <publishRegistry>
                        <username>abc</username>
                        <password>mytoken</password>
                        <url>https://ghcr.io</url>
                    </publishRegistry>
                </docker>
Mike
  • 4,722
  • 1
  • 27
  • 40
  • 1
    I have configured a private repository without any authentication. If i don't specify the username/password fields I get an error "Invalid Docker publish registry configuration, either token or username/password must be provided". Any suggestions? – Andy Dufresne Nov 26 '21 at 12:11
  • Yeah, their source code certainly expects one or the other: https://github.com/spring-projects/spring-boot/blob/47516b50c39bd6ea924a1f6720ce6d4a71088651/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java#L158 – Mike Nov 26 '21 at 21:38
  • 1
    I'd open an issue on their GitHub page. I can't think of a reason off hand (aside from security best practices) that they would require one or the other. – Mike Nov 26 '21 at 21:39
  • 1
    Thanks for your input. I created an issue. On a related note do you have a jenkins pipeline for your project? I am trying to create one but getting blocked in creating a docker image through the pipeline. Searching for a reference pipeline script. Thanks! – Andy Dufresne Nov 29 '21 at 13:10
  • In this case I have not integrated into a Jenkins pipeline. – Mike Nov 29 '21 at 23:15