Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearranging code directories #41

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/container_workflows.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# This is a workflow to build images
name: Build Docker Images

on: [push]
on:
push:
branches:
- release

jobs:
#TODO: redo the tests with the new arrangement
build:
name: Build Docker Image
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ We welcome pull requests!

### Organization of source code

- `app` is the frontend TypeScript / React application
- `api` is the backend Python / FastApi application
- `deploy` has code for deploying the system
- `hubfrontend` is a Typescript / React app that serves as the frontend for the system.
- `backendconfigserver` is an HTTP server which serves the configuration for the detectors.
- `deploy` has code for deploying the system in various environments
File renamed without changes.
9 changes: 7 additions & 2 deletions backend.Dockerfile → backendconfigserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
FROM python:3.9-slim-bookworm
FROM python:3.11-slim-bookworm

RUN apt-get update && \
apt-get install -y \
sudo && \
apt-get clean

WORKDIR /app

COPY ./requirements.txt /app/requirements.txt

RUN pip3 install --no-cache-dir --upgrade -r /app/requirements.txt
RUN pip3 install opencv-python-headless==4.8.0.74
RUN pip3 install opencv-python-headless>=4.8

RUN pip install --index-url=https://www.piwheels.org/simple --no-cache-dir -r /app/requirements.txt
RUN pip install --no-deps groundlight
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM python:3.9-slim-buster
FROM python:3.11-slim-buster

RUN apt-get update && \
apt-get install -y \
sudo && \
apt-get clean

WORKDIR /app

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 93 additions & 0 deletions backendconfigserver/api/rtsp_scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# check if the -v flag is present
if [[ $1 == "-v" ]]; then
VERBOSE=1
else
VERBOSE=0
fi

# Function to install necessary dependencies
install_dependencies() {
echo "Installing dependencies..."
sudo apt update
sudo apt install -y nmap net-tools iproute2
}

# Function to find subnets
find_subnets() {
# This function finds the subnets associated with your physical network interfaces
# It excludes loopback, virtual, and docker interfaces

# List all network interfaces except loopback and docker/virtual interfaces
local interfaces=$(ip -br link | awk '$1 !~ /^lo|docker|veth|br-|virbr/ {print $1}')

# Loop through each interface to find its subnet
for interface in $interfaces; do
# Get the IP address and subnet mask for each interface
ip -4 addr show $interface | grep -oP '(?<=inet\s)\d+(\.\d+){3}/\d+' | while read -r subnet; do
# check if the subnet is bigger than /24 first
# first
echo "$subnet"
done
done
}


# Function to scan a given subnet
scan_subnet() {
local subnet=$1

# parse the subnet string, which looks like "192.168.1.7/16" into base and mask
local base=$(echo "$subnet" | cut -d '/' -f 1)
local mask=$(echo "$subnet" | cut -d '/' -f 2)

# If the mask is smaller than /24, we'll want to use a faster scan
# Otherwise, we'll use a slower but more reliable scan
if [[ $mask -lt 24 ]]; then
if [[ $mask -lt 22 ]]; then
# Limit size of scan
mask=22
if [[ $VERBOSE -eq 1 ]]; then
echo "Limiting subnet $subnet to /$mask so scan doesn't take forever."
echo "For a full scan, run 'nmap -T4 -p 554 --open -oG - $subnet'"
fi
fi
# T5 is "insane" and super fast, but can be unreliable. (e.g. 5s for /22)
# Limiting to T4 since that finds things reliably for me.
SPEED=-T4
else
# It's 24 or less, so use a fast but reliable scan
SPEED=-T4
fi
# re-assamble the subnet string
subnet="$base/$mask"
if [[ $VERBOSE -eq 1 ]]; then
echo "Scanning subnet $subnet at speed $SPEED"
fi

# T5 is "insane" and super fast, but perhaps unreliable. (e.g. 5s for /22)
# T4 is safer, but much slower. (e.g. 26s for /22)
SPEED=-T5

# Run Nmap with Grepable output, then parse to list hosts with open port 554
nmap $SPEED -p 554 --open -oG - $subnet | grep '/open/' | awk '{ print $2 }' | while read -r host; do
echo "rtsp://admin:admin@$host:554"
done
}


# Main execution
main() {
# check if `ip` and `nmap` are available
if ! command -v ip &> /dev/null || ! command -v nmap &> /dev/null; then
echo "Missing dependencies. Attempting to install them"
install_dependencies
fi
find_subnets | while read -r subnet; do
scan_subnet "$subnet"
done
}

main

File renamed without changes.
2 changes: 1 addition & 1 deletion requirements.txt → backendconfigserver/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fastapi==0.95.2
uvicorn[standard]
groundlight
opencv-python==4.8.0.74
opencv-python>=4.8
framegrab
pypylon
slack_sdk
Expand Down
19 changes: 0 additions & 19 deletions deploy/docker-compose.yml

This file was deleted.

21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "2"
services:
hubfrontend:
build: ./hubfrontend
ports:
- "80:3000"
depends_on:
- backendconfigserver
backendconfigserver:
build: ./backendconfigserver
ports:
- "8000:8000"
devices:
- /dev/video0:/dev/video0
- /dev/video1:/dev/video1
- /dev/video2:/dev/video2
- /dev/video3:/dev/video3
privileged: true
# Seems balena doesn't like volume mounting.
#volumes:
#- /dev/bus/usb:/dev/bus/usb
12 changes: 6 additions & 6 deletions frontend.Dockerfile → hubfrontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM base AS deps
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
Expand All @@ -20,8 +20,8 @@ RUN \
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps --link /app/node_modules ./node_modules
COPY --link . .
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
Expand All @@ -45,12 +45,12 @@ RUN \
addgroup --system --gid 1001 nodejs; \
adduser --system --uid 1001 nextjs

COPY --from=builder --link /app/public ./public
COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --link --chown=1001:1001 /app/.next/standalone ./
COPY --from=builder --link --chown=1001:1001 /app/.next/static ./.next/static
COPY --from=builder --chown=1001:1001 /app/.next/standalone ./
COPY --from=builder --chown=1001:1001 /app/.next/static ./.next/static

USER nextjs

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.