0

I've followed this tutorial: https://www.baeldung.com/spring-boot-azure

However, although I set the credentials in settings.xml for maven, I still get this error:

[WARNING] Failed to push apiefrontdoor.azurecr.io/apiefrontdoor, retrying in 10 seconds (5/5).
[INFO] Pushing apiefrontdoor.azurecr.io/apiefrontdoor
The push refers to repository [apiefrontdoor.azurecr.io/apiefrontdoor]
c7f1d24c6c55: Preparing
a46d8ce138df: Preparing
42fd82c87bc8: Preparing
ceaf9e1ebef5: Preparing
9b9b7f3d56a0: Preparing
f1b5933fe4b5: Waiting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:36 min
[INFO] Finished at: 2020-06-02T18:24:11-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (default-cli) on project apiefrontdoor: Exception caught: unauthorized: authentication required -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (default-cli) on project apiefrontdoor: Exception caught
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught
    at com.spotify.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:151)
    at com.spotify.docker.BuildMojo.execute (BuildMojo.java:329)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: com.spotify.docker.client.exceptions.DockerException: unauthorized: authentication required
    at com.spotify.docker.client.AnsiProgressHandler.progress (AnsiProgressHandler.java:55)
    at com.spotify.docker.Utils$DigestExtractingProgressHandler.progress (Utils.java:191)
    at com.spotify.docker.client.ProgressStream.tail (ProgressStream.java:77)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2754)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2738)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.apieproject</groupId>
    <artifactId>apiefrontdoor</artifactId>
    <version>0.0.1</version>
    <name>frontdoor</name>
    <description>APIE Project Landing Project</description>

    <properties>
       <jib-maven-plugin.version>2.3.0</jib-maven-plugin.version>
       <azure.containerRegistry>apiefrontdoor</azure.containerRegistry>
       <docker.image.prefix>apiefrontdoor.azurecr.io</docker.image.prefix>
       <java.version>1.8</java.version>
    </properties>

    <dependencies>
        ....
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
              <artifactId>jib-maven-plugin</artifactId>
              <groupId>com.google.cloud.tools</groupId>
              <version>${jib-maven-plugin.version}</version>
              <configuration>
                 <from>
                     <image>mcr.microsoft.com/java/jre:8-zulu-alpine</image>
                 </from>
                 <to>
                     <image>${docker.image.prefix}/${project.artifactId}</image>
                 </to>
              </configuration>
            </plugin>
            <plugin>
               <groupId>com.microsoft.azure</groupId>
               <artifactId>azure-webapp-maven-plugin</artifactId>
               <version>1.9.1</version>
               <configuration>
                  <authentication>
                     <serverId>azure-auth</serverId>
                  </authentication>
                  <resourceGroup>apieproject</resourceGroup>
                  <appName>apiefrontdoor</appName>
                  <region>Central US</region>
                  <containerSettings>
                     <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                  </containerSettings>
                  <appServicePlanName>ASP-apieproject-ae27 (P1v2: 1)</appServicePlanName>
                  <appSettings>
                     <property>
                        <name>PORT</name>
                        <value>8080</value>
                     </property>
                  </appSettings>
                 </configuration>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <serverId>${azure.containerRegistry}</serverId>
                    <registryUrl>https://${docker.image.prefix}</registryUrl>
                    <dockerDirectory>docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>


And here is my settings.xml

<servers>

    <server>
     <id>azure-auth</id>
      <configuration>
         <client>my-client</client>
         <tenant>my-tenant</tenant>
         <key>my-key</key>
         <environment>AZURE</environment>
      </configuration>
   </server>
   <server>
        <id>apiefrontdoor</id>
        <username>my-username</username>
        <password>my-password</password>
    </server>
  </servers>

I can independently login to the Azure Container Registry using 'docker login' so that's not a credential issue. But although the project builds successfully, I can't push it to the same registry. Please assist.

amelongo
  • 93
  • 11

2 Answers2

0

Most probably, the problem is the id in the server for settings.xml file and docker.image.prefix in pom.xml file. It shoudld exactly match. Read example from url to know more about it.

Atul
  • 1,116
  • 1
  • 10
  • 20
  • I check values are same.But didn't help. Authentication suppliers used are: ConfigFileRegistryAuthSupplier, FixedRegistryAuthSupplier. Can that be the issue? – amelongo Jun 04 '20 at 02:08
  • [INFO] --- docker-maven-plugin:1.2.2:push (default-cli) @ apiefrontdoor --- [INFO] Pushing apiefrontdoor.azurecr.io/apiefrontdoor The push refers to repository [apiefrontdoor.azurecr.io/apiefrontdoor] [WARNING] Failed to push apiefrontdoor.azurecr.io/apiefrontdoor, retrying in 10 seconds (1/5). Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:push (default-cli) on project apiefrontdoor: Exception caught: unauthorized: authentication required – amelongo Jun 04 '20 at 02:12
  • In the sample above, pom.xml contains apiefrontdoor.azurecr.io whereas in settings.xml file contains apiefrontdoor Can you trying adding above in the settings.xml file and try again? – Atul Jun 04 '20 at 09:41
0

I was able to resolve this issue per this discussion trail

  • As stated in the discussion, an Azure Container Registry service principal should be created with the permissions AcrPush and AcrImageSigner. Therefore, please don't use the container registry access keys for this.
  • Afterward, instead of running a combo of build and push like this:

          mvn docker:build -DpushImage
    
  • I separated these, after login to docker registry of course, the command into two distinct ones:

       a) mvn docker:build
       b) docker push <repo_name>.azurecr.io/<repo_name>:latest
    

Note: 'latest' was configured as my tag. If you used a different tag for versioning, please replace 'latest' with the latest version you just build

amelongo
  • 93
  • 11