2

I am trying to create a docker test enviroment for our opensource hobby project. Our python and angular code is running without errors. I need a little help with configuring the docker runner to include mongodb.

stages: 
- build
- test

services:
  - mongo

variables:
  MONGODB_URI: "mongodb://mongo/projekt_eszkozok"


build: 
  stage: build
  image: "python:3.8.2"
  script:
    - "pip3 install -r sources/backend/requirements.txt"

test:
  stage: test
  image: "python:3.8.2"
  script:
    - "pip3 install -r sources/backend/requirements.txt"
    - cd sources/backend
    - "python -m unittest discover tests/"

The error:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

Also it might matter that the project have Angular frontend which is going to be added to the test enviroment once we made our first Angular test.

Python database config:

MONGODB_SETTINGS = {
    'host': 'mongodb://127.0.0.1:27017/projekt_eszkozok'
}

Also tried with:

MONGODB_SETTINGS = {
    'host': 'mongodb://mongo:27017/projekt_eszkozok'
}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Zahovay
  • 135
  • 9

1 Answers1

0

As yippie-flu and Vishesh Kumar Singh answered in MongoDB server doesn't start at gitlab runner using gitlab-ci, instead of localhost:27017, you have to use mongo:27017 because the mongo service is running in its own Docker container.

Aleksey Tsalolikhin
  • 1,518
  • 7
  • 14