user2719441
user2719441

Reputation: 162

Openshift Docker Strategy - not able to pull maven artifacts from private repo

In OpenShift i am using s2i( docker strategy) . I have configured two repo's public and private in pom.xml .

maven is able to pull the artifacts from the public repo , But it could not pull the application specific artifact from the private repo.

Is there a way to update the maven setting.xml inside the openshift by providing maven repo credentials. how to provide credentials to pull the artifacts from private maven repo configured.

Error Below

Downloading from central: https://artifactory.mycomp.com/artifactory/java-snapshot-local/com/test/common-security/1.0.0/common-security-1.0.0.pom

Failed to execute goal on project demo-app: Could not resolve dependencies for project com.example:demo-app:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.mycomp:common-security:jar:1.0.0: Failed to read artifact descriptor for com.mycomp:common-security:jar:1.0.0: Could not transfer artifact com.mycomp:common-security:pom:1.0.0 from/to central (https://artifactory.mycomp.com/artifactory/java-snapshot-local): authentication failed for https://artifactory.mycomp.com/artifactory/java-snapshot-local/com/test/common-security/1.0.0/common-security-1.0.0.pom, status: 401 Unauthorized -> [Help 1] [ERROR]

Upvotes: 1

Views: 448

Answers (1)

user2719441
user2719441

Reputation: 162

The below one worked for me but not sure this one is ideal. Add the settings.xml to the root of the source:

<settings>
    <servers>
        <server>
            <id>${repo.id}</id>
            <username>${repo.login}</username>
            <password>${repo.pwd}</password>
        </server>
    </servers>
</settings> 

Inside the docker, use can use the settings.xml as an argument during build and supply the credentials.

# Build the application first using Maven
FROM maven:3.8-openjdk-11 as build
WORKDIR /app
COPY . .
COPY settings.xml /usr/share/
RUN mvn --version
RUN mvn --settings /usr/share/settings.xml -Drepo.id=central -Drepo.login=Myname -Drepo.pwd=MyPass clean install -Dmaven.test.skip=true

# Inject the JAR file into a new container to keep the file small
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=build /app/target/demo-app*.jar /app/app.jar
EXPOSE 8080
ENTRYPOINT ["sh", "-c"]
CMD ["java -jar app.jar"]

Upvotes: 1

Related Questions