1

I'm working on a Django project using Docker. I have configured Travis-Ci and I want to submit test coverage to coveralls. However, it is not working as expected. any help will be highly appreciated.

Here is the error I'm getting

Submitting coverage to coveralls.io...
No source for /mwibutsa/mwibutsa/settings.py
No source for /mwibutsa/mwibutsa/urls.py
No source for /mwibutsa/user/admin.py
No source for /mwibutsa/user/migrations/0001_initial.py
No source for /mwibutsa/user/models.py
No source for /mwibutsa/user/tests/test_user_api.py
No source for /mwibutsa/user/tests/test_user_model.py
Could not submit coverage: 422 Client Error: Unprocessable Entity for url: https://coveralls.io/api/v1/jobs
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/coveralls/api.py", line 177, in wear
    response.raise_for_status()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://coveralls.io/api/v1/jobs
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/coveralls/cli.py", line 77, in main
    result = coverallz.wear()
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/coveralls/api.py", line 180, in wear
    raise CoverallsException('Could not submit coverage: {}'.format(e))
coveralls.exception.CoverallsException: Could not submit coverage: 422 Client Error: Unprocessable Entity for url: https://coveralls.io/api/v1/jobs

**Here is my Travis.yml file**

language: python python: - "3.7" services: docker before_script: pip install docker-compose script: - docker-compose run web sh -c "coverage run manage.py test && flake8 && coverage report" after_success: - coveralls

language: python
python:
  - "3.7"
services: docker
before_script: pip install docker-compose
script:
  - docker-compose run web sh -c "coverage run manage.py test && flake8 && coverage report"
after_success:
  - coveralls

My Dockerfile

FROM python:3.7-alpine
LABEL description="Mwibutsa Floribert"

ENV PYTHONUNBUFFERED 1

RUN mkdir /mwibutsa
WORKDIR /mwibutsa

COPY requirements.txt /mwibutsa/
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual  .tmp-build-deps gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN apk del .tmp-build-deps


COPY . /mwibutsa/

My docker-compose.yml

version: '3.7'
services:
  web:
    build: .
    command: >
      sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST=db
      - DB_NAME=postgres
      - DB_PASSWORD=password
      - DB_USER=postgres
      - DB_PORT=5432
    volumes:
      - .:/mwibutsa
    ports:
        - "8000:8000"
    depends_on:
      - db
  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_NAME=postgres
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=postgres
      - POSTGRES_PORT=5432

2 Answers2

2

To understand why the coverage is not being submitted, you have to understand how docker containers operate.

The container is created to mimic a separate and independent unit. This means that commands being run in the global context are different from those being run inside the container context.

In your case, you are running tests and generating a coverage report inside the container's context then trying to submit a report to coveralls from the global context.

Since the file is in the container, the coveralls command cannot find the report and hence nothing gets submitted.

You may refer to the answer provided here to solve this: Coveralls: Error- No source for in my application using Docker container

Or check out the documentation provided by travis on how to submit to coveralls from travis using docker: https://docs.travis-ci.com/user/coveralls/#using-coveralls-with-docker-builds

2

You have to run coveralls inside the container so it can send the data file generated by coverage to coveralls.io. You have to run coverage again in the after_success command so the .coverage data file is present in the container when coveralls runs. You also have to pass the coveralls repo token in as an environment variable that you set in travis https://docs.travis-ci.com/user/environment-variables#defining-variables-in-repository-settings.

.travis.yml

language: python
python:
  - "3.7"

services: docker

before_script: pip install docker-compose

script:
  - docker-compose run web sh -c "coverage run manage.py test && flake8 && coverage report"
after_success:
  - docker-compose run web sh -c "coverage run manage.py test && TRAVIS_JOB_ID=$TRAVIS_JOB_ID TRAVIS_BRANCH=$TRAVIS_BRANCH COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN coveralls"

You need to make sure your git repo files are copied into the container for coveralls to accurately report the branch and have the badge work. You might also need to install git in the container.

Dockerfile:10

RUN apk add --update --no-cache postgresql-client jpeg-dev git
Anon Anon
  • 21
  • 4