diff --git a/.env_sample b/.env_sample index 3661206..09b1666 100644 --- a/.env_sample +++ b/.env_sample @@ -2,4 +2,5 @@ SLEEP_DATA_PATH=/path/to/sleep/data DEBUG=False OWL=False VIDEO_PATH=/path/to/video -HATCH_IP=192.168.HATCH.IP \ No newline at end of file +HATCH_IP=192.168.HATCH.IP +CAM_STREAM_URL=192.168.1.100:554/h264Preview_01_sub \ No newline at end of file diff --git a/.env_sample_docker b/.env_sample_docker new file mode 100644 index 0000000..718f35f --- /dev/null +++ b/.env_sample_docker @@ -0,0 +1,7 @@ +SLEEP_DATA_PATH=/usr/app/babysleepcoach +DEBUG=False +OWL=False +VIDEO_PATH=/usr/app/babysleepcoach/video +HATCH_IP=192.168.HATCH.IP +CAM_STREAM_URL=192.168.1.100:554/h264Preview_01_sub +REACT_APP_BACKEND_URL=http://10.0.0.2:7081 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 72fd018..c665612 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ build !*.ipynb !requirements.txt !.env_sample +!.env_sample_docker +!dockerfile +!start_docker.sh diff --git a/README.md b/README.md index 49a38c7..893cb5f 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,25 @@ And you'll probably get a warning about the app trying to boot on port `80`. You You'll need to update some paths and IPs in the code.

## Someone send me proof you got it all running. + +

+## Docker +It is also possible to install the app into a docker container. +Clone the repository. Navigate to the path and build the docker image. + ``` +docker image build -t babysleepcoach . +``` +Run the container (adjust the ports, URLs and path). + +With an environment file (for the .env file see env_sample_docker): +``` +docker run -d -p7080:80 -p7081:8000 --env-file .env --name babysleepcoach babysleepcoach +``` + +Or with the parameters direct via command line: +``` +docker run -d -p7080:80 -p7081:8000 -e REACT_APP_BACKEND_URL=URL_OF_THE_DOCKER_CONTAINER:7081 -e CAM_STREAM_URL=rtsp://user:password@URL_OF_CAMERA:554/stream1 -e DEBUG=False -e OWL=False -e HATCH_IP=127.0.0.1 -v /PATH_TO_SLEEP_LOGS_ON_HOST/sleep_logs.csv:/usr/app/babysleepcoach/sleep_logs.csv --name babysleepcoach babysleepcoach +``` + +The frontend can be accessed via http://URL_OF_THE_DOCKER_CONTAINER:7080 (or the port you wrote in the run command). + diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..0a74b23 --- /dev/null +++ b/dockerfile @@ -0,0 +1,21 @@ +#Deriving the latest base image +FROM node:slim + +WORKDIR /usr/app/babysleepcoach + +RUN mkdir -p video + +#Copy all files in the container +COPY . . + +# Install required packages +RUN apt-get update && apt-get install python3-pip libgl1 libglib2.0-0 -y +RUN pip3 install --upgrade pip +RUN pip3 install -r requirements.txt + +RUN cd webapp && yarn install + +ENV SLEEP_DATA_PATH=/usr/app/babysleepcoach +ENV VIDEO_PATH=/usr/app/babysleepcoach/video + +CMD ["./start_docker.sh"] \ No newline at end of file diff --git a/main.py b/main.py index 2a6be97..388fafb 100644 --- a/main.py +++ b/main.py @@ -471,7 +471,7 @@ def live(self, consumer_q): w = 800 if img.shape[0] > 1080 and img.shape[1] > 1920: # max res 1080p - img = maintain_aspect_ratio_resize(img, width=self.frame_dim[0], height=self.frame_dim[1]) + img = maintain_aspect_ratio_resize(self=self, image=img, width=self.frame_dim[0], height=self.frame_dim[1]) img_to_process = img[y:y+h, x:x+w] @@ -545,10 +545,9 @@ def start_server(): def receive(producer_q): print("Start receiving frames.") - cam_ip = os.environ['CAM_IP'] - cam_pw = os.environ['CAM_PW'] - connect_str = "rtsp://admin:" + cam_pw + "@" + cam_ip - connect_str2 = connect_str + ":554" + "//h264Preview_01_sub" # this might be different depending on camera used + + cam_stream_url = os.environ['CAM_STREAM_URL'] + connect_str = cam_stream_url os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;tcp' # Use tcp instead of udp if stream is unstable c = cv2.VideoCapture(connect_str) diff --git a/start_docker.sh b/start_docker.sh new file mode 100644 index 0000000..453a5f1 --- /dev/null +++ b/start_docker.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +python3 main.py & +cd /usr/app/babysleepcoach/webapp +yarn start \ No newline at end of file diff --git a/webapp/src/App.js b/webapp/src/App.js index 8b5908b..fe410e3 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -133,7 +133,7 @@ const createCrazyCircles = (events, forecast) => { const offset = 50; const img = new Image(); - img.src = "http://this_device_ip:8000//absolute_path_to_project_dir/webapp/public/baby_face_192.png"; + img.src = process.env.REACT_APP_BACKEND_URL + "/webapp/public/baby_face_192.png"; img.addEventListener("load", (e) => { context.save(); context.beginPath(); @@ -371,7 +371,7 @@ const processSleepLogs = async (forecast) => { const file = forecast ? 'sleep_logs_forecasted' : 'sleep_logs'; // Request sleep log data from HTTP server on the device (somewhere on LAN) which is running with sleep tracking service - const sleepLogs = await d3.csv(`http://ip_address_of_device_running_sleep_tracker:8000/path_on_device_to_sleep_log_csv_file/${file}.csv`); + const sleepLogs = await d3.csv(process.env.REACT_APP_BACKEND_URL + `/${file}.csv`); // convert timestamps to date objects sleepLogs.forEach((d) => {