Skip to content
Snippets Groups Projects
Commit 33e585df authored by David Trattnig's avatar David Trattnig
Browse files

Docker config and docs. #1

parent ff7bcc57
No related branches found
No related tags found
No related merge requests found
...@@ -72,3 +72,5 @@ python ...@@ -72,3 +72,5 @@ python
# Configurations # Configurations
config/engine-api.ini config/engine-api.ini
config/gunicorn.conf.py config/gunicorn.conf.py
config/docker/engine-api.ini
config/docker/gunicorn.conf.py
...@@ -10,14 +10,16 @@ RUN mkdir -p /var/log/aura ...@@ -10,14 +10,16 @@ RUN mkdir -p /var/log/aura
COPY . /srv COPY . /srv
WORKDIR /srv WORKDIR /srv
RUN pip3 install --no-cache-dir -r requirements.txt RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir -r contrib/mariadb-requirements.txt
ENV PYTHONPATH "${PYTHONPATH}:/srv/src"
# Create default config # Create default config
COPY config/sample/gunicorn/sample-docker.gunicorn.conf.py config/docker/gunicorn.conf.py COPY ./config/sample/gunicorn/sample-docker.gunicorn.conf.py /srv/config/gunicorn.conf.py
# Start the API Server # Start the API Server
EXPOSE 8008 EXPOSE 8008
ENTRYPOINT ["gunicorn"] ENTRYPOINT ["gunicorn"]
CMD ["-c", "/srv/config/docker/gunicorn.conf.py", "src.app:app"] CMD ["-c", "/srv/config/gunicorn.conf.py", "src.app:app"]
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
- [Running with Systemd](#running-with-systemd) - [Running with Systemd](#running-with-systemd)
- [Running with Supervisor](#running-with-supervisor) - [Running with Supervisor](#running-with-supervisor)
- [Running with Docker](#running-with-docker) - [Running with Docker](#running-with-docker)
- [Using the API](#using-the-api) - [Creating a local image (Developers)](#creating-a-local-image-developers)
- [Publish new image (Developers)](#publish-new-image-developers)
- [Using the API (Developers)](#using-the-api-developers)
- [About](#about) - [About](#about)
<!-- /TOC --> <!-- /TOC -->
...@@ -218,7 +220,7 @@ If this is succeeding, you can now proceed to configure Engine API to run as a s ...@@ -218,7 +220,7 @@ If this is succeeding, you can now proceed to configure Engine API to run as a s
The Systemd unit file configuration expects to be running under the user `engineuser`. To create such user type: The Systemd unit file configuration expects to be running under the user `engineuser`. To create such user type:
```shell ```bash
sudo adduser engineuser sudo adduser engineuser
sudo adduser engineuser sudo sudo adduser engineuser sudo
``` ```
...@@ -228,32 +230,32 @@ Engine API installed under `/opt/aura/engine-api` and `engineuser` owning the fi ...@@ -228,32 +230,32 @@ Engine API installed under `/opt/aura/engine-api` and `engineuser` owning the fi
Next login to `engineuser` and give it permissions to the unit file Next login to `engineuser` and give it permissions to the unit file
```shell ```bash
su engineuser su engineuser
sudo chmod 644 /etc/systemd/system/aura-engine-api.service sudo chmod 644 /etc/systemd/system/aura-engine-api.service
``` ```
Let's start the service Let's start the service
```shell ```bash
sudo systemctl start aura-engine-api sudo systemctl start aura-engine-api
``` ```
And check if it has started successfully And check if it has started successfully
```shell ```bash
sudo systemctl status aura-engine-api sudo systemctl status aura-engine-api
``` ```
If you experience issues and need more information, check the syslog while starting the service If you experience issues and need more information, check the syslog while starting the service
```shell ```bash
tail -f /var/log/syslog tail -f /var/log/syslog
``` ```
You can stop or restart the service with one of these You can stop or restart the service with one of these
```shell ```bash
sudo systemctl stop aura-engine-api sudo systemctl stop aura-engine-api
sudo systemctl restart aura-engine-api sudo systemctl restart aura-engine-api
``` ```
...@@ -267,20 +269,47 @@ can find an example Supervisor configuration file. Follow the initial steps of t ...@@ -267,20 +269,47 @@ can find an example Supervisor configuration file. Follow the initial steps of t
### Running with Docker ### Running with Docker
To run the server in a Docker container, please execute the following from the root directory: Having the configuration files `engine-api.ini` and `gunicorn.conf.py` located in `./config/docker`,
you can run the API server in a Docker container this way
```bash ```bash
# Building the image exec sudo docker run \
./run.sh docker:build --network="host" \
--name engine-api \
--rm -d \
-u $UID:$GID \
-p 8008:8008 \
-v "$BASE_D":/srv \
-v "$BASE_D/config/docker":/srv/config \
--tmpfs /var/log/aura/ autoradio/engine-api
```
# Push the current image to dockerhub.com The project also contains a convenience script to get started with a one-liner
./run.sh docker:push
# Starting up a container ```bash
# Start up a container
./run.sh docker:api ./run.sh docker:api
``` ```
## Using the API #### Creating a local image (Developers)
If you are a developer and want to create a local image, run
```bash
# Build the image
./run.sh docker:build
```
#### Publish new image (Developers)
If you are developer and want to publish a new image to DockerHub, run
```bash
# Releasing the image to DockerHub
./run.sh docker:push
```
## Using the API (Developers)
You can find details on the available API endpoints here: https://app.swaggerhub.com/apis/AURA-Engine/engine-api/1.0.0 You can find details on the available API endpoints here: https://app.swaggerhub.com/apis/AURA-Engine/engine-api/1.0.0
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
# range. # range.
# #
pythonpath = "/opt/aura/engine-api" pythonpath = "/srv"
bind = '172.17.0.1:8008' bind = '0.0.0.0:8008'
backlog = 2048 backlog = 2048
# #
......
#######################
# Engine API Settings #
#######################
[database]
db_user="aura"
db_name="aura_engine_api"
db_pass="---SECRET--PASSWORD---"
db_host="localhost"
db_charset="utf8"
[monitoring]
logdir="./logs"
# possible values: debug, info, warning, error, critical
loglevel="info"
debug_flask="false"
[api]
api_port=8008
[federation]
# Defines the engine number id for identification of record sources. Default values are:
#
# 1 ... Engine 1 (main node)
# 2 ... Engine 2 (main node, not needed for single deployment)
# 0 ... Sync Host (sync node, not needed for single engine deployment)
#
# Engine API supports two deployment models:
#
# - "main": Deployed together with some `engine` (Single instance or for redundant engines)
# - "sync": Independent deployment, in charge of syncing data of two main-nodes
#
# The `synch_host` identifies the host where data is gathered from/synced to, depended on the
# chosen `node_type`.
# NODE 1
; host_id=1
; sync_host="http://engine.sync.local:8008"
# NODE 2
; host_id=2
; sync_host="http://engine.sync.local:8008"
# NODE SYNC
; host_id=0
; main_host_1="http://engine1.local:8008"
; main_host_2="http://engine2.local:8008"
; default_source=1
; sync_interval=3600
; sync_batch_size=100
; sync_step_sleep=2
# API endpoints to sync data from main to child nodes
sync_api_store_playlog="/api/v1/playlog/store"
sync_api_store_healthlog="/api/v1/source/health"
sync_api_get_playlog="/api/v1/playlog"
\ No newline at end of file
...@@ -101,11 +101,14 @@ if [[ $docker == "true" ]]; then ...@@ -101,11 +101,14 @@ if [[ $docker == "true" ]]; then
### Runs Engine API using Gunicorn ### ### Runs Engine API using Gunicorn ###
if [[ $mode == "api" ]]; then if [[ $mode == "api" ]]; then
exec sudo docker run --name engine-api --rm -it \ exec sudo docker run \
--network="host" \
--name engine-api \
--rm -d \
-u $UID:$GID \ -u $UID:$GID \
-p 8008:8008 \ -p 8008:8008 \
-v "$BASE_D":/srv \ -v "$BASE_D":/srv \
-v "$BASE_D/config/docker":/etc/aura \ -v "$BASE_D/config/docker":/srv/config \
--tmpfs /var/log/aura/ autoradio/engine-api --tmpfs /var/log/aura/ autoradio/engine-api
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment