version: "3"

services:
  anonymous_github:
    build: .
    restart: always
    image: tdurieux/anonymous_github:v2
    env_file:
      - ./.env
    environment: 
      - REDIS_HOSTNAME=redis
      - DB_HOSTNAME=mongodb
    volumes:
      - .:/app
    ports:
      - $PORT:$PORT
    healthcheck:
      test:
        - CMD
        - node
        - healthcheck.js
      interval: 10s
      timeout: 10s
      retries: 5
    links:
      - mongodb
      - redis

  redis:
    image: "redis:alpine"

  mongodb:
    image: mongo:latest
    restart: on-failure
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: $DB_USERNAME
      MONGO_INITDB_ROOT_PASSWORD: $DB_PASSWORD
    volumes:
      - mongodb_data_container:/data/db
    command: --quiet
    healthcheck:
      test:
        - CMD
        - mongo
        - --eval
        - "db.adminCommand('ping')"
      interval: 10s
      timeout: 10s
      retries: 5

  mongodb-backup:
    image: tiredofit/db-backup
    links:
      - mongodb
    volumes:
      - ./db_backups:/backup
    environment:
      - DB_TYPE=mongo
      - DB_HOST=mongodb
      - DB_DUMP_FREQ=60
      - DB_CLEANUP_TIME=240
      - COMPRESSION=XZ
      - DB_USER=$DB_USERNAME
      - DB_PASS=$DB_PASSWORD

    restart: always
volumes:
  mongodb_data_container:
