version: "3.9"

services:
  db:
    image: mysql:8
    container_name: mytimetracker-db
    restart: always
    environment:
      MYSQL_DATABASE: mytimetracker
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: appuser
      MYSQL_PASSWORD: apppass
    volumes:
      - db_data:/var/lib/mysql
    expose:
      - "3306"
    networks:
      - traefik

  app:
    image: eclipse-temurin:17-jdk-alpine
    container_name: mytimetracker-app
    depends_on:
      - db
    ports:
      - "8400:8080"
    environment:
      SPRING_PROFILES_ACTIVE: docker
    volumes:
      - ./build/libs/MyTimeTracker-0.0.1-SNAPSHOT.jar:/app/app.jar
    working_dir: /app
    command: ["java", "-jar", "app.jar"]
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mytimetracker.rule=Host(`timetracker.nilzbu.de`)"
      - "traefik.http.routers.mytimetracker.entrypoints=websecure"
      - "traefik.http.routers.mytimetracker.tls=true"
      - "traefik.http.routers.mytimetracker.tls.certresolver=letsEncrypt"
      - "traefik.http.services.mytimetracker.loadbalancer.server.port=8080"
    networks:
      - traefik
    restart: always

volumes:
  db_data:

networks:
  traefik:
    external: true