Django test fails on github-actions, works locally
I am ahving a problem. I am following a tutorial and wrote a wait for db command in my django project to wait until db is available and then run my tests. The command is below:
docker compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test"
When I run this command on my terminal, it executes fine.
However, I have a github action on run this command as soon as my code is pushed, I am getting an error when that heppens, and I am unable to comprehend the log. The yml file for github action is below:
---
name: Checks
on: [push]
jobs:
test-lint:
name: Test and Lint
runs-on: ubuntu-24.04
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
- name: Test
run: docker compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test"
- name: Lint
run: docker compose run --rm app sh -c "flake8"
Though most of the log part says success, I am unable to identify the error, it is probably only on the last line. The full error message says this:
Run docker compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test"
docker compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test"
shell: /usr/bin/bash -e {0}
time="2025-05-31T10:01:15Z" level=warning msg="/home/runner/work/recipe-app-api/recipe-app-api/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion"
db Pulling
f18232174bc9 Pulling fs layer
e87a4ab71e3e Pulling fs layer
e8ea8730f798 Pulling fs layer
2cae8a172409 Pulling fs layer
adbaf2d32053 Pulling fs layer
8ff80b4b5201 Pulling fs layer
dca80ca41ba4 Pulling fs layer
a8b21e5461c2 Pulling fs layer
1d318b8003f7 Pulling fs layer
17d9bf165746 Pulling fs layer
752117175404 Pulling fs layer
dca80ca41ba4 Waiting
a8b21e5461c2 Waiting
1d318b8003f7 Waiting
17d9bf165746 Waiting
752117175404 Waiting
2cae8a172409 Waiting
adbaf2d32053 Waiting
8ff80b4b5201 Waiting
f18232174bc9 Downloading [> ] 37.46kB/3.642MB
e8ea8730f798 Downloading [> ] 11.67kB/1.12MB
e87a4ab71e3e Downloading [====================================> ] 721B/975B
e87a4ab71e3e Downloading [==================================================>] 975B/975B
e87a4ab71e3e Verifying Checksum
e87a4ab71e3e Download complete
e8ea8730f798 Verifying Checksum
e8ea8730f798 Download complete
f18232174bc9 Verifying Checksum
f18232174bc9 Download complete
f18232174bc9 Extracting [> ] 65.54kB/3.642MB
2cae8a172409 Downloading [==================================================>] 172B/172B
2cae8a172409 Verifying Checksum
2cae8a172409 Download complete
8ff80b4b5201 Downloading [> ] 530.6kB/102.1MB
f18232174bc9 Extracting [==================================================>] 3.642MB/3.642MB
f18232174bc9 Extracting [==================================================>] 3.642MB/3.642MB
f18232174bc9 Pull complete
e87a4ab71e3e Extracting [==================================================>] 975B/975B
e87a4ab71e3e Extracting [==================================================>] 975B/975B
dca80ca41ba4 Downloading [===> ] 720B/9.015kB
dca80ca41ba4 Verifying Checksum
dca80ca41ba4 Download complete
adbaf2d32053 Downloading [==================================================>] 116B/116B
adbaf2d32053 Download complete
#11 7.010 Collecting pytz (from Django<3.3,>=3.2.4->-r /tmp/requirements.txt (line 1))
#11 7.018 Downloading pytz-2025.2-py2.py3-none-any.whl.metadata (22 kB)
#11 7.040 Collecting sqlparse>=0.2.2 (from Django<3.3,>=3.2.4->-r /tmp/requirements.txt (line 1))
#11 7.048 Downloading sqlparse-0.5.3-py3-none-any.whl.metadata (3.9 kB)
#11 7.096 Collecting typing-extensions>=4 (from asgiref<4,>=3.3.2->Django<3.3,>=3.2.4->-r /tmp/requirements.txt (line 1))
#11 7.103 Downloading typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
#11 7.118 Downloading Django-3.2.25-py3-none-any.whl (7.9 MB)
#11 7.189 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.9/7.9 MB 135.4 MB/s eta 0:00:00
#11 7.199 Downloading djangorestframework-3.12.4-py3-none-any.whl (957 kB)
#11 7.209 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 957.7/957.7 kB 93.6 MB/s eta 0:00:00
#11 7.217 Downloading asgiref-3.8.1-py3-none-any.whl (23 kB)
#11 7.227 Downloading psycopg2_binary-2.9.10-cp39-cp39-musllinux_1_2_x86_64.whl (3.0 MB)
#11 7.249 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 150.0 MB/s eta 0:00:00
#11 7.257 Downloading sqlparse-0.5.3-py3-none-any.whl (44 kB)
#11 7.275 Downloading typing_extensions-4.13.2-py3-none-any.whl (45 kB)
#11 7.286 Downloading pytz-2025.2-py2.py3-none-any.whl (509 kB)
#11 7.392 Installing collected packages: pytz, typing-extensions, sqlparse, psycopg2-binary, asgiref, Django, djangorestframework
#11 10.10
#11 10.11 Successfully installed Django-3.2.25 asgiref-3.8.1 djangorestframework-3.12.4 psycopg2-binary-2.9.10 pytz-2025.2 sqlparse-0.5.3 typing-extensions-4.13.2
#11 10.54 Collecting flake8<3.10,>=3.9.2 (from -r /tmp/requirements.dev.txt (line 1))
#11 10.57 Downloading flake8-3.9.2-py2.py3-none-any.whl.metadata (3.7 kB)
#11 10.59 Collecting pyflakes<2.4.0,>=2.3.0 (from flake8<3.10,>=3.9.2->-r /tmp/requirements.dev.txt (line 1))
#11 10.60 Downloading pyflakes-2.3.1-py2.py3-none-any.whl.metadata (3.9 kB)
#11 10.61 Collecting pycodestyle<2.8.0,>=2.7.0 (from flake8<3.10,>=3.9.2->-r /tmp/requirements.dev.txt (line 1))
#11 10.62 Downloading pycodestyle-2.7.0-py2.py3-none-any.whl.metadata (30 kB)
#11 10.64 Collecting mccabe<0.7.0,>=0.6.0 (from flake8<3.10,>=3.9.2->-r /tmp/requirements.dev.txt (line 1))
#11 10.65 Downloading mccabe-0.6.1-py2.py3-none-any.whl.metadata (4.3 kB)
#11 10.66 Downloading flake8-3.9.2-py2.py3-none-any.whl (73 kB)
#11 10.67 Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
#11 10.68 Downloading pycodestyle-2.7.0-py2.py3-none-any.whl (41 kB)
#11 10.69 Downloading pyflakes-2.3.1-py2.py3-none-any.whl (68 kB)
#11 10.72 Installing collected packages: mccabe, pyflakes, pycodestyle, flake8
#11 10.90
#11 10.91 Successfully installed flake8-3.9.2 mccabe-0.6.1 pycodestyle-2.7.0 pyflakes-2.3.1
#11 DONE 11.1s
#12 [app] exporting to image
#12 exporting layers
#12 exporting layers 1.4s done
#12 writing image sha256:bbd70f1bfb30f79e25aa3c150a6dc5904a66ccdbaa995b3c91e79dd2cf894e38 done
#12 naming to docker.io/library/recipe-app-api-app done
#12 DONE 1.4s
#13 [app] resolving provenance for metadata file
#13 DONE 0.0s
Segmentation fault (core dumped)
Error: Process completed with exit code 139.
Please help me, I am new to this and facing issues. I can provide more information if required.
I tried changing the command with a hyphen, like docker-compose
and running it again, but it gave an error of unkown command
This segmentation fault is most likely a memory-related issue. It can happen because your local machine has more resources than the GitHub Actions runner. Try setting resource limits in your docker-compose.yml
file, like this for github action:
services:
db:
...
deploy:
resources:
limits:
memory: 512M