feat: add prefix for env variables
This commit is contained in:
parent
f8797de8e7
commit
dba4c50437
@ -15,9 +15,9 @@ RUN apt-get update && \
|
||||
apt-get purge -y --auto-remove build-essential python3-dev
|
||||
# ref: https://github.com/docker-library/python/issues/60#issuecomment-134322383
|
||||
|
||||
ENV DEFAULT_SETTINGS_FILE=/cfg/settings.toml
|
||||
ENV DEFAULT_LOG_DIR=/log
|
||||
ENV DEFAULT_OUT_DIR=/rec
|
||||
ENV BLREC_DEFAULT_SETTINGS_FILE=/cfg/settings.toml
|
||||
ENV BLREC_DEFAULT_LOG_DIR=/log
|
||||
ENV BLREC_DEFAULT_OUT_DIR=/rec
|
||||
ENV TZ="Asia/Shanghai"
|
||||
|
||||
EXPOSE 2233
|
||||
|
@ -17,9 +17,9 @@ RUN sed -i "s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.li
|
||||
apt-get purge -y --auto-remove build-essential python3-dev
|
||||
# ref: https://github.com/docker-library/python/issues/60#issuecomment-134322383
|
||||
|
||||
ENV DEFAULT_SETTINGS_FILE=/cfg/settings.toml
|
||||
ENV DEFAULT_LOG_DIR=/log
|
||||
ENV DEFAULT_OUT_DIR=/rec
|
||||
ENV BLREC_DEFAULT_SETTINGS_FILE=/cfg/settings.toml
|
||||
ENV BLREC_DEFAULT_LOG_DIR=/log
|
||||
ENV BLREC_DEFAULT_OUT_DIR=/rec
|
||||
ENV TZ="Asia/Shanghai"
|
||||
|
||||
EXPOSE 2233
|
||||
|
18
README.md
18
README.md
@ -79,9 +79,9 @@
|
||||
|
||||
### 环境变量
|
||||
|
||||
- 默认设置文件位置: `ENV DEFAULT_SETTINGS_FILE=/cfg/settings.toml`
|
||||
- 默认日志存放目录: `ENV DEFAULT_LOG_DIR=/log`
|
||||
- 默认录播存放目录: `ENV DEFAULT_OUT_DIR=/rec`
|
||||
- 默认设置文件位置: `ENV BLREC_DEFAULT_SETTINGS_FILE=/cfg/settings.toml`
|
||||
- 默认日志存放目录: `ENV BLREC_DEFAULT_LOG_DIR=/log`
|
||||
- 默认录播存放目录: `ENV BLREC_DEFAULT_OUT_DIR=/rec`
|
||||
- 默认时区: `ENV TZ="Asia/Shanghai"`
|
||||
|
||||
### 默认参数运行
|
||||
@ -164,18 +164,18 @@ api key 可以使用数字和字母,长度限制为最短 8 最长 80。
|
||||
|
||||
作为 ASGI 应用运行,参数通过环境变量指定。
|
||||
|
||||
- `config` 指定设置文件
|
||||
- `out_dir` 指定录播存放位置
|
||||
- `log_dir` 指定日志存放位置
|
||||
- `api_key` 指定 `api key`
|
||||
- `BLREC_CONFIG` 指定设置文件
|
||||
- `BLREC_OUT_DIR` 指定录播存放位置
|
||||
- `BLREC_LOG_DIR` 指定日志存放位置
|
||||
- `BLREC_API_KEY` 指定 `api key`
|
||||
|
||||
### bash
|
||||
|
||||
config=path/to/settings.toml out_dir=path/to/dir api_key=******** uvicorn blrec.web:app --host 0.0.0.0 --port 8000
|
||||
BLREC_CONFIG=path/to/settings.toml BLREC_OUT_DIR=path/to/dir BLREC_API_KEY=******** uvicorn blrec.web:app --host 0.0.0.0 --port 8000
|
||||
|
||||
### cmd
|
||||
|
||||
set config=D:\\path\\to\\config.toml & set out_dir=D:\\path\\to\\dir & set api_key=******** uvicorn blrec.web:app --host 0.0.0.0 --port 8000
|
||||
set BLREC_CONFIG=D:\\path\\to\\config.toml & set BLREC_OUT_DIR=D:\\path\\to\\dir & set BLREC_API_KEY=******** uvicorn blrec.web:app --host 0.0.0.0 --port 8000
|
||||
|
||||
## Webhook
|
||||
|
||||
|
@ -18,7 +18,7 @@ __all__ = 'AppApi', 'WebApi'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TRACE_API_REQ = bool(os.environ.get('TRACE_API_REQ'))
|
||||
TRACE_API_REQ = bool(os.environ.get('BLREC_TRACE_API_REQ'))
|
||||
|
||||
|
||||
class BaseApi(ABC):
|
||||
|
@ -54,13 +54,13 @@ def cli_main(
|
||||
) -> None:
|
||||
"""Bilibili live streaming recorder"""
|
||||
if config is not None:
|
||||
os.environ['config'] = config
|
||||
os.environ['BLREC_CONFIG'] = config
|
||||
if api_key is not None:
|
||||
os.environ['api_key'] = api_key
|
||||
os.environ['BLREC_API_KEY'] = api_key
|
||||
if out_dir is not None:
|
||||
os.environ['out_dir'] = out_dir
|
||||
os.environ['BLREC_OUT_DIR'] = out_dir
|
||||
if log_dir is not None:
|
||||
os.environ['log_dir'] = log_dir
|
||||
os.environ['BLREC_LOG_DIR'] = log_dir
|
||||
|
||||
if root_path:
|
||||
if not root_path.startswith('/'):
|
||||
|
@ -36,7 +36,7 @@ class SpaceReclaimer(SpaceEventListener, SwitchableMixin):
|
||||
super().__init__()
|
||||
self._space_monitor = space_monitor
|
||||
self.path = path
|
||||
if value := os.environ.get('REC_TTL'):
|
||||
if value := os.environ.get('BLREC_REC_TTL'):
|
||||
try:
|
||||
rec_ttl = int(value)
|
||||
except Exception as exc:
|
||||
|
@ -22,7 +22,7 @@ __all__ = ('sort',)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TRACE_OP_SORT = bool(os.environ.get('TRACE_OP_SORT'))
|
||||
TRACE_OP_SORT = bool(os.environ.get('BLREC_TRACE_OP_SORT'))
|
||||
|
||||
|
||||
def sort() -> Callable[[FLVStream], FLVStream]:
|
||||
|
@ -18,8 +18,8 @@ __all__ = ('SegmentRemuxer',)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TRACE_REMUX_SEGMENT = bool(os.environ.get('TRACE_REMUX_SEGMENT'))
|
||||
TRACE_LIBAV = bool(os.environ.get('TRACE_LIBAV'))
|
||||
TRACE_REMUX_SEGMENT = bool(os.environ.get('BLREC_TRACE_REMUX_SEGMENT'))
|
||||
TRACE_LIBAV = bool(os.environ.get('BLREC_TRACE_LIBAV'))
|
||||
if TRACE_LIBAV:
|
||||
logging.getLogger('libav').setLevel(5)
|
||||
else:
|
||||
|
@ -55,7 +55,7 @@ __all__ = (
|
||||
'PushdeerSettings',
|
||||
'PushplusSettings',
|
||||
'TelegramSettings',
|
||||
'BarkSettings'
|
||||
'BarkSettings',
|
||||
'NotifierSettings',
|
||||
'NotificationSettings',
|
||||
'EmailMessageTemplateSettings',
|
||||
@ -74,19 +74,25 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_OUT_DIR: Final[str] = os.environ.get('DEFAULT_OUT_DIR', '.')
|
||||
DEFAULT_LOG_DIR: Final[str] = os.environ.get('DEFAULT_LOG_DIR', '~/.blrec/logs/')
|
||||
DEFAULT_OUT_DIR: Final[str] = os.environ.get('BLREC_DEFAULT_OUT_DIR', '.')
|
||||
DEFAULT_LOG_DIR: Final[str] = os.environ.get('BLREC_DEFAULT_LOG_DIR', '~/.blrec/logs/')
|
||||
DEFAULT_SETTINGS_FILE: Final[str] = os.environ.get(
|
||||
'DEFAULT_SETTINGS_FILE', '~/.blrec/settings.toml'
|
||||
'BLREC_DEFAULT_SETTINGS_FILE', '~/.blrec/settings.toml'
|
||||
)
|
||||
|
||||
|
||||
class EnvSettings(BaseSettings):
|
||||
settings_file: Annotated[str, Field(env='config')] = DEFAULT_SETTINGS_FILE
|
||||
out_dir: Optional[str] = None
|
||||
log_dir: Optional[str] = None
|
||||
settings_file: Annotated[str, Field(env='BLREC_CONFIG')] = DEFAULT_SETTINGS_FILE
|
||||
out_dir: Annotated[Optional[str], Field(env='BLREC_OUT_DIR')] = None
|
||||
log_dir: Annotated[Optional[str], Field(env='BLREC_LOG_DIR')] = None
|
||||
api_key: Annotated[
|
||||
Optional[str], Field(min_length=8, max_length=80, regex=r'[a-zA-Z\d\-]{8,80}'),
|
||||
Optional[str],
|
||||
Field(
|
||||
env='BLREC_API_KEY',
|
||||
min_length=8,
|
||||
max_length=80,
|
||||
regex=r'[a-zA-Z\d\-]{8,80}',
|
||||
),
|
||||
] = None
|
||||
|
||||
class Config:
|
||||
@ -420,10 +426,13 @@ class TelegramSettings(BaseModel):
|
||||
|
||||
@validator('server')
|
||||
def _validate_server(cls, value: str) -> str:
|
||||
if value != '' and not re.fullmatch(r'^https?:\/\/[a-zA-Z0-9-_.]+(:[0-9]+)?', value):
|
||||
if value != '' and not re.fullmatch(
|
||||
r'^https?:\/\/[a-zA-Z0-9-_.]+(:[0-9]+)?', value
|
||||
):
|
||||
raise ValueError('server is invalid')
|
||||
return value
|
||||
|
||||
|
||||
class BarkSettings(BaseModel):
|
||||
server: str = ''
|
||||
pushkey: str = ''
|
||||
@ -600,10 +609,7 @@ class TelegramNotificationSettings(
|
||||
|
||||
|
||||
class BarkNotificationSettings(
|
||||
BarkSettings,
|
||||
NotifierSettings,
|
||||
NotificationSettings,
|
||||
BarkMessageTemplateSettings,
|
||||
BarkSettings, NotifierSettings, NotificationSettings, BarkMessageTemplateSettings
|
||||
):
|
||||
pass
|
||||
|
||||
|
@ -146,7 +146,7 @@ class SupportDebugMixin(ABC):
|
||||
super().__init__()
|
||||
|
||||
def _init_for_debug(self, room_id: int) -> None:
|
||||
if (value := os.environ.get('DEBUG')) and (
|
||||
if (value := os.environ.get('BLREC_DEBUG')) and (
|
||||
value == '*' or room_id in value.split(',')
|
||||
):
|
||||
self._debug = True
|
||||
|
Loading…
Reference in New Issue
Block a user