Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Automated build downloading private jars from a Maven Sonatype Nexus repository

I am building a development pipeline. The Docker images will be created automatically after a successful and tested version of my java application be deployed on a private Maven repository (Sonatype Nexus).

Once my application is built successfully, I need to publish it in somewhere, and Docker needs to have access to download it and create a container.

I thought on Docker accessing the Nexus Maven repository, but I did not find how can wget download a jar from a private repository. I did not found on Nexus documentation how I can pass authentication parameters to access a private URL. Does anyone know that?

PS: I also accept advice of easier solutions to accomplish this.

like image 620
John John Pichler Avatar asked Apr 25 '16 13:04

John John Pichler


2 Answers

I just discovered I can do it using cURL. Example:

curl -u username:password -o myapp.war "http://nexus.mycompany.com/service/local/artifact/maven/redirect?r=snapshots&g=com.company&a=MyApp&v=1.0-SNAPSHOT&p=war" -L

Where de -L flag is to cURL accepts redirect (301 response).

So, in docker-compose.yml I have a line like this:

RUN curl -u username:password -o myapp.war "http://nexus.mycompany.com/service/local/artifact/maven/redirect?r=snapshots&g=com.company&a=MyApp&v=1.0-SNAPSHOT&p=war" -L
like image 186
John John Pichler Avatar answered Sep 30 '22 04:09

John John Pichler


If you are using maven

mvn dependency:copy -Dartifact=groupId:artifactId:version[:packaging][:classifier] -DoutputDirectory=[target] -Dusername=[username] -Dpassword=[password]
like image 44
Hisham Khalil Avatar answered Sep 30 '22 05:09

Hisham Khalil