Postgres host error while trying to run build on GitLab CI

I’m having issue getting postgres to work on my django project in GitLab CI.

I’m follwing this documentation -

http://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html .

I’ve set the DATABASE_URL=postgres://postgres:@postgres:5432/test_db as per the guide but still I’m getting following error in the build - could not translate host name "postgres" to address: Name or service not known

This is my gitlab-ci.yml -

test:
  script:
  - export DATABASE_URL=postgres://postgres:@postgres:5432/test_db
  - apt-get update -y
  - apt-get install -y python-dev python-pip
  - pip install -r requirements.txt
  - python manage.py test

This is on Gitlab.com. Am I doing something wrong?

Finally solved the issue. All I had to do was, add the postgres under the services. The documentation made it seem like the postgres service would be already there.

Here’s how my final .gilab-ci.yml looks -

services:
    - postgres

test:
    script:
        - apt-get update -y
        - apt-get install -y python-dev python-pip
        - pip install -r requirements.txt
        - python manage.py test

variables:
    DATABASE_HOST: postgres
    DATABASE_USER: postgres
    DATABASE_PASSWORD: ""