Skip to content

Commit

Permalink
Merge pull request #1 from maexled/docker
Browse files Browse the repository at this point in the history
Added Dockerfile
  • Loading branch information
maexled authored Jun 3, 2022
2 parents 4010032 + d5b09a6 commit df511e4
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 18 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy-docker-image-on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Create and publish a Docker image on Release

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.9-slim-buster

WORKDIR /camera

COPY requirements.txt ./

RUN apt update && \
apt upgrade -y && \
apt install ffmpeg zip curl -y && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
rm -rf /var/lib/apt/lists/*


COPY . .
RUN mkdir files

CMD ["bash", "move.sh"]
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,68 @@
### About the Project
## About the Project
The project is designed to manage images uploaded by a (Hikvision) IP-Camera in a folder using FTP. The images in the `temp/` Folder are moved by the `move.sh` script in the right folder named by it's current date. Every night should be the `raffer.sh` script automatically started to render the images to one full video. Optionally the videos are uploaded to specific nextcloud server, configurable in `config.cfg`

### Prerequisites
## Prerequisites

* ffmpeg
```sh
sudo apt install ffmpeg
* python3

### Installation
## Installation
### Be stupid and do it with bash

1. Clone the repo
```sh
git clone https://github.com/maexled/camera-images-bash-manager.git
cd camera-images-bash-manager/
```
2. Create files folder
3. Install needed python libraries
```sh
pip install -r requirements.txt
```
3. Create files folder
```sh
mkdir files
```
3. Define variables in `config.cfg`
4. Define variables in `config.cfg`
```bash
fps="10"
samba_user="samba"
object_detection="true"
save_longtime_pictures="true"
save_object_detection="true"
save_to_nextcloud="true"
nextcloud_host="https://yournextcloud.com"
nextcloud_path="Videos"
nextcloud_username="Maexled"
nextcloud_password="YourSecretPassword"
4. Start `move.sh` in screen
fps="10"
raffer_execution="00:15"
samba_user="samba"
object_detection="true"
save_longtime_pictures="true"
save_object_detection="true"
save_to_nextcloud="true"
nextcloud_host="https://yournextcloud.com"
nextcloud_path="Videos"
nextcloud_username="Maexled"
nextcloud_password="YourSecretPassword"
```
- `samba_user` - is the user who will own the moved files
- `raffer_execution` - if you want to execute raffer in other ways (e.g cron), keep it empty

The other variables should be self-explanatory

5. Start `move.sh` in screen
```sh
bash move.sh
```
5. Create crontab for `raffer.sh`, for example crontab -e
6. Create crontab for `raffer.sh`, for example crontab -e
```sh
15 0 * * * bash /camera/raffer.sh
```
This will execute everyday 00:15 the raffer script makes the video then.

### Be smart and do it with docker!
```sh
docker run \
--name camera-images-manager \
-v /home/max/cameratest/files:/camera/files \
-v /home/max/cameratest/temp:/camera/temp \
-v /home/max/cameratest/config.cfg:/camera/config.cfg \
-e TZ=Europe/Berlin \
camera-images-bash
```
#### Configuration variables in config.cfg:
- `samba_user` - recommened to set it as root. In container no extra user will be created.

1 change: 1 addition & 0 deletions config.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fps="10"
raffer_execution="00:15"
samba_user="samba"
object_detection="true"
longtime_pictures="true"
Expand Down
12 changes: 12 additions & 0 deletions move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ check=1;
# For longtime picture of the hour to move at least every hour a picture if enabled
last=-1;

# Store last day raffer was executed so it do not happens multiple times on day
raffer_last_executed_day=-1

while [ true ]; do
date=$(date --date='+0 hour' +'%m/%d/%Y, %H:%M:%S')
datedir=$(date --date='+0 hour' +'%Y/%m/%d')
Expand Down Expand Up @@ -54,5 +57,14 @@ while [ true ]; do
fi
done;
check=$((check + 1));

# Check for time to start raffer
if [ $(date +%H:%M) == "$raffer_execution" ] && [ $(date +%d) -ne "$raffer_last_executed_day" ];
then
raffer_last_executed_day=$(date +%d)
echo "Starting raffer in background..."
bash $DIR/raffer.sh &
fi

sleep 1;
done;
2 changes: 1 addition & 1 deletion raffer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ echo Starting;

DIR="$(cd "$(dirname "$0")" && pwd)"

source $DIR/config.cf
source $DIR/config.cfg

datediryesterday=$DIR/files/$(date --date='-1 day' +'%Y/%m/%d')
fulldateyesterday=$(date --date='-1 day' +'%Y-%m-%d')
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy==1.22.4
imutils==0.5.4
opencv-python==4.5.5.64

0 comments on commit df511e4

Please sign in to comment.