services:
  client:
    image: ghcr.io/bluewave-labs/checkmate:frontend-staging
    restart: always
    environment:
      UPTIME_APP_API_BASE_URL: "https://checkmate-test.bluewavelabs.ca/api/v1"
      UPTIME_APP_CLIENT_HOST: "https://checkmate-test.bluewavelabs.ca"
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - server
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d/:ro
      - ./certbot/www:/var/www/certbot/:ro
      - ./certbot/conf/:/etc/nginx/ssl/:ro

  certbot:
    image: certbot/certbot:latest
    restart: always
    volumes:
      - ./certbot/www/:/var/www/certbot/:rw
      - ./certbot/conf/:/etc/letsencrypt/:rw
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew --webroot -w /var/www/certbot; sleep 12h & wait $${!}; done;'"

  server:
    image: ghcr.io/bluewave-labs/checkmate:backend-staging
    restart: always
    ports:
      - "52345:52345"
    env_file:
      - server.env
    depends_on:
      - redis
      - mongodb
  redis:
    image: ghcr.io/bluewave-labs/checkmate:redis-staging
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - ./redis/data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 5s
  mongodb:
    image: ghcr.io/bluewave-labs/checkmate:mongo-staging
    restart: always
    command: ["mongod", "--quiet", "--replSet", "rs0", "--bind_ip_all"]
    ports:
      - "27017:27017"
    volumes:
      - ./mongo/data:/data/db
      # - ./mongo/init/02_create_users.js:/docker-entrypoint-initdb.d/02_create_users.js // No longer needed
    env_file:
      - mongo.env
    healthcheck:
      test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]}) }" | mongosh --port 27017 --quiet
      interval: 5s
      timeout: 30s
      start_period: 0s
      start_interval: 1s
      retries: 30
