services:
    mysql-test:
        image: mysql:8.0
        command: --default-authentication-plugin=mysql_native_password
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: art_relations
        volumes:
            - ./scripts/mysql-init.sql:/docker-entrypoint-initdb.d/init.sql:ro
        tmpfs:
            - /var/lib/mysql
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot"]
            interval: 5s
            timeout: 5s
            retries: 20
            start_period: 30s

    unit-lint:
        build:
            context: .
            target: unit-lint
        environment:
            - DD_TRACE_ENABLED=0
            # Functional tests connect to the mysql-test service; the unit run
            # stays on SQLite because TEST_DB_BACKEND is set inline only for the
            # functional pytest invocation (see scripts/unit-lint.sh).
            - TEST_DB_HOST=mysql-test
            - TEST_DB_PORT=3306
            - TEST_DB_USER=root
            - TEST_DB_PASSWORD=root
        depends_on:
            mysql-test:
                condition: service_healthy
        volumes:
            - .:/var/app

    track-dev:
        build:
            context: .
            target: dev
        healthcheck:
            test: ["CMD", "curl", "-f", "http://localhost:5000/hello/"]
            interval: 1m30s
            timeout: 10s
            retries: 3
            start_period: 40s
        ports:
            - "5000:5000"
        volumes:
            - .:/var/app
        env_file:
            - path: .env
              required: false
        environment:
            - Environment=dev

    integration-test:
        build:
            context: .
            target: integration-test
        environment:
            - QA_DB_USER
            - QA_DB_PASS
            - QA_GRASS_HOST
            - QA_DB_HOST
            - BASE_QA_URL
            - BASE_QA_GRASS_URL
            - QA_DB_DATABASE
            - AWS_REGION
            - AWS_DEFAULT_REGION=us-east-1
            - AWS_ACCESS_KEY_ID
            - AWS_SECRET_ACCESS_KEY
            - AWS_SESSION_TOKEN
        volumes:
            - .:/var/app

    deploy:
        build:
            context: .
            target: deploy
        volumes:
            - .:/var/app
        ports:
            - "8080:8080"
