kilag
kilag

Reputation: 574

Use own packages (Artifact) in Azure function?

I want to use a packages deploy on azure artifact in an azure function

locally it was simple : just update the pip.ini, and the installation from requirements works great, I can launch my azure function locally, all is working

But how can I do it when I deploy it? maybe I need to put a pip.ini somewhere in my main folder?

Thanks

Upvotes: 5

Views: 4211

Answers (3)

Ari
Ari

Reputation: 6189

From your Function in the Azure Portal, navigate to its configuration blade. Then add under the 'Application Settings` tab click 'New Application Setting'. Provide the below as the key:

PIP_EXTRA_INDEX_URL

With the value set as your URL you want to use instead.

Source: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#custom-dependencies

Any pip flag can be set as an environment variable, example

--trusted-host

can be set as

PIP_TRUSTED_HOST

Just prefix PIP_ then the flag in capitals with - changed to _

Upvotes: 5

kilag
kilag

Reputation: 574

I finally find the solution :

go to your azure function, and open the command

here launch the different command :

mkdir pipconfig
cd pipconfig

now right your pip.ini with :

echo "[global]" > pip.ini
echo "extra-index-url=https://XXXXX" >> pip.ini

with the last url link to your artifact now you have created your pip.ini in your azure function, go to your environement variable and create :

PIP_CONFIG_FILE with value /home/pipconfig/pip.ini

and restart your function : you can publish as always and you can import your private artifact

hope it will help other people

Upvotes: 4

Hury Shen
Hury Shen

Reputation: 15754

Since you have generated requirements.txt file and it includes all of the info of the packages in your function project. You just need to deploy your function project(with requirements.txt) to azure. It will install the packages according to the requirements.txt automatically. For more information about deploy the python function to azure, you can refer to this tutorial.

Update:

As you mentioned your package is not a public package in your comments. You can try to use this command below:

func azure functionapp publish <APP_NAME> --build local

This command will build your project locally and then deploy it to azure.(But I'm not sure if this command can work fine because it also read from the requirements.txt file)

If the "build local" command doesn't work, you need to use docker, please refer to the steps in below screenshot: enter image description here

Here is a tutorial for further information about the steps above.

Upvotes: 2

Related Questions