version: "3.0"

services:
    reverse-proxy:
        image: traefik:v2.1.3
        command:
            - --entrypoints.web.address=:80
            - --entrypoints.websecure.address=:443
            - --providers.docker=true
            - --certificatesResolvers.le.acme.httpChallenge.entryPoint=web
            - --certificatesresolvers.le.acme.email=martin.eigenmann@unisg.ch
            - --certificatesresolvers.le.acme.storage=/acme.json
            - --providers.docker.exposedByDefault=false
            - --serversTransport.insecureSkipVerify=true
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - ./acme.json:/acme.json
        restart: unless-stopped
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
            - "traefik.http.routers.http-catchall.entrypoints=web"
            - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
            - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

    tapas-tasks:
        image: openjdk
        command: "java -jar /data/tapas-tasks-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.tapas-tasks.rule=Host(`tapas-tasks.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.tapas-tasks.service=tapas-tasks"
            - "traefik.http.services.tapas-tasks.loadbalancer.server.port=8081"
            - "traefik.http.routers.tapas-tasks.tls=true"
            - "traefik.http.routers.tapas-tasks.entryPoints=web,websecure"
            - "traefik.http.routers.tapas-tasks.tls.certresolver=le"

    tapas-auction-house:
        image: openjdk
        command: "java -jar /data/tapas-auction-house-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.tapas-auction-house.rule=Host(`tapas-auction-house.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.tapas-auction-house.service=tapas-auction-house"
            - "traefik.http.services.tapas-auction-house.loadbalancer.server.port=8086"
            - "traefik.http.routers.tapas-auction-house.tls=true"
            - "traefik.http.routers.tapas-auction-house.entryPoints=web,websecure"
            - "traefik.http.routers.tapas-auction-house.tls.certresolver=le"

    assignment:
        image: openjdk
        command: "java -jar /data/assignment-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.assignment.rule=Host(`assignment.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.assignment.service=assignment"
            - "traefik.http.services.assignment.loadbalancer.server.port=8082"
            - "traefik.http.routers.assignment.tls=true"
            - "traefik.http.routers.assignment.entryPoints=web,websecure"
            - "traefik.http.routers.assignment.tls.certresolver=le"

    executor-pool:
        image: openjdk
        command: "java -jar /data/executor-pool-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.executor-pool.rule=Host(`executor-pool.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.executor-pool.service=executor-pool"
            - "traefik.http.services.executor-pool.loadbalancer.server.port=8083"
            - "traefik.http.routers.executor-pool.tls=true"
            - "traefik.http.routers.executor-pool.entryPoints=web,websecure"
            - "traefik.http.routers.executor-pool.tls.certresolver=le"

    executor1:
        image: openjdk
        command: "java -jar /data/executor1-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        depends_on:
            - executor-pool
            - assignment
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.executor1.rule=Host(`executor1.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.executor1.service=executor1"
            - "traefik.http.services.executor1.loadbalancer.server.port=8084"
            - "traefik.http.routers.executor1.tls=true"
            - "traefik.http.routers.executor1.entryPoints=web,websecure"
            - "traefik.http.routers.executor1.tls.certresolver=le"

    executor2:
        image: openjdk
        command: "java -jar /data/executor2-0.0.1-SNAPSHOT.jar"
        restart: unless-stopped
        depends_on:
            - executor-pool
            - assignment
        volumes:
            - ./:/data/
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.executor2.rule=Host(`executor2.${PUB_IP}.nip.io`)"
            - "traefik.http.routers.executor2.service=executor2"
            - "traefik.http.services.executor2.loadbalancer.server.port=8085"
            - "traefik.http.routers.executor2.tls=true"
            - "traefik.http.routers.executor2.entryPoints=web,websecure"
            - "traefik.http.routers.executor2.tls.certresolver=le"
