version: "3.9"

networks:
  traefik:
    external: true

volumes:
  pb_data:

services:
  traefik:
    image: traefik:v3.6
    container_name: traefik
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    command:
      - "--api.dashboard=true"
      - "--api.insecure=true"
      - "--log.level=DEBUG"
      - "--accesslog=true"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--certificatesresolvers.letsencrypt.acme.email=tech@thob.studio"
      - "--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme.json"
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entryPoint.scheme=https"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./configs/traefik/acme.json:/etc/traefik/acme.json"
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.entrypoints=websecure"
      - "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
      - "traefik.http.routers.traefik.rule=Host(`traefik.ar.thob.studio`)"

  app:
    container_name: ar-app
    image: registry.digitalocean.com/thob-blr1/ar:latest
    pull_policy: always
    restart: unless-stopped
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - VITE_POCKETBASE_URL=${VITE_POCKETBASE_URL:-https://pb.ar.thob.studio}
    expose:
      - "3000"
    environment:
      - VITE_POCKETBASE_URL=${VITE_POCKETBASE_URL:-https://pb.ar.thob.studio}
      - VITE_FRONTEND_URL=${VITE_FRONTEND_URL:-https://ar.thob.studio}
    depends_on:
      - pocketbase
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.ar-app.rule=Host(`ar.thob.studio`)"
      - "traefik.http.routers.ar-app.entrypoints=websecure"
      - "traefik.http.routers.ar-app.tls=true"
      - "traefik.http.routers.ar-app.tls.certresolver=letsencrypt"
      - "traefik.http.services.ar-app.loadbalancer.server.port=3000"

  pocketbase:
    container_name: ar-pb
    image: ghcr.io/muchobien/pocketbase:latest
    restart: unless-stopped
    command:
      - serve
      - --http=0.0.0.0:8090
      - --dir=/pb_data
      - --migrationsDir=/pb_migrations
    volumes:
      - pb_data:/pb_data
      - ./pb_migrations:/pb_migrations
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.ar-pb.rule=Host(`pb.ar.thob.studio`)"
      - "traefik.http.routers.ar-pb.entrypoints=websecure"
      - "traefik.http.routers.ar-pb.tls=true"
      - "traefik.http.routers.ar-pb.tls.certresolver=letsencrypt"
      - "traefik.http.services.ar-pb.loadbalancer.server.port=8090"
