services:
  mongo:
    image: mongo:7
    restart: unless-stopped
    volumes:
      - mongo_data:/data/db
    networks:
      - hrms_network

  backend:
    image: ghcr.io/iodex99/hrms-backend:${VERSION:-latest}
    restart: unless-stopped
    env_file: .env
    environment:
      - MONGO_URL=mongodb://mongo:27017
    volumes:
      - uploads_data:/app/uploads
    depends_on:
      - mongo
    networks:
      - hrms_network

  frontend:
    image: ghcr.io/iodex99/hrms-frontend:${VERSION:-latest}
    restart: unless-stopped
    volumes:
      - uploads_data:/app/uploads:ro
    depends_on:
      - backend
    networks:
      - hrms_network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.hrms.rule=Host(`${DOMAIN}`)"
      - "traefik.http.routers.hrms.entrypoints=websecure"
      - "traefik.http.routers.hrms.tls.certresolver=letsencrypt"
      - "traefik.http.routers.hrms.tls.domains[0].main=${DOMAIN}"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.hrms-http.rule=Host(`${DOMAIN}`)"
      - "traefik.http.routers.hrms-http.entrypoints=web"
      - "traefik.http.routers.hrms-http.middlewares=redirect-to-https"

  traefik:
    image: traefik:v3.0
    restart: unless-stopped
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.letsencrypt.acme.tlschallenge=true"
      - "--certificatesresolvers.letsencrypt.acme.email=${ADMIN_EMAIL}"
      - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "letsencrypt_data:/letsencrypt"
    networks:
      - hrms_network

  update-agent:
    image: ghcr.io/iodex99/hrms-update-agent:${VERSION:-latest}
    restart: unless-stopped
    env_file: .env
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/usr/local/bin/docker:/usr/local/bin/docker:ro"
    networks:
      - hrms_network

volumes:
  mongo_data:
  uploads_data:
  letsencrypt_data:

networks:
  hrms_network:
    driver: bridge
