postgresql 无法从Web应用程序访问Postgres Flexible Server

gudnpqoy  于 2023-10-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(124)

我有一个Django应用程序要在Azure DevOps中使用管道进行部署,并部署到Azure云资源。Django数据库是同一资源组中的Postgres Flexible Server。我也有一个虚拟的网络资源在集团。管道安装依赖项,然后从Makefile中的命令执行测试。

在测试步骤中,Django应用程序无法到达数据库服务器,名称无法解析为IP,我尝试使用服务器IP并获得相同的错误。

我没有设置任何防火墙规则,也没有设置私有端点

voj3qocg

voj3qocg1#

要使用Azure Web App部署PostgreSQL,请参阅此Document:-
您可以单独创建Azure Web App和PostgreSQL Flexible服务器并部署您的Web App,或者创建Web App +数据库并在其中部署您的Web App。

对于Web应用程序+数据库[PostgreSQL DB是通过连接到Azure Web应用程序的VNET集成创建的]

在引擎中选择Web App +数据库后,选择PostgreSQL:-

  • Azure Web应用程序与PostgreSQL的Vnet集成:-*

My Azure Repository with .env file:-

我已经在我的应用程序设置中添加了DBSECRET_KEY,如下所示,并且AZURE_POSTGRESQL_CONNECTIONSTRING连接字符串是使用Web App +数据库选项自动创建的:-

然后我去Azure Web应用程序>开发工具>高级工具> Kudu > SSH >然后运行下面的命令来执行迁移如下:

python manage.py migrate

  • 我使用了以下Azure DevOps yaml脚本:-*

trigger:
- main

variables:
  
  azureServiceConnectionId: 'xxxxx-b9c0-f610xxxx'

  # Web app name
  webAppName: 'siliconpypostgesqlq'

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

  # Environment name
  environmentName: 'siliconpypostgesqlq'

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

  # Python version: 3.7
  pythonVersion: '3.10'

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 : siliconpypostgesqlq'
            inputs:
              azureSubscription: $(azureServiceConnectionId)
              appName: $(webAppName)
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

输出:-

我的Web应用加载成功,如下所示:-

  • Azure Web应用程序和PostgreSQL单独部署,没有任何Vnet集成,PostgreSQL通过允许Azure服务访问公共网络:-*

我的PostgreSQL设置:-

相关问题