version: '3'

volumes:
    smart-farm-mysql: { }
    smart-farm-elasticsearch: { }
    smart-farm-traefik: { }
    upload: { }

services:
    smart-farm-mysql:
        image: mysql/mysql-server:8.0.25
        volumes:
            - smart-farm-mysql:/var/lib/mysql/
        environment:
            - MYSQL_USER=farm
            - MYSQL_ALLOW_EMPTY_PASSWORD=yes
            - MYSQL_PASSWORD=P@ssw0rdfarm
            - MYSQL_ROOT_PASSWORD=P@ssw0rdfarm
            - MYSQL_DATABASE=smf
        ports:
            - 3307:3306
        command: mysqld --default-authentication-plugin=mysql_native_password --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp

    smart-farm-elasticsearch:
        image: elasticsearch:5.6.13
        volumes:
            - smart-farm-elasticsearch:/usr/share/elasticsearch/data/
        ports:
            - 9200:9200
            - 9300:9300
        command: -Enetwork.host=0.0.0.0 -Ediscovery.type=single-node
        environment:
            - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"

    smart-farm-api:
        build:
            context: .
            dockerfile: ./src/main/docker/Dockerfile
        image: smart-farm-api
        volumes:
            - upload:/home/jhipster/upload
        depends_on:
            - smart-farm-mysql
            - smart-farm-elasticsearch
        environment:
            - _JAVA_OPTIONS=-Xmx1024m -Xms512m -Djava.net.preferIPv4Stack=true
            - SPRING_PROFILES_ACTIVE=prod,swagger
            - SPRING_DATASOURCE_URL=jdbc:mysql://smart-farm-mysql:3306/smf?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
#            - SPRING_JACKSON_SERIALIZATION_WRITE-DATES-AS-TIMESTAMPS=false
            - SPRING_DATASOURCE_USERNAME=farm
            - SPRING_DATASOURCE_PASSWORD=P@ssw0rdfarm
            - JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
            - SPRING_DATA_JEST_URI=http://smart-farm-elasticsearch:9200
        ports:
            - 8080:8080

    smart-farm-cdn:
        build:
            context: .
            dockerfile: ./x_cdn/Dockerfile
        image: smart-farm-cdn
        depends_on:
            - smart-farm-api
#        volumes_from:
#            - smart-farm-api
        volumes:
            - upload:/home/jhipster/upload

    traefik:
        build:
            context: .
            dockerfile: ./src/main/docker/traefik/Dockerfile
        image: smart-farm-traefik
        depends_on:
            - smart-farm-api
        volumes:
            - smart-farm-traefik:/etc/traefik/acme:z
        ports:
            - "0.0.0.0:80:80"
            - "0.0.0.0:443:443"
