diff --git a/Jenkinsfile b/Jenkinsfile index c64cdc6..72de72f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { frigate_config = readJSON file: 'frigate_config.json' } - ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, extras: "--extra-vars 'mqtt_password=\"${frigate_config.mqtt.password}\" ipgeolocation_api_key=\"${frigate_config.ipgeolocation.api_key}\" garage_rtsp_password=\"${frigate_config.rtsp.garage.password}\" front_door_rtsp_password=\"${frigate_config.rtsp.front_door.password}\" doorbell_rtsp_password=\"${frigate_config.rtsp.doorbell.password}\" driveway_rtsp_password=\"${frigate_config.rtsp.driveway.password}\" back_door_rtsp_password=\"${frigate_config.rtsp.back_door.password}\" family_room_rtsp_password=\"${frigate_config.rtsp.family_room.password}\"'", playbook: 'install.yaml' + ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, extras: "--extra-vars 'ipgeolocation_api_key=\"${frigate_config.ipgeolocation.api_key}\" garage_rtsp_password=\"${frigate_config.rtsp.garage.password}\" front_door_rtsp_password=\"${frigate_config.rtsp.front_door.password}\" doorbell_rtsp_password=\"${frigate_config.rtsp.doorbell.password}\" driveway_rtsp_password=\"${frigate_config.rtsp.driveway.password}\" back_door_rtsp_password=\"${frigate_config.rtsp.back_door.password}\" family_room_rtsp_password=\"${frigate_config.rtsp.family_room.password}\"'", playbook: 'install.yaml' ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'stop.yaml' ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'start.yaml' } diff --git a/conf/config.yaml b/conf/config.yaml index 899f4e7..5f75024 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,7 +1,5 @@ mqtt: host: mqtt - user: '{FRIGATE_MQTT_USERNAME}' - password: '{FRIGATE_MQTT_PASSWORD}' detectors: cpu1: diff --git a/conf/docker-compose.yaml b/conf/docker-compose.yaml index 2015cd0..d1c1c7e 100644 --- a/conf/docker-compose.yaml +++ b/conf/docker-compose.yaml @@ -7,6 +7,8 @@ services: labels: autoheal: 'true' restart: unless-stopped + depends_on: + - mqtt healthcheck: test: ls /media/frigate && curl -s -f http://localhost:5000 -o /dev/null interval: 60s @@ -14,8 +16,6 @@ services: start_period: 30s timeout: 30s environment: - FRIGATE_MQTT_USERNAME: frigate - FRIGATE_MQTT_PASSWORD: ${MQTT_PASSWORD} FRIGATE_GARAGE_RTSP_USERNAME: motion FRIGATE_GARAGE_RTSP_PASSWORD: ${FRIGATE_GARAGE_RTSP_PASSWORD} FRIGATE_FRONT_DOOR_RTSP_USERNAME: motion @@ -46,19 +46,18 @@ services: source: /etc/localtime target: /etc/localtime read_only: true -# networks: -# - frigate + networks: + - frigate ports: - 127.0.0.1:10000:5000 - extra_hosts: - - mqtt:192.168.0.6 notify: container_name: frigate-notify image: frigate-notify:latest restart: unless-stopped + depends_on: + - frigate + - mqtt environment: - MQTT_USERNAME: frigate - MQTT_PASSWORD: ${MQTT_PASSWORD} REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt volumes: - type: bind @@ -69,14 +68,17 @@ services: source: /etc/localtime target: /etc/localtime read_only: true - extra_hosts: - - mqtt:192.168.0.6 + networks: + - frigate webcontrol: container_name: frigate-webcontrol image: frigate-webcontrol:latest labels: autoheal: 'true' restart: unless-stopped + depends_on: + - frigate + - mqtt healthcheck: test: curl -s -f http://localhost -o /dev/null interval: 60s @@ -84,40 +86,35 @@ services: start_period: 30s timeout: 30s environment: - MQTT_USERNAME: frigate - MQTT_PASSWORD: ${MQTT_PASSWORD} IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY} volumes: - type: bind source: /etc/localtime target: /etc/localtime read_only: true + networks: + - frigate ports: - 127.0.0.1:10001:80 - extra_hosts: - - mqtt:192.168.0.6 -# mqtt: -# container_name: mqtt -# image: eclipse-mosquitto:latest -# command: -# - mosquitto -# - -c -# - /mosquitto-no-auth.conf -# restart: unless-stopped -# volumes: -# - type: bind -# source: /etc/localtime -# target: /etc/localtime -# read_only: true -# networks: -# - frigate -# ports: -# - 1883:1883 -# - 9001:9001 + mqtt: + container_name: mqtt + image: eclipse-mosquitto:2.0.18 + command: + - mosquitto + - -c + - /mosquitto-no-auth.conf + restart: unless-stopped + volumes: + - type: bind + source: /etc/localtime + target: /etc/localtime + read_only: true + networks: + - frigate -#networks: -# frigate: -# name: frigate +networks: + frigate: + name: frigate volumes: config: diff --git a/install.yaml b/install.yaml index 8b17922..fe56313 100644 --- a/install.yaml +++ b/install.yaml @@ -1,8 +1,6 @@ - name: Install Frigate hosts: Barad-dur vars_prompt: - - name: mqtt_password - prompt: Enter password for MQTT user frigate - name: ipgeolocation_api_key prompt: Enter API key for IPGeolocation - name: garage_rtsp_password @@ -118,8 +116,6 @@ - name: Insert into Postgres table service vars: frigate_config: - mqtt: - password: '{{mqtt_password}}' ipgeolocation: api_key: '{{ipgeolocation_api_key}}' rtsp: diff --git a/notify/src/frigate_event_notifier.py b/notify/src/frigate_event_notifier.py index 1640ec2..7430913 100644 --- a/notify/src/frigate_event_notifier.py +++ b/notify/src/frigate_event_notifier.py @@ -10,7 +10,8 @@ import paho.mqtt.client as mqtt class FrigateEventNotifier: def __init__(self, mqtt_username, mqtt_password, quiet_period=3 * 60): self.mqtt_client = mqtt.Client() - self.mqtt_client.username_pw_set(mqtt_username, password=mqtt_password) + if mqtt_username is not None and mqtt_password is not None: + self.mqtt_client.username_pw_set(mqtt_username, password=mqtt_password) self.mqtt_client.on_connect = self._on_connect self.mqtt_client.on_message = self._on_message @@ -114,5 +115,5 @@ class FrigateEventNotifier: if __name__ == '__main__': - frigate_event_notifier = FrigateEventNotifier(os.environ['MQTT_USERNAME'], os.environ['MQTT_PASSWORD']) + frigate_event_notifier = FrigateEventNotifier(os.environ.get('MQTT_USERNAME'), os.environ.get('MQTT_PASSWORD')) frigate_event_notifier.start() diff --git a/start.yaml b/start.yaml index 9d5022c..6bdb429 100644 --- a/start.yaml +++ b/start.yaml @@ -35,7 +35,6 @@ - name: Docker Compose up Frigate environment: - MQTT_PASSWORD: '{{frigate_config.mqtt.password}}' IPGEOLOCATION_API_KEY: '{{frigate_config.ipgeolocation.api_key}}' FRIGATE_GARAGE_RTSP_PASSWORD: '{{frigate_config.rtsp.garage.password}}' FRIGATE_FRONT_DOOR_RTSP_PASSWORD: '{{frigate_config.rtsp.front_door.password}}' diff --git a/webcontrol/src/detection.py b/webcontrol/src/detection.py index 40f4ab1..9f14f12 100644 --- a/webcontrol/src/detection.py +++ b/webcontrol/src/detection.py @@ -53,7 +53,11 @@ def reset_all_camera_detection_at_sunset(): def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None: sleep(delay) - mqtt_publish.single(f'frigate/{camera}/detect/set', 'ON' if value else 'OFF', hostname='mqtt', port=1883, auth={'username': os.environ['MQTT_USERNAME'], 'password': os.environ['MQTT_PASSWORD']}) + mqtt_auth = {'username': os.environ.get('MQTT_USERNAME'), 'password': os.environ.get('MQTT_PASSWORD')} + if not all(mqtt_auth.values()): + mqtt_auth = None + + mqtt_publish.single(f'frigate/{camera}/detect/set', 'ON' if value else 'OFF', hostname='mqtt', port=1883, auth=mqtt_auth) @blueprint.route('/camera//detect', methods=['POST'])