services:
  traefik:
    # The official v3 Traefik docker image
    image: traefik:v3.3
    container_name: traefik
    # Enables the web UI and tells Traefik to listen to docker
    command: --api.insecure=true --providers.docker
    ports:
      # The HTTP port
      - '80:80'
      # The Web UI (enabled by --api.insecure=true)
      - '8080:8080'
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

  gittype:
    container_name: gittype
    build:
      context: ./
      target: dev # DEV
      # target: prod # PROD
    environment:
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      DATABASE_URL: ${DATABASE_URL}
    develop:
      watch:
        - path: ./src
          action: sync
          target: /app/src
        - path: ./static
          action: sync
          target: /app/static
        - path: ./prisma
          action: sync
          target: /app/prisma
        - path: ./package.json
          action: rebuild
    labels:
      - 'traefik.http.routers.gittype.rule=PathPrefix(`/`)'
      - 'traefik.http.services.gittype.loadbalancer.server.port=5173' # DEV
      # - 'traefik.http.services.gittype.loadbalancer.server.port=3000' # PROD
    depends_on:
      - mysql

  mysql:
    image: mysql:9.3.0
    container_name: mysql
    volumes:
      - mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DATABASE: gittype
    ports:
      - 3306:3306

  # DEV ONLY
  # phpmyadmin:
  #   image: phpmyadmin
  #   container_name: phpmyadmin
  #   environment:
  #     PMA_HOST: mysql
  #     PMA_USER: root
  #     PMA_PASSWORD: ${MYSQL_PASSWORD}
  #   labels:
  #     - 'traefik.http.routers.phpmyadmin.rule=Host(`db.localhost`)'
  #     - 'traefik.http.services.phpmyadmin.loadbalancer.server.port=80'
  prisma-studio:
    image: node:lts-alpine3.17
    working_dir: /usr/src/app
    volumes:
      - .:/usr/src/app
    command: npx prisma studio --port 5555 --browser none
    env_file:
      - .env
    labels:
      - 'traefik.http.routers.prisma.rule=Host(`prisma.localhost`)'
      - 'traefik.http.services.prisma.loadbalancer.server.port=5555'

volumes:
  mysql: