-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from BrewBlox/develop
Edge release
- Loading branch information
Showing
34 changed files
with
2,096 additions
and
1,813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.venv/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM python:3.11-bookworm as base | ||
|
||
ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple | ||
ENV PIP_FIND_LINKS=/wheeley | ||
ENV VENV=/app/.venv | ||
ENV PATH="$VENV/bin:$PATH" | ||
|
||
COPY ./dist /app/dist | ||
|
||
RUN <<EOF | ||
set -ex | ||
|
||
mkdir /wheeley | ||
python3 -m venv $VENV | ||
pip3 install --upgrade pip wheel setuptools | ||
pip3 wheel --wheel-dir=/wheeley -r /app/dist/requirements.txt | ||
pip3 wheel --wheel-dir=/wheeley /app/dist/*.tar.gz | ||
EOF | ||
|
||
FROM python:3.11-slim-bookworm | ||
WORKDIR /app | ||
|
||
ENV PIP_FIND_LINKS=/wheeley | ||
ENV VENV=/app/.venv | ||
ENV PATH="$VENV/bin:$PATH" | ||
|
||
COPY --from=base /wheeley /wheeley | ||
COPY ./parse_appenv.py ./parse_appenv.py | ||
COPY ./entrypoint.sh ./entrypoint.sh | ||
|
||
RUN <<EOF | ||
set -ex | ||
|
||
apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
libopenblas-dev | ||
rm -rf /var/cache/apt/archives /var/lib/apt/lists | ||
|
||
python3 -m venv $VENV | ||
pip3 install --no-index brewblox_tilt | ||
pip3 freeze | ||
rm -rf /wheeley | ||
EOF | ||
|
||
ENTRYPOINT ["bash", "./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
from contextlib import AsyncExitStack, asynccontextmanager | ||
from pprint import pformat | ||
|
||
from fastapi import FastAPI | ||
|
||
from . import broadcaster, mqtt, parser, scanner, stored, utils | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def setup_logging(debug: bool): | ||
level = logging.DEBUG if debug else logging.INFO | ||
unimportant_level = logging.INFO if debug else logging.WARN | ||
format = '%(asctime)s.%(msecs)03d [%(levelname).1s:%(name)s:%(lineno)d] %(message)s' | ||
datefmt = '%Y/%m/%d %H:%M:%S' | ||
|
||
logging.basicConfig(level=level, format=format, datefmt=datefmt) | ||
logging.captureWarnings(True) | ||
|
||
logging.getLogger('gmqtt').setLevel(unimportant_level) | ||
logging.getLogger('httpx').setLevel(unimportant_level) | ||
logging.getLogger('httpcore').setLevel(logging.WARN) | ||
logging.getLogger('uvicorn.access').setLevel(unimportant_level) | ||
logging.getLogger('uvicorn.error').disabled = True | ||
logging.getLogger('bleak.backends.bluezdbus.manager').setLevel(unimportant_level) | ||
|
||
|
||
@asynccontextmanager | ||
async def lifespan(app: FastAPI): | ||
LOGGER.info(utils.get_config()) | ||
LOGGER.debug('LOGGERS:\n' + pformat(logging.root.manager.loggerDict)) | ||
|
||
async with AsyncExitStack() as stack: | ||
await stack.enter_async_context(mqtt.lifespan()) | ||
await stack.enter_async_context(broadcaster.lifespan()) | ||
yield | ||
|
||
|
||
def create_app() -> FastAPI: | ||
config = utils.get_config() | ||
setup_logging(config.debug) | ||
|
||
# Call setup functions for modules | ||
mqtt.setup() | ||
stored.setup() | ||
parser.setup() | ||
scanner.setup() | ||
|
||
app = FastAPI(lifespan=lifespan) | ||
return app |
Oops, something went wrong.