Spotify dockerfile could't push image, resource is deined - spring-boot

I am using Spotify Dockerfile maven plugin like this
<plugins>
<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>myUserName</username>
<password>myPassword</password>
<repository>dockerhubUsername/dockerhubRepo</repository>
<tag>latest</tag>
<buildArgs>
<JAR_FILE>${project.artifactId}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
So whenever I build using mvn deploy I get this error
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.10:push (default) on project nepse-sim: Could not push image: denied: requested access to the resource is denied -> [Help 1]
I have specified my dockerhub username and password there in the configuration but still I am getting this error. Any help would be appreciated. Thanks

First of all, Do not put your credentials in pom.xml because this will be in git or whatever you are using. So add your credentials in settings.xml inside .m2 folder.
<server>
<id>docker.io</id>
<username>xxxxx</username>
<password>xxxxxx</password>
</server>
Change your configuration tag in pom.xml as below -
<configuration>
<repository>dockerhubUsername/dockerhubRepo</repository>
<tag>${project.version}</tag>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
Then It should work.

Related

Maven wildfly deployment with multiple servers (standalone)

in my environment I have two wildfly server where I want to deploy with the wildfly-maven-plugin.
The servers differ in the name dev01 and dev02 but have the same port 9993 and username and password.
My understanding is that the wildfly-maven-plugin support only single server deployment.
If the problem are not big enough we use a module/submodule structure where the war file will be build in a submodule.
I'm using two profiles wildfly-deploy-dev01 and wildfly-deploy-dev02.
<profiles>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>wildfly-deploy-dev02</id>
<build>
[...]
<profiles>
In the main module I skipped it.
In the war submodule:
<profiles>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
<finalName>${project.artifactId}-v1.0</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<id>wildfly-credentials<id>
<hostname>dev01.example.com</hostname>
<protocol>remote+https</protocol>
<port>9993</port>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
[same as above for hostname dev02.example.com]
</profiles>
First I was thinking everthing works fine but then I found out that only the last server will be deployed.
mvn wildfly:deploy -P wildfly-deploy-dev01,wildfly-deploy-dev02
I played around by setting the configration after the execution tag without success. It looks that the second profile overwrite the first one.
Futher I hardcoded the finalname because the parsedVersion is not parsed.
<finalName>${project.artifactId}-v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</finalName>
At the moment I'm lost with Maven. Has anybody an idea how I can deploy with the plugin on two servers?
Thanks,
Markus
Ways which I tried:
https://github.com/tsotzolas/wildfly_maven_plugins_examples/blob/master/deployToMultiplesServer/pom.xml
wildfly-maven-plugin not deploying when multiple profiles selected
Cannot access parsedVersion value in pom properties
You should be able to do this in a single profile with different executions. There shouldn't be a need to multiple profiles.
<profiles>
<profile>
<id>wildfly-deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<id>wildfly-credentials<id>
<protocol>remote+https</protocol>
<port>9993</port>
</configuration>
<executions>
<execution>
<id>deploy-dev1</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>dev01.example.com</hostname>
</configuration>
</execution>
<execution>
<id>deploy-dev2</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>dev02.example.com</hostname>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profiles>
With this you'd just have to do mvn clean install -Pwildfly-deploy.

How to Solve Authentication issue when pushing Docker Image using Maven to Private repository

I am trying to push my docker image which is build using maven in my local to my public/private repository in Docker Cloud/Docker Hub.But I am getting Index response didn't contain any endpoints when it's try to Push.Below is sample config of my pom.xml.
I am not sure which configuration I am missing here.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.11</version>
<configuration>
<imageName>${docker.image.prefix}/dockercloudappstation</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<!-- <dockerHost>tcp://192.168.99.100:2376</dockerHost> -->
<serverId>docker-hub</serverId>
<!-- <registryUrl>https://hub.docker.com/</registryUrl> -->
<resources>
<resource>
<!-- <targetPath>/</targetPath> -->
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-image-version</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<!-- <image>${docker.image.prefix}/${project.artifactId}</image> -->
<image>${docker.image.prefix}/dockercloudappstation</image>
<newName>hub.docker.com/${docker.image.prefix}/dockercloudappstation</newName>
<!-- <serverId>docker-hub</serverId> -->
<pushImage>true</pushImage>
</configuration>
</execution>
<execution>
<id>tag-image-latest</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<!-- <image>${docker.image.prefix}/${project.artifactId}</image> -->
<image>${docker.image.prefix}/dockercloudappstation</image>
<newName>hub.docker.com/${docker.image.prefix}/dockercloudappstation:latest</newName>
<pushImage>true</pushImage>
</configuration>
</execution>
<execution>
<id>push-image</id>
<phase>package</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<serverId>docker-hub</serverId>
<!-- <imageName>${docker.image.prefix}/dockercloudappstation</imageName> -->
</configuration>
</execution>
Error Log:
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught
at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:130)
at com.spotify.docker.TagMojo.execute(TagMojo.java:44)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: com.spotify.docker.client.exceptions.DockerException: Index response didn't contain any endpoints
at com.spotify.docker.client.AnsiProgressHandler.progress(AnsiProgressHandler.java:52)
at com.spotify.docker.Utils$DigestExtractingProgressHandler.progress(Utils.java:150)
at com.spotify.docker.client.ProgressStream.tail(ProgressStream.java:77)
at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1040)
at com.spotify.docker.Utils.pushImage(Utils.java:83)
at com.spotify.docker.TagMojo.execute(TagMojo.java:119)
at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:128)
Open settings.xml for your maven settings configuration and add here server with your credentials. Usually this file is located in .m2 folder so add here something like:
<servers>
<server>
<id>docker-hub</id>
<username>username</username>
<password>password</password>
</server>
</servers>
This settings shouldn't be (and AFAIK can't be) in pom.xml because of security issues.
If you are interested in more secure option you can encrypt your password like in example here.
You have too messy pom.xml. Try to start with simplest pom.xml configuration. Check springio example and change springio property to your docker hub repo.
<properties>
<docker.image.prefix>springio</docker.image.prefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.11</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<serverId>docker-hub</serverId>
<!-- <registryUrl></registryUrl> is optional and defaults to https://index.docker.io/v1/ in the Spotify docker-client dependency. -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>

Clear local maven repository via maven-plugin on install phase

I'd like to delete the content of my entire repository (.m2/repository) before the installation phase. Of course I don't want to do it by hand so I am looking for a plugin which does the magic. So far I came across maven-clean-plugin and I am trying to use it as follows:
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${settings.localRepository}/</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I expect this to wipe out the entire repository before downloading the new artifacts, and finally to remove the target folder from the modules. Removal of target folders works, however the wiping out the repository is kinda not working. It does wipe out the repository, however then maven complains about some artifacts required are missing so the compilation fails and returns such errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources (default-resources) on project com.google.protobuf: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.3 -> [Help 1]
I feel like I am pretty close to the solution. Probably I just need to tweak the parameter tags of the plugin.
Could anyone give an idea?
If you clean the entire local repository you also delete all plugins which are needed by maven and was downloaded before clean runs. You should use the dependency plaugin for delteing only jars which are dependecies of your Project:
mvn dependency:purge-local-repository
In pom you can use it like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>clean</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<resolutionFuzziness>groupId</resolutionFuzziness>
<includes>
<include>org.ambraproject</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

How to resolve a Maven "The packaging for this project did not assign a file to the build artifact" error?

I’m using Maven 3.2.3. I used to be able to run “mvn clean install” on my WAR project and the WAR would get installed to my local repository. However, I recently added a configuration so that my WAR would be constructed in place (config is below). Now, when I run
mvn clean install
I get the error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.5.2:install (install) on project myproject: The packaging for this project did not assign a file to the build artifact -> [Help 1]
How do I fix this? I tried making the “install” goal of the maven-install-plugin the default, but that didn’t help. Below is my Maven configuration …
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/classes</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<id>war-inplace</id>
<phase>package</phase>
<goals>
<goal>inplace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Adding the below rpm entry
%_rpmfilename noarch/%%{NAME}-%%{VERSION}-%%{RELEASE}.noarch.rpm
in each of the following files mentioned here solved the problem for me. (from 64 to no-arch).
vim /etc/rpm/macros
vim ~/.rpmmacros

Signing apk with maven-jarsigner-plugin

I followed this tutorial and configured maven to sign my apk.
Here is a part of my pom.xml
<!-- Maven plugin which is responsible for signing apks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
<goal>verify</goal>
</goals>
<phase>package</phase>
<inherited>true</inherited>
<configuration>
<removeExistingSignatures>true</removeExistingSignatures>
<archiveDirectory/>
<includes>
<include>${project.build.directory}/eticapp-1.0.0-SNAPSHOT.apk</include>
</includes>
<keystore>d:\My Docs\KeyStore\EtickAppKeystore</keystore>
<alias>ekey</alias>
<storepass>1234abcd</storepass>
<keypass>123abc</keypass>
<verbose>true</verbose>
<arguments>
<argument>-sigalg</argument><argument>MD5withRSA</argument>
<argument>-digestalg</argument><argument>SHA1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Indeed when I am trying to execute the goals:
jarsigner:sign jarsigner:verify
I get an Exception about failing alias, which is clearly set.
Any solutions for that?
Failed to execute goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign (default-cli) on project eticapp: The parameters 'alias' for goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign are missing or invalid -> [Help 1]
The solution was not to use quotatin marks in my alias and password!

Resources