Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops install Python package from Azure Artifacts inside Docker

I am trying to install a pip package from Azure Artifacts as part of a Docker image(with Docker@2 task) but whatever I try does not work.

It looks like my pip inside Docker cannot authenticate against Azure Artifacts whatever I try. Closest I got is with

RUN pip install keyring artifacts-keyring
ENV ARTIFACTS_KEYRING_NONINTERACTIVE_MODE true
RUN pip install <> --index-url https://pkgs.dev.azure.com/<>/_packaging/<>/pypi/simple/

but in my Azure devops, i keep getting

ERROR: Could not find a version that satisfies the requirement <> (from versions: none)
ERROR: No matching distribution found for <>

Also - Azure documentation on this seems to very poor, if I switch ENV ARTIFACTS_KEYRING_NONINTERACTIVE_MODE false it prompts my Azure DevOps pipeline to authenticate intercatively which is not what I want.

How can I install a Python package published in Azure Artifacts as part of my Azure Pipeline Docker task automatically?

like image 666
and_apo Avatar asked Apr 08 '20 11:04

and_apo


2 Answers

How can I install a Python package published in Azure Artifacts as part of my Azure Pipeline Docker task automatically?

We could use the PipAuthenticate task to populates the PIP_EXTRA_INDEX_URL environment variable:

It authenticates with your artifacts feed and per the docs, will store the location of a config file that can be used to connect in the PYPIRC_PATH environment variable.

Then pass it in the build arg:

arguments: --build-arg INDEX_URL=$(PIP_EXTRA_INDEX_URL)

You could check this document Consuming Azure Pipelines Python artifact feeds in Docker for some more details.

Hope this helps.

like image 60
Leo Liu-MSFT Avatar answered Dec 31 '22 02:12

Leo Liu-MSFT


To add to the accepted answer, here is a somewhat more complete code example:

azure-pipelines.yml

- task: PipAuthenticate@1
  inputs:
    artifactFeeds: 'my_artifacts_feed'
    # 'onlyAddExtraIndex' populates PIP_EXTRA_INDEX_URL env variable
    onlyAddExtraIndex: True

- task: Docker@2
  displayName: 'Build Docker Image'
  inputs:
    command: build
    dockerfile: $(dockerfilePath)
    tags: |
      $(tag)
    arguments: --build-arg INDEX_URL=$(PIP_EXTRA_INDEX_URL)

Dockerfile

FROM python:3.8-buster

# add an URL that PIP automatically searches (e.g., Azure Artifact Store URL)
ARG INDEX_URL
ENV PIP_EXTRA_INDEX_URL=$INDEX_URL

COPY requirements.txt
RUN pip install -r requirements.txt
like image 44
sh0rtcircuit Avatar answered Dec 31 '22 01:12

sh0rtcircuit