spotify maven docker plugin fails when executing 'mvn clean install'

1.2k Views Asked by At

My goal is to build a dockerized java application using Spotify's dockerfile-maven-plugin but I cannot get it to succeed. When building the same application via docker cli (docker build . --build-arg APP_NAME=<app_name> --build-arg APP_VERSION=<app_version>) it works as expected and the image is push to the local registry, which convinces me that docker is well configured.

When executing mvn clean install it fails after trying - IMO - to interact with docker using the corporate proxy requesting the unix://localhost:80. If I do the clean and install goals in sequence but separately the same happens but, strangely enough, it does not occur when only executing mvn install with the package already built. In this case the process is successful - The execution is successful, the image is created and pushed to the local registry.

Can someone point me to where the issue might be and how to setup the environment so that mvn clean install works as expected? I tried searching the plugin documentation and for similar cases but found none. Thank you.

A little context:

Company restricts all laptop communications, even to internal content, to go through the companies proxies. This configuration is set both in Maven (in ~/.m2/setttings.xml file) and in docker ( file /etc/systemd/system/docker.service.d/http-proxy.conf).

~/.m2/settings.xml relevant section:

(...)
  <proxies>
    <proxy>
      <id>proxy-01</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy-01-redacted_ipaddress</host>
      <port>80</port>
      <nonProxyHosts>localhost</nonProxyHosts>
    </proxy>
  </proxies>
(...)

/etc/systemd/system/docker.service.d/http-proxy.conf content:

[Service]
Environment="HTTP_PROXY=http://proxy-01-redacted_ipaddress:80"
Environment="HTTPS_PROXY=http://proxy-01-redacted_ipaddress:80"
Environment="NO_PROXY=localhost,127.0.0.1"

The DOCKER_HOST environment is not defined but docker ps and the remaining docker cli commands work as expected.

The application itself, using mvn compiles correctly and from the java perspective everything works as expected (tested with mvn package) but when I modify the pom.xml file to include the plugin the final result is not the expected one:

The pom.xml added config:

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.3</version>
                <executions>
                    <execution>
                        <id>build-image</id>
                        <phase>install</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <repository>${project.artifactId}</repository>
                            <tag>${project.version}</tag>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                    <buildArgs>
                        <APP_NAME>${project.artifactId}</APP_NAME>
                        <APP_VERSION>${project.version}</APP_VERSION>
                    </buildArgs>
                </configuration>
            </plugin>

(I've tried more recent versions of the plugin but the behaviour is the same).

The various execution output:

  • mvn clean install -
[INFO]
[INFO] --- dockerfile-maven-plugin:1.4.3:build (build-image) @ hipster ---
[INFO] Building Docker context /home/ubuntu/dev/hipster
[INFO]
[INFO] Image will be built as hipster:22.1_rc004
[INFO]
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not build image
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:185)
    at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:105)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:252)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:241)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    (...)
    Caused by: com.spotify.docker.client.exceptions.DockerRequestException: Request error: GET unix://localhost:80/version: 400, body: <html>
<head>
        <title>Request Error</title>
        <meta name="author" content="JackJonas" version="082009">
        <meta name="description" content="Error Template">
        <style type="text/css">
                html { font-size:100%; /* IE Hack */ margin:0; padding:0; height:100%; }
                body { font-size:14px; background: #FFFFFF; font-family:  Arial, Verdana, Tahoma, Helvetica; margin:0; padding:0; height:100%; }
                a:link { color: blue; }
                a:visited { color: blue; }
(...)
This is the proxy html response when a invalid request is received.
(---)
<br><br><br>
</div>
</center>
</body>
</html>
(...)
Caused by: com.spotify.docker.client.shaded.javax.ws.rs.BadRequestException: HTTP 400 Bad Request
(...)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:20 min
[INFO] Finished at: 2022-05-17T11:30:38Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.3:build (build-image) on project hipster: Could not build image: Request error: GET unix://localhost:80/version: 400, body: <html>
(...)
0

There are 0 best solutions below