Connecting to mariaDB in Github action

I know there are multiple related questions but I can't get this to work.

I'm working on a Github action to test my Django app using MariaDB and Selenium before deploying. I have simplified it to just running the tests for now.

I have reviewed my secrets and know they are correct.

I have tried running services on both localhost and in a container, but neither can seem to resolve the database address.

I have tried it like this:

name: Deploy

on:
  push:

jobs:
  django-tests:
    runs-on: ubuntu-latest

    services:
      db:
        env:
          MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
          MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
          MYSQL_USER: ${{ secrets.MYSQL_USER }}
          MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
        image: mariadb:11.5
        options: >
          --health-cmd="healthcheck.sh --connect --innodb_initialized"
        ports:
          - 3306:3306
      selenium:
        image: selenium/standalone-chrome
        ports:
          - 4444:4444

    steps:
    - name: Check out code
      uses: actions/checkout@v3

    - name: Debug Hostname Resolution
      run: |
        ping -c 4 localhost:3306 || echo "Failed to resolve 'db'"

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.12

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Run Django Selenium Tests
      env:
        SECRET_KEY: ${{ secrets.DJANGO_SECRET }}
        MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
        MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
        MYSQL_USER: ${{ secrets.MYSQL_USER }}
        MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
        DATABASE_URL: mysql://${{ secrets.MYSQL_USER }}:${{ secrets.MYSQL_PASSWORD }}@localhost:3306/${{ secrets.MYSQL_DATABASE }}
        DISPLAY: ":99.0"
      run: |
        python manage.py migrate
        python manage.py test

and also running in a python container without exposing ports and connecting to "db" directly (the services name).

Any help would be appreciated!

Back to Top