Tag Archives: download

Scenario

Let’s say you built spring-boot executable jar and uploaded it into nexus repository. To deploy your spring-boot application you create a Dockerfile that downloads your jar using nexus rest search and download API. For example:

FROM openjdk:8-jre-alpine

MAINTAINER itzap <mailer@itzap.com>

WORKDIR /

RUN wget -O app-service.jar  \
	'https://nexus.companyUrl.com/nexus/service/rest/v1/search/assets/download?group=com.mycompany.service&name=app-service&repository=company-snapshots&sort=version&direction=des'

EXPOSE 8080

ENTRYPOINT [ "java", "-jar","app-service.jar"]

When you run docker container you see the following error message:

no main manifest attribute, in app-service.jar

Diagnostic

When you build and run jar locally everything is working fine. app-service.jar inside docker container appears to be corrupted. To diagnose the issue run the wget command from the terminal:

wget -O app-service.jar  \
	'https://nexus.companyUrl.com/nexus/service/rest/v1/search/assets/download?group=com.mycompany.service&name=app-service&repository=company-snapshots&sort=version&direction=des'

Notice the following results on the command line:

$ wget -O app-service.jar 'https://nexus.companyUrl.com/nexus/service/rest/v1/search/assets/download?group=com.mycompany.service&name=app-service&repository=company-snapshots&sort=version&direction=desc'

--2019-10-21 21:48:27--  https://nexus.companyUrl.com/nexus/service/rest/v1/search/assets/download?group=com.mycompany.service&name=app-service&repository=company-snapshots&sort=version&direction=desc

Распознаётся nexus.compnyUrl.com (nexus.companyUrl.com)… 00.00.00.00

Подключение к nexus.compnyUrl.com (nexus.compnyUrl.com)|00.00.00.00|:443... соединение установлено.

HTTP-запрос отправлен. Ожидание ответа… 302 Found

Адрес: https://nexus.compnyUrl.com/nexus/repository/company-snapshots/com/mycompany/service/app-service/0.0.1-SNAPSHOT/app-service-0.0.1-20191021.220127-1-javadoc.jar [переход]

--2019-10-21 21:48:28--  https://nexus.compnyUrl.com/nexus/repository/app-snapshots/com/mycompany/service/app-service/0.0.1-SNAPSHOT/app-service-0.0.1-20191021.220127-1-javadoc.jar

Повторное использование соединения с nexus.compnyUrl.com:443.

HTTP-запрос отправлен. Ожидание ответа… 200 OK

Длина: 247463 (242K) [application/java-archive]

Сохранение в: «app-service.jar»

Do not get all these messages in Russian fool you. This is not a Russian hacker attack. Pay attention to what is actually being downloaded. app-service-0.0.1-20191021.220127-1-javadoc.jar javadoc!!!

Solution

Solution to this issue can be found in sonatype Search API. Looking through documentation I came across this query parameter maven.classifier This issue happens when your repository contains javadoc jar alnog side your artifact. &sort=version&direction=desc parameters are also critical to insure you are downloading the latest version, but not enough to uniquely identify artifact. Final URL that works looks like this:

'https://nexus.companyUrl.com/nexus/service/rest/v1/search/assets/download?group=com.mycompany.service&name=app-service&repository=company-snapshots&sort=version&direction=desc&maven.classifier'