feat(lps): docker-compose 에 lps-admin 추가 + 환경설정 config.local.toml 단일화
- lps-admin 컨테이너화: Vite 정적 빌드 → nginx, /v1·/healthz·/readyz 를 lps-api:9600 으로 동일출처 프록시(빌드 타임 API URL 주입 불필요) - lps-api/worker: APP_ENV=local 고정 + DB_HOST override(도메인 backend·negodata·agent 와 동일 패턴), config.<env>.toml 마운트 방식 폐기 - server_configs 에 DB 접속 env override(_apply_db_env_override) 복원 - config.dev/prod.toml.example 제거 — 환경 구분 없이 config.local.toml 하나 (prod 서버도 그 서버의 config.local.toml + docker compose up -d) - run_docker.sh 환경 선택 제거·lps-admin 포함, README·operations 문서 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d111610555
commit
dc8c288f68
10 files changed
+188
-230
No files matched your search
@@ -1,80 +0,0 @@
|
||||
# dev(개발 서버, Docker) 설정 — 복사해서 사용: cp config.dev.toml.example config.dev.toml
|
||||
# 실제 config.dev.toml 은 시크릿 포함이라 커밋하지 않는다(.gitignore: *.toml).
|
||||
#
|
||||
# 실행: ./lps/run_docker.sh 에서 dev 선택(권장) 또는 APP_ENV=dev docker compose up -d lps-api lps-worker
|
||||
# compose 가 이 파일을 컨테이너에 마운트하고 APP_ENV 로 선택한다. 이미지에는 시크릿이 없다 —
|
||||
# 마운트를 잊으면 기동 시 FileNotFoundError 로 즉시 실패(조용한 오동작 없음).
|
||||
# local 과의 차이만 주석으로 표시 — 나머지 의미는 config.local.toml.example 참고.
|
||||
|
||||
[WebServerConfig]
|
||||
server_name = "LpsServer"
|
||||
port = 9600
|
||||
process_count = 1 # API 병목은 드묾(단일로 ~1,100 RPS 실측). 부하 대비 시에만 코어 수만큼
|
||||
is_ssl = false
|
||||
is_test = false
|
||||
cors_origins = []
|
||||
api_keys = [] # dev 는 개방 모드(협의: guard 는 prod 전용)
|
||||
|
||||
[LogConfig]
|
||||
print_console = true
|
||||
log_level = "info"
|
||||
|
||||
[MainDBConfig]
|
||||
db_type = "postgresql"
|
||||
name = "lps_db"
|
||||
write_host = "host.docker.internal" # 컨테이너 → 호스트 DB (전용 DB 서버면 그 호스트로)
|
||||
write_port = 5432
|
||||
write_id = "<DB_USER>"
|
||||
write_pw = "<DB_PASSWORD>"
|
||||
read_host = "host.docker.internal"
|
||||
read_port = 5432
|
||||
read_id = "<DB_USER>"
|
||||
read_pw = "<DB_PASSWORD>"
|
||||
show_log = false
|
||||
pool_size = 10
|
||||
max_overflow = 20
|
||||
connection_budget = 40 # 전용 PG(max_connections≈100)면 90 근처로 상향
|
||||
sslmode = ""
|
||||
|
||||
[WorkerConfig]
|
||||
concurrency = 1
|
||||
fallbacks = []
|
||||
profile_dir = "/profiles" # compose 의 영속 볼륨(lps-profiles) — 재시작에도 cf_clearance 유지
|
||||
job_deadline_sec = 300
|
||||
shutdown_grace_sec = 60
|
||||
chrome_channel = "chrome"
|
||||
chrome_executable = "/usr/bin/chromium" # 컨테이너는 시스템 chromium + Xvfb(headful)
|
||||
heartbeat_file = "/tmp/lps_worker_heartbeat"
|
||||
|
||||
[AlertConfig]
|
||||
webhook = "" # Slack 호환 웹훅 — 채우면 임계 알림 전송(docs/operations.md)
|
||||
cooldown_min = 30
|
||||
dead_1h = 20
|
||||
blocks_1h = 80
|
||||
queue_lag_sec = 300
|
||||
pool_pct = 90
|
||||
source_fail_30m = 5
|
||||
deadline_1h = 5
|
||||
cost_1h_usd = 1.0
|
||||
ports_low_pct = 30
|
||||
block_sessions_6h = 1
|
||||
|
||||
[NaverConfig]
|
||||
[[NaverConfig.keys]]
|
||||
id = "<NAVER_CLIENT_ID>"
|
||||
secret = "<NAVER_CLIENT_SECRET>"
|
||||
|
||||
[OpenAIConfig]
|
||||
api_key = "<OPENAI_API_KEY>" # 비면 AI 판정 OFF
|
||||
model = "gpt-4o-mini"
|
||||
|
||||
[DecodoConfig]
|
||||
host = "" # 4종(호스트·계정·포트범위) 비면 프록시 미사용(직접 연결)
|
||||
username = ""
|
||||
password = ""
|
||||
port_start = 0
|
||||
port_end = 0
|
||||
session_minutes = 10
|
||||
cost_per_gb = 0.0
|
||||
ip_request_budget = 3
|
||||
port_cooldown_sec = 0
|
||||
@@ -1,82 +0,0 @@
|
||||
# prod(운영 서버, Docker) 설정 — 복사해서 사용: cp config.prod.toml.example config.prod.toml
|
||||
# 실제 config.prod.toml 은 시크릿 포함이라 커밋하지 않는다(.gitignore: *.toml).
|
||||
#
|
||||
# 실행: ./lps/run_docker.sh 에서 prod 선택(권장) — guard 키 미설정 경고 + API 포트 127.0.0.1 바인드까지 처리
|
||||
# (수동: APP_ENV=prod LPS_API_BIND=127.0.0.1 docker compose up -d lps-api lps-worker)
|
||||
# prod 필수 체크: ① api_keys 채움 ② negodata 쪽 lps_api_key 에 같은 키 ③ 알림 webhook 권장
|
||||
# compose 가 이 파일을 컨테이너에 마운트하고 APP_ENV 로 선택한다. 이미지에는 시크릿이 없다 —
|
||||
# 마운트를 잊으면 기동 시 FileNotFoundError 로 즉시 실패(조용한 오동작 없음).
|
||||
# local 과의 차이만 주석으로 표시 — 나머지 의미는 config.local.toml.example 참고.
|
||||
|
||||
[WebServerConfig]
|
||||
server_name = "LpsServer"
|
||||
port = 9600
|
||||
process_count = 1 # API 병목은 드묾(단일로 ~1,100 RPS 실측). 부하 대비 시에만 코어 수만큼
|
||||
is_ssl = false
|
||||
is_test = false
|
||||
cors_origins = []
|
||||
api_keys = ["<openssl rand -hex 32 로 생성>"] # prod 필수 — 비우면 개방 모드(위험). 복수 등록=무중단 교체
|
||||
|
||||
[LogConfig]
|
||||
print_console = true
|
||||
log_level = "info" # prod 는 debug 금지(로그량·민감정보)
|
||||
|
||||
[MainDBConfig]
|
||||
db_type = "postgresql"
|
||||
name = "lps_db"
|
||||
write_host = "host.docker.internal" # 컨테이너 → 호스트 DB (전용 DB 서버면 그 호스트로)
|
||||
write_port = 5432
|
||||
write_id = "<DB_USER>"
|
||||
write_pw = "<DB_PASSWORD>"
|
||||
read_host = "host.docker.internal"
|
||||
read_port = 5432
|
||||
read_id = "<DB_USER>"
|
||||
read_pw = "<DB_PASSWORD>"
|
||||
show_log = false
|
||||
pool_size = 10
|
||||
max_overflow = 20
|
||||
connection_budget = 40 # 전용 PG(max_connections≈100)면 90 근처로 상향. 관리형 DB 면 sslmode 도 확인
|
||||
sslmode = ""
|
||||
|
||||
[WorkerConfig]
|
||||
concurrency = 1
|
||||
fallbacks = []
|
||||
profile_dir = "/profiles" # compose 의 영속 볼륨(lps-profiles) — 재시작에도 cf_clearance 유지
|
||||
job_deadline_sec = 300
|
||||
shutdown_grace_sec = 60
|
||||
chrome_channel = "chrome"
|
||||
chrome_executable = "/usr/bin/chromium" # 컨테이너는 시스템 chromium + Xvfb(headful)
|
||||
heartbeat_file = "/tmp/lps_worker_heartbeat"
|
||||
|
||||
[AlertConfig]
|
||||
webhook = "" # prod 는 채우기를 권장 — 없으면 임계 알림이 로그로만 남는다(docs/operations.md)
|
||||
cooldown_min = 30
|
||||
dead_1h = 20
|
||||
blocks_1h = 80
|
||||
queue_lag_sec = 300
|
||||
pool_pct = 90
|
||||
source_fail_30m = 5
|
||||
deadline_1h = 5
|
||||
cost_1h_usd = 1.0
|
||||
ports_low_pct = 30
|
||||
block_sessions_6h = 1
|
||||
|
||||
[NaverConfig]
|
||||
[[NaverConfig.keys]]
|
||||
id = "<NAVER_CLIENT_ID>"
|
||||
secret = "<NAVER_CLIENT_SECRET>"
|
||||
|
||||
[OpenAIConfig]
|
||||
api_key = "<OPENAI_API_KEY>" # 비면 AI 판정 OFF
|
||||
model = "gpt-4o-mini"
|
||||
|
||||
[DecodoConfig]
|
||||
host = "" # 4종(호스트·계정·포트범위) 비면 프록시 미사용(직접 연결)
|
||||
username = ""
|
||||
password = ""
|
||||
port_start = 0
|
||||
port_end = 0
|
||||
session_minutes = 10
|
||||
cost_per_gb = 0.0
|
||||
ip_request_budget = 3
|
||||
port_cooldown_sec = 0
|
||||
@@ -6,13 +6,16 @@ from config.config_models import (
|
||||
WorkerConfig, AlertConfig,
|
||||
)
|
||||
|
||||
# ── 설정 소스는 TOML 하나다(2026-07-13 협의 — env/.env 이중 관리 제거). ──
|
||||
# env 는 부트스트랩·실행 입력만 남는다:
|
||||
# APP_ENV : 어떤 toml 을 읽을지 — local(호스트 실행) / dev·prod(컨테이너에 마운트된 config.<env>.toml)
|
||||
# ── 설정 소스는 config.local.toml 하나다(도메인 backend 와 동일 — 서버마다 그 서버의 값, 미커밋). ──
|
||||
# 운영 전제: 항상 APP_ENV=local 로 띄운다 → config.local.toml (호스트 실행·pytest·docker 모두 동일).
|
||||
# prod 서버도 그 서버의 config.local.toml 에 prod 값(시크릿·guard키·스케일)을 채우고 `docker compose up -d`.
|
||||
# env 는 실행 입력과 '환경별로 바뀌는 접속점'만 담당한다:
|
||||
# DB_HOST/PORT/… : DB 접속 override — config.local.toml 은 127.0.0.1(호스트 실행·pytest) 유지하고,
|
||||
# 컨테이너에선 compose 가 DB_HOST=host.docker.internal 로 호스트 DB 를 가리킨다(_apply_db_env_override).
|
||||
# PROCESS_COUNT : 실행 스크립트·부하벤치의 대화형 입력(uvicorn 워커 수 임시 override)
|
||||
# WORKER_CONCURRENCY : 워커 실행 스크립트의 대화형 입력(worker_main 이 읽음)
|
||||
# LPS_LIVE : 라이브 스모크 테스트 옵트인(설정이 아니라 실행 스위치)
|
||||
# 시크릿 포함 실값은 환경별 config.<APP_ENV>.toml(미커밋)에 두고, Docker 는 파일을 마운트한다.
|
||||
# 시크릿(네이버·OpenAI·DECODO)은 env 로 넣지 않는다 — config.local.toml 에 두고 컨테이너엔 마운트한다.
|
||||
APP_ENV = os.environ.get("APP_ENV", "local")
|
||||
|
||||
_config_dir = os.path.dirname(__file__)
|
||||
@@ -21,7 +24,7 @@ _config_file = os.path.join(_config_dir, f"config.{APP_ENV}.toml")
|
||||
if not os.path.exists(_config_file):
|
||||
raise FileNotFoundError(
|
||||
f"설정 파일이 없습니다: {_config_file} (APP_ENV={APP_ENV}). "
|
||||
"호스트 실행은 config.local.toml 준비, 컨테이너(dev/prod)는 config.<APP_ENV>.toml 마운트를 확인하세요."
|
||||
"config.local.toml 을 준비하세요(config.local.toml.example 복사). 컨테이너는 compose 가 이 파일을 마운트합니다."
|
||||
)
|
||||
|
||||
configs = Configs(_config_file)
|
||||
@@ -37,6 +40,26 @@ worker_config: WorkerConfig = configs.get(WorkerConfig) or WorkerConfig()
|
||||
alert_config: AlertConfig = configs.get(AlertConfig) or AlertConfig()
|
||||
|
||||
|
||||
# DB 접속 env override — config.local.toml 의 접속 정보를 '환경별로 바뀌는 값만' 덮는다.
|
||||
# 로컬(호스트 uvicorn·pytest)은 env 미설정 → toml(127.0.0.1) 그대로. 컨테이너는 compose 가
|
||||
# DB_HOST=host.docker.internal 을 넣어 호스트 DB 를 가리킨다(도메인 backend 와 동일한 패턴).
|
||||
# 값이 빈 문자열이면 override 하지 않는다 → 관리형 DB 는 LPS_DB_HOST= 로 비워 config.local.toml 의 호스트를 쓴다.
|
||||
def _apply_db_env_override(cfg: MainDBConfig):
|
||||
if os.environ.get("DB_HOST"):
|
||||
cfg.write_host = cfg.read_host = os.environ["DB_HOST"]
|
||||
if os.environ.get("DB_PORT"):
|
||||
cfg.write_port = cfg.read_port = int(os.environ["DB_PORT"])
|
||||
if os.environ.get("DB_USER"):
|
||||
cfg.write_id = cfg.read_id = os.environ["DB_USER"]
|
||||
if os.environ.get("DB_PASSWORD"):
|
||||
cfg.write_pw = cfg.read_pw = os.environ["DB_PASSWORD"]
|
||||
if os.environ.get("DB_NAME"):
|
||||
cfg.name = os.environ["DB_NAME"]
|
||||
# 커넥션 예산도 env 로 조정 가능(자동 산정 입력) — 전용/공유 PG 에 맞춰 서버별로.
|
||||
if os.environ.get("DB_CONNECTION_BUDGET"):
|
||||
cfg.connection_budget = int(os.environ["DB_CONNECTION_BUDGET"])
|
||||
|
||||
|
||||
def _autosize_pool(cfg: MainDBConfig, process_count: int):
|
||||
"""process_count 기반 커넥션 풀 자동 산정.
|
||||
|
||||
@@ -59,6 +82,9 @@ def _autosize_pool(cfg: MainDBConfig, process_count: int):
|
||||
return cfg.pool_size, cfg.max_overflow
|
||||
|
||||
|
||||
# DB 접속점 override(호스트↔컨테이너) — 자동 산정(예산) 전에 적용해야 budget override 가 반영된다.
|
||||
_apply_db_env_override(main_db_config)
|
||||
|
||||
# uvicorn 워커 수 — 실행 스크립트/부하벤치의 대화형 입력만 env 로 임시 override(설정은 toml 이 소스).
|
||||
if os.environ.get("PROCESS_COUNT"):
|
||||
web_server_config.process_count = int(os.environ["PROCESS_COUNT"])
|
||||
|
||||
Reference in new issue
Block a user