Issue
When trying to setup a Github action to test a Django project automatically, we ran into an issue with the django.yml
setup. Whenever we ran the .yml, we got this exception on the last step (python manage.py test
):
django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'db' (-3)")
To state, our docker environment and tests alone work fine, just when trying to do this in a Github action, we get issues.
What we have tried
- We have tried running a
docker-compose up -d
before running the test, to know for sure that our DB is running. - Tried adding environment variables with DB info like this: https://github.com/Cuda-Chen/django-mysql-github-actions-demo/blob/main/.github/workflows/django-ci.yml
Current code
name: Django CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
Does anyone know what is going on here, and how we can resolve this?