Skip to content

Commit

Permalink
feat: First version
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonf committed Jul 9, 2024
1 parent 0f38a17 commit aa1da67
Show file tree
Hide file tree
Showing 30 changed files with 1,512 additions and 1 deletion.
63 changes: 63 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release

on:
push:
branches:
- main

permissions:
contents: write
pages: write
id-token: write

jobs:
pages:
runs-on: ubuntu-latest
environment:
name: Development

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

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 21

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y python3-pip python3-venv
npm install @semantic-release/[email protected]
npm install @semantic-release/[email protected]
npm install @semantic-release/[email protected]
npm install @semantic-release/[email protected]
npm install @saithodev/[email protected]
- name: Make release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: npx semantic-release --debug

- name: Create documentation
run: |
python3 -m venv venv
source venv/bin/activate
pip install .
cd docs && make html && cd ..
mkdir public
mv docs/build/html/* public/
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
136 changes: 136 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#vscode
.history/

#Emacs
*~

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
19 changes: 19 additions & 0 deletions .release/update_version_number.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# This script has to be called from the root of the repository

if [[ $# -eq 0 ]] ; then
echo "Usage: $0 <VERSION_NUMBER>"
exit 0
fi

VERSION=${1}

# service-template a.b.c
sed -i "s/## RidgeRun Analytics Microservice [[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/## RidgeRun Analytics Microservice ${VERSION}/g" README.md
#version="a.b.c"
sed -i "s/version=\"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\"/version=\"${VERSION}\"/g" setup.py
# release = 'a.b.c'
sed -i "s/release = '[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+'/release = '${VERSION}'/g" docs/source/conf.py
# version: a.b.c
sed -i "s/version: [[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/version: ${VERSION}/g" api/openapi.yaml
17 changes: 17 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/exec", {
"prepareCmd": "./.release/update_version_number.sh ${nextRelease.version}"
}],
["@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}],
["@semantic-release/git", {
"assets": ["CHANGELOG.md", "README.md", "api/openapi.yaml", "docs/source/conf.py", "setup.py"],
"message": "Bump version number to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
"@semantic-release/github"
]
}
Empty file added CHANGELOG.md
Empty file.
95 changes: 94 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,94 @@
# analytics-service
## RidgeRun Analytics Microservice 1.0.0


Analytics Microservice reads the detection metadata from redis and executes the enabled actions.
The actions can be: move the camera to the detected object position in PTZ microservice
and start an event recording in VST microservice.

By default all the actions are disabled, you need to enable them through a configuration file or
the server with the [configuration request](api/openapi.yaml).
In both cases, the configuration is defined in JSON format as follows:

```bash
{
"move_camera": {
"enable": 1,
"port": 5030,
"ip": "127.0.0.1"
},
"record": {
"enable": 0,
"port": 81,
"ip": "127.0.0.1"
}
}
```
As you can see the configuration allows you to enable/disable each of the available actions
and configure the URI of the corresponding microservice.

### Running the service

The project is configured (via setup.py) to install the service with the name __analytics__. So to install it run:

```bash
pip install .
```

Then you will have the service with the following options:

```bash
usage: analytics [-h] [--port PORT] [--host HOST] [--config-file CONFIG_FILE]

options:
-h, --help show this help message and exit
--port PORT Port for server
--host HOST Server ip address
--config-file CONFIG_FILE
Configuration JSON file
```


To start the service in address 127.0.0.1 and port 5040 just run:
```bash
analytics
```

If you want to serve in a different port or address, use the __--port__ and __--host__ options.


## Analytics Docker


### Build the container

You can build the analytics microservice container using the Dockerfile in the docker directory.
This includes a base LT4 image and the dependencies to run the analytics microservice application.

First, we need to prepare a context directory for this build, you need to create a directory
and include this repository and the rrms-utils project. The Dockerfile will look for both packages
in the context directory and will copy them to the container.

```bash
analytics-context/
├── analytics
└── rrms-utils
```

Then build the container image with the following command:

```bash
DOCKER_BUILDKIT=0 docker build --network=host --tag ridgerun/analytics-service --file analytics-context/analytics/docker/Dockerfile analytics-context/
```

Change analytics-context/ to your context's path and the tag to the name you want to give to the image.

### Launch the container

The container can be launched by running the following command:

```bash
docker run --runtime nvidia -it --network host --volume /home/nvidia/analytics-configs/:/configs --name analytics-service ridgerun/analytics-service:latest analytics --host 0.0.0.0 --config-file /configs/analytics.json
```

Here we are creating a container called analytics-service that will start the analytics application,
launching the server allowing access to any IP available in the device. Also provides a configuration file through the configs volume.
Empty file added analytics/__init__.py
Empty file.
Empty file.
Loading

0 comments on commit aa1da67

Please sign in to comment.