I’m learning to use Gitlab CI and I’m trying to configure .gitlab-ci file to run CI into my Django project.
- I have the following .gitlab-ci file:
stages:
- test
variables:
MYSQL_DATABASE: $DB_NAME
MYSQL_USER: $DB_USER
MYSQL_PASSWORD: $DB_PASSWORD
services:
- mysql:8.0
test:
image: alpine:3.13
stage: test
script:
- ...(up the app)...
- I have configured the environment variables in the gitlab (Settings → CI/CD → Variables), e.g:
DB_HOST=mysql
- And I have the following DB configuration in my
settings.py
file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': getenv('DB_NAME'),
'USER': getenv('DB_USER'),
'PASSWORD': getenv('DB_PASSWORD'),
'HOST': getenv('DB_HOST'),
'PORT': getenv('DB_PORT'),
'TEST' : {
'NAME' : f"test_{getenv('DB_NAME')}",
}
}
}
When I run this, all the installation is successfully but at moment to run test I have the following error:
django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'mysql' (-2)")
Why it happens if in Gitlab Documentation said that if I use the mysql
services it’s the host that I need to configure?