Added docker support

This commit is contained in:
Jeff Laflamme 2024-06-27 11:25:36 +07:00
parent af95c0175b
commit 46c38748cf
6 changed files with 56 additions and 5 deletions

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM python:3.8
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["python", "-u", "server.py"]

View File

@ -48,7 +48,9 @@ source venv/bin/activate
pip install -r requirements.txt
```
5. Set up the configuration in `config.ini`:
5. Configuration
- Copy config/config.init.sample to config/config.ini
- Set up the configuration in `config.ini`:
**[interface]**
@ -73,7 +75,7 @@ pip install -r requirements.txt
```ini
[interface]
type = serial
# port = /dev/ttyUSB0
# port = /dev/ttyUSB0 # or /dev/ttyACM0
# hostname = 192.168.x.x
[sync]
@ -90,6 +92,16 @@ python server.py
Be sure you've followed the Python virtual environment steps above and activated it before running.
## Docker
The docker entrypoint.sh will automatically copy config.ini.sample to config.ini
if you want to edit config, make sure you add the config directory as a docker volume.
```sh
docker run -it --name tc2bbsmesh -v tc2bbsmesh-config:/config/ -v tc2bbsmesh-data:/data/ --device=/dev/ttyACM0 tc2-bbs-mesh
```
Tested on Orange Pi 3 LTS (Armbian), but should work on all linux distros.
## Features
- **Mail System**: Send and receive mail messages.

View File

@ -17,7 +17,7 @@
[interface]
type = serial
# port = /dev/ttyUSB0
# port = /dev/ttyACM0
# hostname = 192.168.x.x

View File

@ -2,11 +2,12 @@ import configparser
import time
import meshtastic.serial_interface
import meshtastic.tcp_interface
import os
import serial.tools.list_ports
def initialize_config():
config = configparser.ConfigParser()
config.read('config.ini')
config.read(os.getenv('CONFIG_FILE', 'config/config.ini'))
interface_type = config['interface']['type']
hostname = config['interface'].get('hostname', None)

View File

@ -1,4 +1,5 @@
import logging
import os
import sqlite3
import threading
import uuid
@ -16,7 +17,7 @@ thread_local = threading.local()
def get_db_connection():
if not hasattr(thread_local, 'connection'):
thread_local.connection = sqlite3.connect('bulletins.db')
thread_local.connection = sqlite3.connect(os.getenv('DB_FILE', 'data/bulletins.db'))
return thread_local.connection
def initialize_database():

23
entrypoint.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
CONFIG_DIR=/app/config
CONFIG_FILE=$CONFIG_DIR/config.ini
SAMPLE_FILE=config.ini.sample
# Create the config directory if it does not exist
mkdir -p $CONFIG_DIR
# Check if the config file exists, if not, copy the sample file
if [ ! -f $CONFIG_FILE ]; then
if [ -f $SAMPLE_FILE ]; then
cp $SAMPLE_FILE $CONFIG_FILE
echo "Copied $SAMPLE_FILE to $CONFIG_FILE"
else
echo "Sample file $SAMPLE_FILE does not exist. Please provide a sample file."
fi
else
echo "Config file $CONFIG_FILE already exists."
fi
exec "$@"