Migrated MQTT to internal Docker network #1

Squashed commit of the following:

commit cc7419ff856867009e48aae1f1685382352a1ded
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:32:38 2023 -0500

    Removed MQTT auth from pipeline

commit ef80c5a56a9d0f5adb821bfc3e83d9f2d3726c7b
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:32:09 2023 -0500

    Removed forced MQTT auth from source

commit 4c00200f8e77c1c4c24d1e6ac9f425e1f3ed83a6
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sun Oct 29 20:31:35 2023 -0500

    Updated configs
This commit is contained in:
Ashish D'Souza 2023-10-29 20:33:14 -05:00
parent 415d4e0094
commit 3642e26c7a
7 changed files with 41 additions and 46 deletions

2
Jenkinsfile vendored
View File

@ -14,7 +14,7 @@ pipeline {
frigate_config = readJSON file: 'frigate_config.json' 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: 'stop.yaml'
ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'start.yaml' ansiblePlaybook credentialsId: 'rivendell-ssh-key', disableHostKeyChecking: true, playbook: 'start.yaml'
} }

View File

@ -1,7 +1,5 @@
mqtt: mqtt:
host: mqtt host: mqtt
user: '{FRIGATE_MQTT_USERNAME}'
password: '{FRIGATE_MQTT_PASSWORD}'
detectors: detectors:
cpu1: cpu1:

View File

@ -7,6 +7,8 @@ services:
labels: labels:
autoheal: 'true' autoheal: 'true'
restart: unless-stopped restart: unless-stopped
depends_on:
- mqtt
healthcheck: healthcheck:
test: ls /media/frigate && curl -s -f http://localhost:5000 -o /dev/null test: ls /media/frigate && curl -s -f http://localhost:5000 -o /dev/null
interval: 60s interval: 60s
@ -14,8 +16,6 @@ services:
start_period: 30s start_period: 30s
timeout: 30s timeout: 30s
environment: environment:
FRIGATE_MQTT_USERNAME: frigate
FRIGATE_MQTT_PASSWORD: ${MQTT_PASSWORD}
FRIGATE_GARAGE_RTSP_USERNAME: motion FRIGATE_GARAGE_RTSP_USERNAME: motion
FRIGATE_GARAGE_RTSP_PASSWORD: ${FRIGATE_GARAGE_RTSP_PASSWORD} FRIGATE_GARAGE_RTSP_PASSWORD: ${FRIGATE_GARAGE_RTSP_PASSWORD}
FRIGATE_FRONT_DOOR_RTSP_USERNAME: motion FRIGATE_FRONT_DOOR_RTSP_USERNAME: motion
@ -46,19 +46,18 @@ services:
source: /etc/localtime source: /etc/localtime
target: /etc/localtime target: /etc/localtime
read_only: true read_only: true
# networks: networks:
# - frigate - frigate
ports: ports:
- 127.0.0.1:10000:5000 - 127.0.0.1:10000:5000
extra_hosts:
- mqtt:192.168.0.6
notify: notify:
container_name: frigate-notify container_name: frigate-notify
image: frigate-notify:latest image: frigate-notify:latest
restart: unless-stopped restart: unless-stopped
depends_on:
- frigate
- mqtt
environment: environment:
MQTT_USERNAME: frigate
MQTT_PASSWORD: ${MQTT_PASSWORD}
REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
volumes: volumes:
- type: bind - type: bind
@ -69,14 +68,17 @@ services:
source: /etc/localtime source: /etc/localtime
target: /etc/localtime target: /etc/localtime
read_only: true read_only: true
extra_hosts: networks:
- mqtt:192.168.0.6 - frigate
webcontrol: webcontrol:
container_name: frigate-webcontrol container_name: frigate-webcontrol
image: frigate-webcontrol:latest image: frigate-webcontrol:latest
labels: labels:
autoheal: 'true' autoheal: 'true'
restart: unless-stopped restart: unless-stopped
depends_on:
- frigate
- mqtt
healthcheck: healthcheck:
test: curl -s -f http://localhost -o /dev/null test: curl -s -f http://localhost -o /dev/null
interval: 60s interval: 60s
@ -84,40 +86,35 @@ services:
start_period: 30s start_period: 30s
timeout: 30s timeout: 30s
environment: environment:
MQTT_USERNAME: frigate
MQTT_PASSWORD: ${MQTT_PASSWORD}
IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY} IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY}
volumes: volumes:
- type: bind - type: bind
source: /etc/localtime source: /etc/localtime
target: /etc/localtime target: /etc/localtime
read_only: true read_only: true
networks:
- frigate
ports: ports:
- 127.0.0.1:10001:80 - 127.0.0.1:10001:80
extra_hosts: mqtt:
- mqtt:192.168.0.6 container_name: mqtt
# mqtt: image: eclipse-mosquitto:2.0.18
# container_name: mqtt command:
# image: eclipse-mosquitto:latest - mosquitto
# command: - -c
# - mosquitto - /mosquitto-no-auth.conf
# - -c restart: unless-stopped
# - /mosquitto-no-auth.conf volumes:
# restart: unless-stopped - type: bind
# volumes: source: /etc/localtime
# - type: bind target: /etc/localtime
# source: /etc/localtime read_only: true
# target: /etc/localtime networks:
# read_only: true - frigate
# networks:
# - frigate
# ports:
# - 1883:1883
# - 9001:9001
#networks: networks:
# frigate: frigate:
# name: frigate name: frigate
volumes: volumes:
config: config:

View File

@ -1,8 +1,6 @@
- name: Install Frigate - name: Install Frigate
hosts: Barad-dur hosts: Barad-dur
vars_prompt: vars_prompt:
- name: mqtt_password
prompt: Enter password for MQTT user frigate
- name: ipgeolocation_api_key - name: ipgeolocation_api_key
prompt: Enter API key for IPGeolocation prompt: Enter API key for IPGeolocation
- name: garage_rtsp_password - name: garage_rtsp_password
@ -118,8 +116,6 @@
- name: Insert into Postgres table service - name: Insert into Postgres table service
vars: vars:
frigate_config: frigate_config:
mqtt:
password: '{{mqtt_password}}'
ipgeolocation: ipgeolocation:
api_key: '{{ipgeolocation_api_key}}' api_key: '{{ipgeolocation_api_key}}'
rtsp: rtsp:

View File

@ -10,6 +10,7 @@ import paho.mqtt.client as mqtt
class FrigateEventNotifier: class FrigateEventNotifier:
def __init__(self, mqtt_username, mqtt_password, quiet_period=3 * 60): def __init__(self, mqtt_username, mqtt_password, quiet_period=3 * 60):
self.mqtt_client = mqtt.Client() self.mqtt_client = mqtt.Client()
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.username_pw_set(mqtt_username, password=mqtt_password)
self.mqtt_client.on_connect = self._on_connect self.mqtt_client.on_connect = self._on_connect
self.mqtt_client.on_message = self._on_message self.mqtt_client.on_message = self._on_message
@ -114,5 +115,5 @@ class FrigateEventNotifier:
if __name__ == '__main__': 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() frigate_event_notifier.start()

View File

@ -35,7 +35,6 @@
- name: Docker Compose up Frigate - name: Docker Compose up Frigate
environment: environment:
MQTT_PASSWORD: '{{frigate_config.mqtt.password}}'
IPGEOLOCATION_API_KEY: '{{frigate_config.ipgeolocation.api_key}}' IPGEOLOCATION_API_KEY: '{{frigate_config.ipgeolocation.api_key}}'
FRIGATE_GARAGE_RTSP_PASSWORD: '{{frigate_config.rtsp.garage.password}}' FRIGATE_GARAGE_RTSP_PASSWORD: '{{frigate_config.rtsp.garage.password}}'
FRIGATE_FRONT_DOOR_RTSP_PASSWORD: '{{frigate_config.rtsp.front_door.password}}' FRIGATE_FRONT_DOOR_RTSP_PASSWORD: '{{frigate_config.rtsp.front_door.password}}'

View File

@ -53,7 +53,11 @@ def reset_all_camera_detection_at_sunset():
def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None: def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None:
sleep(delay) 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/<string:camera>/detect', methods=['POST']) @blueprint.route('/camera/<string:camera>/detect', methods=['POST'])