gpt4 book ai didi

django - 使用 Devops CI/CD 将 Django Web App 部署到 Azure 应用服务

转载 作者:行者123 更新时间:2023-12-02 22:58:36 26 4
gpt4 key购买 nike

我正在尝试使用 CI/CD 管道(Microsoft 为应用程序部署提供的最基本的管道 - 我没有进行任何更改)将简单的 django web ap 部署到 Azure 应用服务。但是我收到以下错误:

2021-03-08T16:55:51.172914117Z   File "", line 219, in _call_with_frames_removed
2021-03-08T16:55:51.172918317Z File "/home/site/wwwroot/deytabank_auth/wsgi.py", line 13, in
2021-03-08T16:55:51.172923117Z from django.core.wsgi import get_wsgi_application
2021-03-08T16:55:51.172927017Z ModuleNotFoundError: No module named 'django'

我检查了其他线程并尝试执行提到的所有操作,但它没有帮助,或者我遗漏了一些内容:

wsgi.py中我添加了:

import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..' )
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../licenses_api')
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../deytabank_auth')

from django.core.wsgi import get_wsgi_application


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'deytabank_auth.settings')

application = get_wsgi_application()

但仍然遇到相同的错误,django 无法识别。我可以看到 reuqirements.txt 已成功安装,并且其中包含所有必需的库(包括 Django)

我的 CI/CD yaml 文件如下所示:

# Python to Linux Web App on Azure
# Build your Python project and deploy it to Azure as a Linux Web App.
# Change python version to one thats appropriate for your application.
# https://learn.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- develop

variables:
# Azure Resource Manager connection created during pipeline creation
azureServiceConnectionId: '***'

# Web app name
webAppName: 'DeytabankAuth'

# Agent VM image name
vmImageName: 'ubuntu-latest'

# Environment name
environmentName: 'DeytabankAuth'

# Project root folder. Point to the folder containing manage.py file.
projectRoot: $(System.DefaultWorkingDirectory)

# Python version: 3.7
pythonVersion: '3.7'

stages:
- stage: Build
displayName: Build stage
jobs:
- job: BuildJob
pool:
vmImage: $(vmImageName)
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
displayName: 'Use Python $(pythonVersion)'

- script: |
python -m venv antenv
source antenv/bin/activate
python -m pip install --upgrade pip
pip install setup
pip install -r requirements.txt
workingDirectory: $(projectRoot)
displayName: "Install requirements"

- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(projectRoot)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
displayName: 'Upload package'
artifact: drop

- stage: Deploy
displayName: 'Deploy Web App'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeploymentJob
pool:
vmImage: $(vmImageName)
environment: $(environmentName)
strategy:
runOnce:
deploy:
steps:

- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
displayName: 'Use Python version'

- task: AzureWebApp@1
displayName: 'Deploy Azure Web App : DeytabankAuth'
inputs:
azureSubscription: $(azureServiceConnectionId)
appName: $(webAppName)
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

也许我需要在 Azure 应用服务中配置某些内容?但我不确定到底是什么。

最佳答案

我以前遇到过这个问题,问题可能是你的部署方法。不确定您使用哪一个,但下面的经典部署中心即将被弃用,请尝试使用新的部署中心。 enter image description here检查了你的工作流程和我这边的工作流程,没有什么不同。所以我将我这边正确的步骤贴出来供大家引用。

  1. 在本地检查您的项目以确保其可以成功运行。

  2. 创建网络应用(这是为了确保您的网络应用不会受到损坏)并导航至部署中心页面。 enter image description here

  3. 转到 GitHub 并导航到 GitHub Action 页面以查看日志。 enter image description here

  4. 测试您的网络应用并检查 KuDu 网站上的文件结构:https://{yourappname}.scm.azurewebsites.net/wwwroot/ enter image description here

您可以像我一样通过单击浏览按钮进行测试。 enter image description here如果您想运行命令,请访问此站点:https://{yourappname}.scm.azurewebsites.net/DebugConsole enter image description here

<小时/>

顺便说一下,我发布了这个link如果您需要使用 DevOps 进行部署

关于django - 使用 Devops CI/CD 将 Django Web App 部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66534333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com