1

Can some one please provide what is the recommended solution for authenticating inside Dockerfile during docker build phase for Azure Artifacts for Maven, NPM or Python?

While most of the solutions for the particular problem of accessing authenticated feed of Azure Artifacts while building from inside a Dockerfile has been mentioned on Stack Overflow or on the internet (in various articles such as below) have targeted the nuget ecosystem, my question is for Maven, NPM or Python Packages.

Example blogs that provide solutions for nuget & docker-

Appreciate the help here.

BB8
  • 125
  • 1
  • 8
  • Hi, how about the issue? Does the answer below resolve your question, If yes, you could [Accept it as an Answer](https://meta.stackexchange.com/a/5235/515442) , so it could help other community members who get the same issues and we could archive this thread, thanks. – LoLance Sep 30 '20 at 10:01

1 Answers1

2

My question is for Maven, NPM or Python Packages.

These package types are from different systems, so we should use different ways to authenticate them.

For Maven:

Check set-up-your-feed . You should configure your pom.xml file to define the url, and then define settings.xml file with PAT. You can manage these two files in your project, then use Dockerfile to copy the settings.xml to ${user.home}/.m2 folder.

For NPM:

enter image description here

You can follow Other topic here to configure one .npmrc which contains credentials. Also I think you can create a normal .npmrc file, and then use Npm Authenticate task to modify it. Here's one working sample.

For Python:

We can use the Pip Authenticate task to populates the PIP_EXTRA_INDEX_URL environment variable and pass it as build arguments. Something like this: arguments: --build-arg INDEX_URL=$(PIP_EXTRA_INDEX_URL)

You can check the two answers from this similar issue for more details.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thanks @lance Li-MSFT, so looks like only way to get this encapsulated is to create a temporary settings.xml or npmrc files (where the secrets or tokens get replaced at run time during build) and once build is completed we can discard it using a multi stage build. Am I correct ? – BB8 Sep 15 '20 at 20:55
  • @BB8 Yes. And once the packages has restored and the real build has finished, we can add a `delete` step to delete the temporary file. – LoLance Sep 16 '20 at 08:43
  • Thanks @lance Li-MSFT – BB8 Sep 30 '20 at 11:52