在使用 func azure functionapp publish 时,在 Azure 中安装非pip或apt包。

huangapple go评论90阅读模式
英文:

Installing non-pip or apt packages in azure when using func azure functionapp publish

问题

我正在使用Linux计划发布我的Azure函数应用程序,需要一些无法通过pip访问的依赖项。我已经能够使用requirements.txt文件发布具有所有pip依赖项的函数。是否有其他文件可以告诉Azure运行apt install libevent-dev之类的命令?

我知道func azure functionapp publish --help文档中列出的--additional-packages标志。但我更希望有一个文件,我可以在其中编写任何Bash命令。这样,我可以使用一些Bash命令来安装任何软件包,例如:

wget -P /tmp https://github.com/someacct/somepackage.deb
apt install /tmp/somepackage.deb

感谢任何帮助!

英文:

I'm publishing my azure function app using a Linux plan and I require some dependencies which are not accessible via pip. I've been able to publish the function with all pip dependencies using a requirements.txt file. Is there any other file which I could use to tell azure to (for example) run apt install libevent-dev?

I'm aware of the --additional-packages flag listed in the func azure functionapp publish --help docs. However I would ideally like a file where I can write any bash command. This way I could install any package with some bash commands like:

wget -P /tmp https://github.com/someacct/somepackage.deb
apt install /tmp/somepackage.deb

Any help is appreciated!

答案1

得分: 1

  • AFAIK, unfortunately there is no such file to install non-pip packages.
  • But as mentioned in SO answer, you can achieve your requirement using Docker.
  • Create a Dockerfile in your project and add the below configuration:

Dockerfile:

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV  AzureWebJobsScriptRoot=/home/site/wwwroot  \
	 AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY . /home/site/wwwroot

RUN  pip  install  -r  /requirements.txt
RUN  wget -P /tmp https://github.com/someacct/somepackage.deb  &&  \
	 apt-get install /tmp/somepackage.deb

COPY  . /home/site/wwwroot
  • Install Docker and signin
  • Create a repository in Docker Hub and note the name:

在使用 func azure functionapp publish 时,在 Azure 中安装非pip或apt包。

Run the below commands in VScode to build and push the Docker image :

docker build --tag <DOcker_ID/Image_name:tag> .
docker run -p 8080:80 -it <DOCKER_ID/Image_name:tag>
docker push <DOCKER_ID/Image_name:tag>

You can refer MSDOC to create the docker image of Azure functions and deploy it to Azure.


I tried with apt-get install libevent-dev in my project:

Dockerfile:

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY requirements.txt /
COPY . /home/site/wwwroot
RUN pip install -r /requirements.txt
RUN apt-get install libevent-dev
COPY . /home/site/wwwroot

在使用 func azure functionapp publish 时,在 Azure 中安装非pip或apt包。

英文:
  • AFAIK, unfortunately there is no such file to install non-pip packages.
  • But as mentioned in SO answer, you can achieve your requirement using Docker.
  • Create a Dockerfile in your project and add the below configuration:

Dockerfile:

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV  AzureWebJobsScriptRoot=/home/site/wwwroot  \
	 AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY . /home/site/wwwroot

RUN  pip  install  -r  /requirements.txt
RUN  wget -P /tmp https://github.com/someacct/somepackage.deb  &&  \
	 apt-get install /tmp/somepackage.deb

COPY  . /home/site/wwwroot
  • Install Docker and signin
  • Create a repository in Docker Hub and note the name:

在使用 func azure functionapp publish 时,在 Azure 中安装非pip或apt包。

Run the below commands in VScode to build and push the Docker image :

docker build --tag <DOcker_ID/Image_name:tag> .
docker run -p 8080:80 -it <DOCKER_ID/Image_name:tag>
docker push <DOCKER_ID/Image_name:tag>

You can refer MSDOC to create the docker image of Azure functions and deploy it to Azure.


I tried with apt-get install libevent-dev in my project:

Dockerfile:

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY requirements.txt /
COPY . /home/site/wwwroot
RUN pip install -r /requirements.txt
RUN apt-get install libevent-dev
COPY . /home/site/wwwroot

在使用 func azure functionapp publish 时,在 Azure 中安装非pip或apt包。

huangapple
  • 本文由 发表于 2023年7月17日 23:32:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定