Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make configuration directory configurable #109

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,47 @@ Python 3.12.3


### Configuration
sjefferson99 marked this conversation as resolved.
Show resolved Hide resolved

#### Network Ports
The host ports mapped for the slack server and webserver should be configured in the docker compose file, however it is also possible to override the ports in the server configs directly if you are not using docker.

#### External Config Files
Currently, the only external config file is the logging.json file.

This is mapped to /app/config in the container

You can make this location accessible by Mapping the internal directory to a volume or bind mount in the docker compose file.

Linux:
```yaml
volumes:
- /var/smib/config:/app/config/
```

Windows:
```yaml
volumes:
- C:/smib/config:/app/config/
```

Local Development:
- Set the `_EXTERNAL_CONFIG_LOCATION` environment variable to the directory containing the External Config Files

#### Logging
Map the internal /app/logs directory to a volume or bind mount in the docker compose to store the logs outside the containers

Linux:
```yaml
volumes:
- /var/smib/slack/logs:/app/logs/
```

Windows:
```yaml
volumes:
- C:/smib/slack/logs:/app/logs/
```

## SMIBHID
[SMIBHID](smibhid/README.md) is the So Make It Bot Human Interface Device and definitely not a mispronunciation of any insults from a popular 90s documentary detailing the activites of the Jupiter Mining Core.

Expand Down
6 changes: 6 additions & 0 deletions smib-fast.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ COPY --from=builder /etc/localtime /etc/localtime

WORKDIR /app
COPY smib ./smib

# Remove logging.json from container
RUN rm ./smib/logging.json

# Copy logging.json into correct container location
COPY smib/logging.json /app/config/logging.json
2 changes: 2 additions & 0 deletions smib/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
WEBSOCKET_PORT = config('WEBSOCKET_PORT', default=4123, cast=int)
WEBSOCKET_PATH = config('WEBSOCKET_PATH', default='ws', cast=to_path)
WEBSOCKET_URL = urlparse(f"{WEBSOCKET_SCHEME}://{WEBSOCKET_HOST}:{WEBSOCKET_PORT}/{WEBSOCKET_PATH}")

EXTERNAL_CONFIG_LOCATION = config('_EXTERNAL_CONFIG_LOCATION', default='/app/config/', cast=Path)
25 changes: 20 additions & 5 deletions smib/common/logging_/setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import inspect
import json
import logging
import logging.config
from pathlib import Path

from smib.common.config import ROOT_DIRECTORY
from smib.common.config import EXTERNAL_CONFIG_LOCATION
from smib.common.utils import get_module_name
from injectable import injectable_factory, load_injection_container, inject


def read_logging_json(path=ROOT_DIRECTORY / 'logging.json'):
def read_logging_json(path=EXTERNAL_CONFIG_LOCATION / 'logging.json'):
path = Path(path)

logging.basicConfig()
logging.info(f'Resolving logging.json to {path}')

if not (path.exists() and path.is_file()):
logging.warning(f'No logging json file found at {path}')
return None

with open(path, 'rt') as file:
config_file = json.load(file)
return config_file


def setup_logging(path=ROOT_DIRECTORY / 'logging.json'):
logging.config.dictConfig(read_logging_json(path))
def setup_logging(path=EXTERNAL_CONFIG_LOCATION / 'logging.json'):
try:
logging.config.dictConfig(read_logging_json(path))
except Exception as e:
logging.basicConfig()
logger = logging.getLogger('setup_logging')
logger.warning(e)


@injectable_factory(logging.Logger, qualifier="plugin_logger")
Expand Down
2 changes: 1 addition & 1 deletion smib/logging.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"file_handler": {
"class": "smib.common.logging_.handlers.EnsureDirectoryTimedRotatingFileHandler",
"formatter": "detailed",
"filename": "logs/smib.log",
"filename": "/app/logs/smib.log",
"when": "midnight",
"interval": 1,
"backupCount": 7
Expand Down