version: '3.4'
services:
  netbox: &netbox
    image: code.europa.eu:4567/digit-c4/netbox-plugins:latest
    depends_on:
    - postgres
    - redis
    - redis-cache
    user: 'unit:root'
    healthcheck:
      start_period: 60s
      timeout: 3s
      interval: 15s
      test: "curl -f http://localhost:8080/api/ || exit 1"
    volumes:
    - netbox-media-files:/opt/netbox/netbox/media:z,rw
    - netbox-reports-files:/opt/netbox/netbox/reports:z,rw
    - netbox-scripts-files:/opt/netbox/netbox/scripts:z,rw
  netbox-worker:
    <<: *netbox
    depends_on:
      netbox:
        condition: service_healthy
    command:
    - /opt/netbox/venv/bin/python
    - /opt/netbox/netbox/manage.py
    - rqworker
    healthcheck:
      start_period: 20s
      timeout: 3s
      interval: 15s
      test: "ps -aux | grep -v grep | grep -q rqworker || exit 1"
  netbox-housekeeping:
    <<: *netbox
    depends_on:
      netbox:
        condition: service_healthy
    command:
    - /opt/netbox/housekeeping.sh
    healthcheck:
      start_period: 20s
      timeout: 3s
      interval: 15s
      test: "ps -aux | grep -v grep | grep -q housekeeping || exit 1"

  # postgres
  postgres:
    image: docker.io/postgres:15-alpine
    volumes:
    - netbox-postgres-data:/var/lib/postgresql/data

  # redis
  redis:
    image: docker.io/redis:7-alpine
    command:
    - sh
    - -c # this is to evaluate the $REDIS_PASSWORD from the env
    - redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
    volumes:
    - netbox-redis-data:/data
  redis-cache:
    image: docker.io/redis:7-alpine
    command:
    - sh
    - -c # this is to evaluate the $REDIS_PASSWORD from the env
    - redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
    volumes:
    - netbox-redis-cache-data:/data

volumes:
  netbox-media-files:
    driver: local
  netbox-postgres-data:
    driver: local
  netbox-redis-cache-data:
    driver: local
  netbox-redis-data:
    driver: local
  netbox-reports-files:
    driver: local
  netbox-scripts-files:
    driver: local