英文:
Github actions failing on dependencies
问题
我试图将我的 GitHub 存储库链接到我的 Azure 函数应用程序,通常通过 UI 完成。然而,GitHub 在构建的依赖项部分抛出了一些错误。
运行 pip install -r requirements.txt
pip install -r requirements.txt
shell: /usr/bin/bash -e {0}
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: .
PYTHON_VERSION: 3.10
pythonLocation: /opt/hostedtoolcache/Python/3.10.11/x64
ERROR: 无法打开要求文件:[Errno 2] 没有该文件或目录:'requirements.txt'
注意:pip 有新版本可用:23.0.1 -> 23.1.2
注意:要更新,请运行:pip install --upgrade pip
错误:进程以退出代码 1 完成。
我对 CI/CD 非常陌生,特别是在这种格式下。对于我需要做什么方面的任何帮助将非常有帮助和感激。我正在使用 Windows,并且使用 Python 3.10.6
以下是我的 GitHub Actions 工作流文件。
Azure Web Apps 部署操作的文档:https://github.com/azure/functions-action
Azure 的更多 GitHub Actions:https://github.com/Azure/actions
有关 Python、GitHub Actions 和 Azure Functions 的更多信息:https://aka.ms/python-webapps-actions
name: 将 Python 项目构建并部署到 Azure Function App - AutoAnalytics
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # 将其设置为你的 Web 应用程序项目的路径,默认为存储库根目录
PYTHON_VERSION: '3.10' # 将其设置为要使用的 Python 版本(支持 3.6、3.7、3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检查存储库
uses: actions/checkout@v2
- name: 设置 Python 版本
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 创建并启动虚拟环境
run: |
python -m venv venv
source venv/bin/activate
- name: 安装依赖项
run: pip install -r requirements.txt
# 可选:在此添加运行测试的步骤
- name: 上传部署作业的工件
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: 从构建作业下载工件
uses: actions/download-artifact@v2
with:
name: python-app
path: .
- name: '部署到 Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'APP_NAME'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_PROFILE_PATH }}
scm-do-build-during-deployment: true
enable-oryx-build: true
英文:
I tried to link my github repo to my azure function app which is typically done through the UI. However, github is throwing me some errors in the dependencies section of the build.
Run pip install -r requirements.txt
pip install -r requirements.txt
shell: /usr/bin/bash -e {0}
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: .
PYTHON_VERSION: 3.10
pythonLocation: /opt/hostedtoolcache/Python/3.10.11/x64
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Notice: A new release of pip is available: 23.0.1 -> 23.1.2
Notice: To update, run: pip install --upgrade pip
Error: Process completed with exit code 1.
I'm very new to CI/CD, especially in this format. Any help on what it needs from me would be very helpful and appreciated. I am working on Windows with Python 3.10.6
Below is my github actions workflow file.
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions
name: Build and deploy Python project to Azure Function App - AutoAnalytics
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Python version
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
# Optional: Add step to run tests here
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .
- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'APP_NAME'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_PROFILE_PATH }}
scm-do-build-during-deployment: true
enable-oryx-build: true
答案1
得分: 1
感谢@Azeem和@GuiFalourd的评论。
确保您的GitHub存储库具有requirements.txt和其他
将函数文件放置在与我在此存储库中的方式相同的位置:-
确保在一个单独的文件夹中具有init.py和functions.json,其余所有文件都放在存储库的根目录,如@Azeem和@GuiFalourd建议的那样:
我的存储库:
我的requirements.txt:
azure-functions
现在,我通过Azure Deployment Center直接运行了GitHub Actions部署,函数已成功部署,如下所示:-
GitHub工作流程:
您可以在此链接找到我的GitHub工作流程。
代码:
代码参考
name: Build and deploy Python project to Azure Function App - siliconfunc432
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Python version
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
# Optional: Add step to run tests here
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .
- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'siliconfunc432'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3DB3646163EA4EC884AD53503517FE4B }}
scm-do-build-during-deployment: true
enable-oryx-build: true
输出:
GitHub工作流成功执行:-
函数已
英文:
Thank you @Azeem and @GuiFalourd for your comments.
Make sure your github repo has requirements.txt and other
Function files places the same way I have in my repository here:-
Make sure to have init.py and functions.json in one separate folder and rest all the files outside of it in the root of your repo as suggested by @Azeem and @GuiFalourd like below:-
My repository:-
My requirements.txt:-
azure-functions
Now, I ran the Github Actions deployment directly via Azure Deployment Center function was deployed successfully, Refer below:-
Github workflow:-
You can find my github workflow in this Link.
Code:-
Code reference
name: Build and deploy Python project to Azure Function App - siliconfunc432
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Python version
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
# Optional: Add step to run tests here
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .
- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'siliconfunc432'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3DB3646163EA4EC884AD53503517FE4B }}
scm-do-build-during-deployment: true
enable-oryx-build: true
Output:-
Github Workflow executed successfully:-
Function was deployed like below:-
> Refer my SO Thread answer here where I deployed a Python Function app with Github Actions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论