I'm setting up a custom TestContainer by pulling an image from a private registry. At the moment it looks like this (it works):
public static GenericContainer<?> customContainer = new GenericContainer<>(
DockerImageName.parse("private-registry.net:port/path/custom-image"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("Test_Custom").withHostName("custom"))
I'm setting the login information through System.setProperty("registry.username", "username") (same for password). I don't want my login to be plaintext code. The idea is to login through settings.xml where the private repositories are defined. I'm completely new to this so I don't know if that's even possible? I've tried just adding it into the xml file like so:
<repositories>
<id>custom-image</id>
<url>private-registry.net:port/path/custom-image</url>
......
</repositories>
<servers>
<server>
<id>custom-image</id>
<username>username</username>
<password>password</password>
</server>
</servers>
It doesn't seem to "detect" automatically, how do I get the container to refer to its url and credentials within the xml? Or is this not possible? I only see answers on how you push an image through maven.
Related
I try to use credentials in my build.sbt config in order to retrieve private artifacts from a gitlab private maven repository.
But as sbt documentation states :
The credentials file is a properties file with keys realm, host, user, and password.
And gitab private maven documentation states :
If a project is private or you want to upload Maven artifacts to GitLab,
credentials will need to be provided for authorization. Support is available for personal access tokens and CI job tokens only. Deploy tokens and regular username/password credentials do not work.
The only way to authenticate when fetching or pushing artifacts to gitlab maven private repository is to use a maven settings.xml file with :
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>REPLACE_WITH_YOUR_PERSONAL_ACCESS_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
I found a workaround to push my private artifacts (intermediate step locally) but I am out of options to use these private artifacts as libraryDependencies in other scala repositories.
Is there anyway to have sbt fetching my private gitlab repository with the required httpHeaders ?
Do you know any workaround (multi-step fetchs) to have my private artifacts retrieved ?
I have a private Nexus with a repository protected via authentication.
Pulling libraries works like a charm, but if I want to use one of the archetypes stored up there I always need to write plaintext username and password in the URL of the archetype catalog like this:
mvn archetype:generate -DarchetypeCatalog=http://username:password#maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
I read http://maven.apache.org/archetype/maven-archetype-plugin/faq.html#authentication and updated my settings.xml with what I understood from that very tiny bit of help:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>myrepo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
<server>
<id>pretty-archetype-unicorn-repo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>someid</id>
<repositories>
<repository>
<id>myrepo</id>
<name>My Repo</name>
<url>http://maven.mycompany.com/nexus/content/repositories/myrepo/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>someid</activeProfile>
</activeProfiles>
</settings>
Needless to say, it doesn't work and when I try:
mvn archetype:generate -DarchetypeCatalog=http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
I get the same old:
[WARNING] Error reading archetype catalog http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
Any hints, or better documentation with working example?
There's currently no way to do that if you don't specify at least -DarchetypeArtifactId. As per the official docs you linked:
The server id used to download the artifact is [archetypeArtifactId]-repo
hence there's no way to just browse the catalog if it's password protected (and you're not willing to expose username/password on your shell history).
In the meanwhile, you can go ahead and vote for ARCHETYPE-204. They have a patch already available since years, they probably just need a bit of a push.
UPDATE
Looking into the source code of the maven archetype project, looks like the following snippet in the settings.xml might work for you:
<servers>
<server>
<id>archetype</id>
<username>${your username}</username>
<password>${your password}</password>
</server>
</servers>
There is a default ID of archetype when building the Repository object while fetching a remote catalog. I don't think it's the official way of dealing with such situations, and it's a bit dirty IMO. But it might still work for you :-)
Also, you should be able to set profiles for reusing the archetype ID for different servers.
I think it should be in your settings.xml
<servers>
<server>
<id>myrepo</id>
<username>${your username}</username>
<password>${your password}</password>
</server>
</servers>
you need to add <server> for each of password protected repositories.
Looks like this is a known issue and you can't use archetypes from protected repository. See https://issues.apache.org/jira/browse/ARCHETYPE-204
There is a workaround available by doing the following:
mvn archetype:generate -DarchetypeCatalog=https://username:password#maven.mycompany.com/nexus/content/repositories/myrepo/
I have installed nexus on my local machine. I want my pom file to point to this repo. How can I add my custom repository to my pom.xml file?
From Maven - Settings Reference
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
...
</settings>
id: This is the ID of the server (not of the user to login as) that matches the id element of the repository/mirror that Maven tries to connect to.
username, password: These elements appear as a pair denoting the login and password required to authenticate to this server.
privateKey, passphrase: Like the previous two elements, this pair specifies a path to a private key (default is ${user.home}/.ssh/id_dsa) and a passphrase, if required. The passphrase and password elements may be externalized in the future, but for now they must be set plain-text in the settings.xml file.
filePermissions, directoryPermissions: When a repository file or directory is created on deployment, these are the permissions to use. The legal values of each is a three digit number corrosponding to *nix file permissions, ie. 664, or 775.
Note: If you use a private key to login to the server, make sure you omit the element. Otherwise, the key will be ignored.
All you should need is the id, username and password
The id and URL should be defined in your pom.xml like this:
<repositories>
...
<repository>
<id>acme-nexus-releases</id>
<name>acme nexus</name>
<url>https://nexus.acme.net/content/repositories/releases</url>
</repository>
...
</repositories>
If you need a username and password to your server, you should encrypt it.
Maven Password Encryption
First of all I can highly recommend reading the Nexus book. It will explain the benefits of using a Maven repository manager.
There is a section on how to configure your Maven build to use Nexus:
http://www.sonatype.com/books/nexus-book/reference/config.html
This leads me to question why you altering your POM file? I suspect what you really want to do is setup Nexus as a remote repository mirror. This is done in your Maven settings file.
The following tells Maven use Nexus as your default repository (Instead of Maven Central)
<settings>
..
..
<mirrors>
<mirror>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
This is desired behaviour since your Nexus repository is configured to cache artifacts retrieved from Central (which is good for build performance).
Note:
The "public" repository group could include other repositories proxied by your Nexus instance (Not just Maven Central). You probabily want this behaviour, as it centralizes all repository management. It just makes your build less portable for people outside of your organization.
It seems the answers here do not support an enterprise use case where a Nexus server has multiple users and has project-based isolation (protection) based on user id ALONG with using an automated build (CI) system like Jenkins. You would not be able to create a settings.xml file to satisfy the different user ids needed for different projects. I am not sure how to solve this, except by opening Nexus up to anonymous access for reading repositories, unless the projects could store a project-specific generic user id in their pom.xml.
From the Apache Maven site
<project>
...
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://myserver/repo</url>
</repository>
</repositories>
...
</project>
"The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml." - Apache Maven site - settings reference
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
If you don't want or you cannot modify the settings.xml file, you can create a new one at the root of your project, and call maven passing it as a parameter with the -s argument:
$ mvn COMMAND ... -s settings.xml
From maven setting reference, you can not put your username/password in a pom.xml
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml.
You can first add a repository in your pom and then add the username/password in the $MAVEN_HOME/conf/settings.xml:
<servers>
<server>
<id>my-internal-site</id>
<username>yourUsername</username>
<password>yourPassword</password>
</server>
</servers>
I'd like to use CloudBees for my CI environment, but I'd also like to deploy my Maven artifacts to my existing private Nexus repository. In my current local Hudson setup, I utilize the username/password settings within the .m2/settings.xml file as follows:
...
<servers>
<server>
<id>my-repository</id>
<username>username</username>
<password>password</password>
</server>
</servers>
...
How/where can I configure these credentials on CloudBees?
You can put these in your private webdav filestore: http://wiki.cloudbees.com/bin/view/DEV/Sharing+Files+with+Build+Executors
Then, just point Maven at this by passing the '-s' option, or clicked the "Advanced" section of your Maven build and add the path in the "Alternate settings file" field.
You should follow this step by step guide:
http://developer.cloudbees.com/bin/view/DEV/Accessing+under+an+external+Maven+repository
I'm trying to store some of our private artifacts on Github and would like to access them as if they were part of a Maven repo. There are lots of pages that explain how to create a public Maven repo on Github: you just put the artifacts in the proper directory structure in your project, and then access them using a "raw" URL:
<repositories>
<repository>
<id>myrepo.myname.github.com</id>
<url>https://github.com/myname/myproject/raw/master/repositories/releases/</url>
</repository>
</repositories>
So far, so good. Now the trouble is that I can't figure out how to access the repo if it's private. I've added a username and password to my settings.xml, but it doesn't work:
<servers>
<server>
<id>myrepo.myname.github.com</id>
<username>myusername</username>
<password>mypassword</password>
</server>
</servers>
What's the trick?
The question is now moot. Github has eliminated downloads. They don't host binaries any more. Probably because of exactly the kind of abuse I've proposed...
You can access private repositories from Maven pom.xml using the following URL:
https://api.github.com/users/username/repos?login=username&token=oauthtoken&repositoryname=reponame