英文:
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:
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
英文:
- 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:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论