Конвейер Azure не подключается к службе базы данных при выполнении тестов
Я пытаюсь запустить тесты приложения Django на azure с помощью Azure pipelines. Но каждый раз, когда я пытаюсь подключиться к базе данных, я сталкиваюсь с ошибкой.
Файл .yml, используемый для конвейера, выглядит следующим образом:
resources:
containers:
- container: pg12
image: postgres:12
env:
POSTGRES_USER: beta
POSTGRES_PASSWORD: beta
POSTGRES_DB: beta
ports:
- 5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
variables:
- name: DJANGO_SETTINGS_MODULE
value: config.settings.production
- name: DJANGO_SECRET_KEY
value: <redacted>
- name: DEBUG
value: False
- name: DATABASE_URL
value: postgres://beta:beta@localhost:5432/beta
trigger:
- qa
pool:
vmImage: ubuntu-latest
strategy:
matrix:
Python37:
PYTHON_VERSION: '3.7'
maxParallel: 3
services:
postgres: postgres:12
steps:
- script: printenv
- task: UsePythonVersion@0
inputs:
versionSpec: '$(PYTHON_VERSION)'
architecture: 'x64'
- script: |
sudo apt install -y postgresql-client
# sudo psql --host=postgres --username=postgres --command="SELECT 1;"
- task: PythonScript@0
displayName: 'Export project path'
inputs:
scriptSource: 'inline'
script: |
"""Search all subdirectories for `manage.py`."""
from glob import iglob
from os import path
# Python >= 3.5
manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
if not manage_py:
raise SystemExit('Could not find a Django project')
project_location = path.dirname(path.abspath(manage_py))
print('Found Django project in', project_location)
print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))
- script: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install -r requirements/local.txt
sudo apt-get install python-dev libpq-dev
displayName: 'Install prerequisites'
- script: |
pushd '$(projectRoot)'
pytest
displayName: 'Run tests'
- task: PublishTestResults@2
inputs:
testResultsFiles: "**/TEST-*.xml"
testRunTitle: 'Python $(PYTHON_VERSION)'
condition: succeededOrFailed()```
Can you tell me what is the source of the error and how can I fix it?