# yaml-language-server: $schema=https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json

services:
    db:
        extends:
            file: ./docker-compose.base.yml
            service: db
        env_file: ./.env.docker-compose.dev
        volumes:
            - postgres_test_data:/var/lib/postgresql/data
        networks:
            - app-network
        profiles:
            - test
            - integration
        ports:
            - 54322:5432

    minio:
        extends:
            file: ./docker-compose.base.yml
            service: minio
        env_file: ./.env.docker-compose.dev
        volumes:
            - minio_data:/data
        networks:
            - app-network
        profiles:
            - test
            - integration
        ports:
            - 9000:9000
            - 9001:9001

    minio-init:
        depends_on:
            minio:
                condition: service_healthy
        env_file: ./.env.docker-compose.dev
        extends:
            file: ./docker-compose.base.yml
            service: minio-init
        networks:
            - app-network
        profiles:
            - test
            - integration

    inbucket:
        extends:
            file: ./docker-compose.base.yml
            service: inbucket
        env_file: ./.env.docker-compose.dev
        networks:
            - app-network
        profiles:
            - test
            - integration

    cache:
        env_file: ./.env.docker-compose.dev
        extends:
            file: docker-compose.base.yml
            service: cache
        networks:
            - app-network
        profiles:
            - test
            - integration
        ports:
            - 6379:6379

    jobs:
        container_name: jobs
        image: ${JOBS_IMAGE}
        platform: linux/amd64
        env_file: .env.docker-compose.dev
        environment:
            - OTEL_SERVICE_NAME=jobs.jobs
            - PUBPUB_URL=${JOBS_INTEGRATION_PUBPUB_URL:-http://integration-tests:3000}
        networks:
            - app-network
        depends_on:
            - db
        profiles:
            - integration

    integration-tests:
        image: ${INTEGRATION_TESTS_IMAGE}
        env_file: ./.env.docker-compose.dev
        environment:
            - PORT=3000
            - CI=true
        depends_on:
            jobs:
                # TODO: add a healthcheck for jobs
                condition: service_started
            db:
                condition: service_started
            inbucket:
                condition: service_started
        # platform: linux/amd64
        healthcheck:
            test: ["CMD-SHELL", "curl http://integration-tests:3000/api/health"]
            interval: 10s
            timeout: 5s
            retries: 5
        profiles:
            - integration
        ports:
            - 3000:3000
        networks:
            - app-network

    site-builder:
        image: ${SITE_BUILDER_IMAGE}
        depends_on:
            - integration-tests
            - jobs
            - minio
        ports:
            - "4000:4000"
        restart: on-failure
        networks:
            - app-network
        profiles:
            - integration
        environment:
            - PUBPUB_URL=http://integration-tests:3000
            - S3_ENDPOINT=${ASSETS_STORAGE_ENDPOINT:-http://minio:9000}
            - S3_REGION=${ASSETS_REGION:-us-east-1}
            - S3_ACCESS_KEY=${ASSETS_UPLOAD_KEY:-preview-different}
            - S3_SECRET_KEY=${ASSETS_UPLOAD_SECRET_KEY:-preview-different123}
            - S3_BUCKET_NAME=${ASSETS_BUCKET_NAME:-byron}
            - PORT=4000

volumes:
    minio_data:
    postgres_test_data:
        driver: local
networks:
    app-network:
