Docker integration example

Dockerfile

First of all you need to build an image with testsuite, here is example Dockerfile:

FROM ubuntu:20.04

RUN apt-get update && \
    apt-get install -y \
            python3.8 python3-virtualenv \
            postgresql-client \
            mysql-client-8.0 && \
    apt-get clean

RUN mkdir -p /opt/yandex
RUN python3 -m virtualenv --python=/usr/bin/python3 /opt/yandex/testsuite

RUN mkdir -p /tmp/testsuite

# Early install requirements
COPY setup.py setup.cfg /tmp/testsuite/
COPY testsuite /tmp/testsuite/testsuite/

RUN /opt/yandex/testsuite/bin/pip install /tmp/testsuite[mongodb,postgresql-binary,mysql]

# Example requirements
COPY docs/examples/requirements.txt /tmp/requirements.txt
RUN /opt/yandex/testsuite/bin/pip install -r /tmp/requirements.txt

docker-compose.yaml

Then you need to configure docker-compose to start required enironment and run testsuite:

version: '2.1'

services:
    db-mongo-test:
        image: mongo

    db-postgresql-test:
        image: "postgres:11"
        environment:
          - POSTGRES_HOST_AUTH_METHOD=trust
          - POSTGRES_USER=testsuite
          - POSTGRES_PASSWORD=testsuite
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -U postgres"]
            interval: 10s
            timeout: 5s
            retries: 5

    db-mysql-test:
        image: "mysql:5.7"
        command: --default-authentication-plugin=mysql_native_password
        environment:
          - MYSQL_ALLOW_EMPTY_PASSWORD=yes
        healthcheck:
            test: ["CMD-SHELL", "mysql -uroot -e \"select 1;\""]
            interval: 10s
            timeout: 5s
            retries: 5

    db-postgresql:
        extends:
            service: db-postgresql-test
        volumes:
          - ../chat-storage-postgres/schemas/postgresql:/schema
          - ./db-postgresql:/docker-entrypoint-initdb.d

    db-mongo:
        extends:
            service: db-mongo-test
        volumes:
          - ./db-mongo:/docker-entrypoint-initdb.d

    db-mysql:
        extends:
            service: db-mysql-test
        volumes:
          - ./db-mysql:/docker-entrypoint-initdb.d
          - ../chat-storage-mysql/schemas/mysql:/schema

    testsuite:
        image: testsuite
        environment:
          - TESTSUITE_ALLOW_ROOT=1
          - PATH=/opt/yandex/testsuite/bin:/bin:/usr/bin
        working_dir: /testsuite/example
        volumes:
          - ..:/testsuite/example

    runtests-chat-backend:
        extends:
            service: testsuite

    runtests-chat-storage-mongo:
        extends:
            service: testsuite
        depends_on:
            db-mongo-test:
                condition: service_healthy
        environment:
          - PYTEST_ADDOPTS="--mongo=mongodb://db-mongo-test/"
        links:
          - db-mongo-test

    runtests-chat-storage-postgres:
        extends:
            service: testsuite
        depends_on:
            db-postgresql-test:
                condition: service_healthy
        environment:
          - PYTEST_ADDOPTS="--postgresql=postgresql://testsuite:testsuite@db-postgresql-test/"
        links:
          - db-postgresql-test

    runtests-chat-storage-mysql:
        extends:
            service: testsuite
        depends_on:
            db-mysql-test:
                condition: service_healthy
        environment:
          - PYTEST_ADDOPTS="--mysql=mysql://root@db-mysql-test/"
        links:
          - db-postgresql-test

    chat-storage-mongo:
        extends:
            service: testsuite
        depends_on:
          - db-mongo
        links:
          - db-mongo
        expose:
          - "8080"
        command: >
            python3 chat-storage-mongo/server.py --port 8080
            --mongo-uri mongodb://db-mongo/

    chat-storage-postgres:
        extends:
            service: testsuite
        depends_on:
            db-postgresql:
                condition: service_healthy
        links:
          - db-postgresql
        expose:
          - "8080"
        command: >
            python3 chat-storage-postgres/server.py --port 8080
            --postgresql postgresql://testsuite:testsuite@db-postgresql/chat_messages

    chat-storage-mysql:
        extends:
            service: testsuite
        depends_on:
            db-mysql:
                condition: service_healthy
        links:
          - db-mysql
        expose:
          - "8080"
        command: >
            python3 chat-storage-mysql/server.py --port 8080 --mysql-host=db-mysql