fix regtests, admin settings prints

This commit is contained in:
dni ⚡ 2022-10-03 23:33:42 +02:00
parent d432a967f1
commit 6ae35868c0
3 changed files with 27 additions and 16 deletions

View File

@ -12,7 +12,7 @@ WORKDIR /app
COPY . .
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev --no-root
RUN poetry install --only main --no-root
RUN poetry run python build.py
ENV LNBITS_PORT="5000"

View File

@ -12,7 +12,7 @@ import time
import click
import uvicorn
from lnbits.settings import settings
from lnbits.settings import settings, set_cli_settings
@click.command(
@ -29,6 +29,9 @@ from lnbits.settings import settings
@click.pass_context
def main(ctx, port: int, host: str, ssl_keyfile: str, ssl_certfile: str, reload: bool):
"""Launched with `poetry run lnbits` at root level"""
set_cli_settings(host=host, port=port)
# this beautiful beast parses all command line arguments and passes them to the uvicorn server
d = dict()
for a in ctx.args:
@ -44,17 +47,16 @@ def main(ctx, port: int, host: str, ssl_keyfile: str, ssl_certfile: str, reload:
d[a.strip("--")] = True # argument like --key
while True:
# loop = asyncio.new_event_loop()
config = uvicorn.Config(
"lnbits.__main__:app",
port=port,
host=host,
reload=reload,
# loop=loop,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
**d
)
server = uvicorn.Server(config=config)
process = mp.Process(target=server.run)
process.start()

View File

@ -28,9 +28,9 @@ class Settings(BaseSettings):
lnbits_admin_ui: bool = Field(default=False)
# .env
debug: Optional[bool]
host: Optional[str]
port: Optional[int]
debug: bool = Field(default=False)
host: str = Field(default="127.0.0.1")
port: int = Field(default=5000)
lnbits_path: str = Field(default=".")
lnbits_commit: str = Field(default="unknown")
@ -132,14 +132,18 @@ class Settings(BaseSettings):
settings = Settings()
settings.lnbits_path = str(path.dirname(path.realpath(__file__)))
settings.lnbits_commit = (
subprocess.check_output(
["git", "-C", settings.lnbits_path, "rev-parse", "HEAD"],
stderr=subprocess.DEVNULL,
try:
settings.lnbits_commit = (
subprocess.check_output(
["git", "-C", settings.lnbits_path, "rev-parse", "HEAD"],
stderr=subprocess.DEVNULL,
)
.strip()
.decode("ascii")
)
.strip()
.decode("ascii")
)
except:
settings.lnbits_commit = "docker"
if not settings.lnbits_admin_ui:
@ -147,6 +151,9 @@ if not settings.lnbits_admin_ui:
for key, value in settings.dict(exclude_none=True).items():
logger.debug(f"{key}: {value}")
def set_cli_settings(**kwargs):
for key, value in kwargs.items():
setattr(settings, key, value)
async def check_admin_settings():
if settings.lnbits_admin_ui:
@ -196,17 +203,19 @@ async def check_admin_settings():
admin = Settings(**row)
logger.debug(f"Admin settings:")
for key, value in admin.dict(exclude_none=True).items():
if not key in read_only_variables:
try:
setattr(settings, key, value)
logger.debug(f"{key}: {value}")
except:
logger.error(
f"error overriding setting: {key}, value: {value}"
)
logger.debug(f"Admin settings:")
for key, value in settings.dict(exclude_none=True).items():
logger.debug(f"{key}: {value}")
http = "https" if settings.lnbits_force_https else "http"
user = settings.lnbits_admin_users[0]
logger.warning(