version: '3'
services:
    ui:
        image: energyweb/origin-ui:canary
        restart: unless-stopped
        env_file:
            - ./.env
        environment:
            DISABLED_UI_FEATURES: IRecConnect;DevicesImport;IRecUIApp;CertificatesImport
            PORT: 80
        ports:
            - 3000:80
        networks:
            - vanilla-app-network
        depends_on:
            backend:
                condition: service_healthy

    backend:
        image: energyweb/migrations:canary
        restart: 'no'
        env_file:
            - ./.env
        environment:
            DB_HOST: postgres
            DB_PORT: 5432
            WEB3: http://ganache-cli:8545
        networks:
            - vanilla-app-network
        ports:
            - ${BACKEND_PORT}:${BACKEND_PORT}
        healthcheck:
            test: curl --fail http://127.0.0.1:$BACKEND_PORT/api/configuration || exit 1
            interval: 3s
            timeout: 3s
            retries: 1
            start_period: 60s
        depends_on:
            ganache-cli:
                condition: service_started
            postgres:
                condition: service_healthy

    ganache-cli:
        image: trufflesuite/ganache-cli
        command: ganache-cli -m "chalk park staff buzz chair purchase wise oak receive avoid avoid home" -l 8000000 -e 1000000 -a 40 -h 0.0.0.0
        networks:
            - vanilla-app-network
        ports:
            - 8545:8545

    solar-simulator:
        image: energyweb/solar-simulator:canary
        restart: unless-stopped
        env_file:
            - ./.env
        environment:
            BACKEND_URL: http://backend
        networks:
            - vanilla-app-network
        depends_on:
            backend:
                condition: service_healthy

    postgres:
        image: postgres
        restart: unless-stopped
        env_file:
            - ./.env
        environment:
            POSTGRES_USER: ${DB_USERNAME}
            POSTGRES_PASSWORD: ${DB_PASSWORD}
            POSTGRES_DB: origin
        healthcheck:
            test: ['CMD-SHELL', 'pg_isready -U postgres']
            interval: 1s
        networks:
            - vanilla-app-network
        volumes:
            - vanilla-postgres-data:/var/lib/postgresql/data
        #        ports:
        #            - 5432:5432
        depends_on:
            - ganache-cli

volumes:
    vanilla-postgres-data:

networks:
    vanilla-app-network:
        driver: bridge
