Settings + fix startup
This commit is contained in:
+43
-8
@@ -87,6 +87,39 @@ def extract_python_version(version_string: str) -> tuple[str, str]:
|
||||
raise ValueError(f"Invalid Python version: {version_string}")
|
||||
|
||||
|
||||
def build_uris(env_alfred: Path, env_secrets: Path) -> None:
|
||||
"""Build MONGO_URI and POSTGRES_URI from components and append them to .env.secrets."""
|
||||
env = {**load_env_file(env_alfred), **load_env_file(env_secrets)}
|
||||
existing = load_env_file(env_secrets)
|
||||
|
||||
computed = {
|
||||
"MONGO_URI": (
|
||||
f"mongodb://{env['MONGO_USER']}:{env['MONGO_PASSWORD']}"
|
||||
f"@{env['MONGO_HOST']}:{env['MONGO_PORT']}/{env['MONGO_DB_NAME']}"
|
||||
f"?authSource=admin"
|
||||
),
|
||||
"POSTGRES_URI": (
|
||||
f"postgresql://{env['POSTGRES_USER']}:{env['POSTGRES_PASSWORD']}"
|
||||
f"@{env['POSTGRES_HOST']}:{env['POSTGRES_PORT']}/{env['POSTGRES_DB_NAME']}"
|
||||
),
|
||||
}
|
||||
|
||||
content = env_secrets.read_text()
|
||||
added = []
|
||||
for key, value in computed.items():
|
||||
if key in existing:
|
||||
content = re.sub(rf"^{key}=.*$", f"{key}={value}", content, flags=re.MULTILINE)
|
||||
else:
|
||||
content = content.rstrip("\n") + f"\n{key}={value}\n"
|
||||
added.append(key)
|
||||
env_secrets.write_text(content)
|
||||
|
||||
if added:
|
||||
print(f" + Computed: {', '.join(added)}")
|
||||
else:
|
||||
print(" ↻ URIs updated")
|
||||
|
||||
|
||||
def write_env_make(toml_data: dict) -> None:
|
||||
"""Write .env.make from pyproject.toml."""
|
||||
project = toml_data["project"]
|
||||
@@ -96,14 +129,13 @@ def write_env_make(toml_data: dict) -> None:
|
||||
|
||||
lines = [
|
||||
"# Auto-generated from pyproject.toml — do not edit manually",
|
||||
f"export ALFRED_VERSION={project['version']}",
|
||||
f"export PYTHON_VERSION={python_full}",
|
||||
f"export PYTHON_VERSION_SHORT={python_short}",
|
||||
f"export IMAGE_NAME={alfred['image_name']}",
|
||||
f"export SERVICE_NAME={alfred['service_name']}",
|
||||
f"export LIBRECHAT_VERSION={alfred['librechat_version']}",
|
||||
f"export RAG_VERSION={alfred['rag_version']}",
|
||||
f"export UV_VERSION={alfred['uv_version']}",
|
||||
f"ALFRED_VERSION={project['version']}",
|
||||
f"PYTHON_VERSION={python_full}",
|
||||
f"IMAGE_NAME={alfred['image_name']}",
|
||||
f"SERVICE_NAME={alfred['service_name']}",
|
||||
f"LIBRECHAT_VERSION={alfred['librechat_version']}",
|
||||
f"RAG_VERSION={alfred['rag_version']}",
|
||||
f"UV_VERSION={alfred['uv_version']}",
|
||||
]
|
||||
|
||||
env_make_path = BASE_DIR / ".env.make"
|
||||
@@ -138,6 +170,9 @@ def main() -> int:
|
||||
print("\n🔐 Secrets:")
|
||||
generate_secrets_file(BASE_DIR / ".env.secrets", secrets_spec)
|
||||
|
||||
print("\n🔗 URIs:")
|
||||
build_uris(BASE_DIR / ".env.alfred", BASE_DIR / ".env.secrets")
|
||||
|
||||
print("\n🔧 Build config:")
|
||||
write_env_make(toml_data)
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ def write_env_make(config: BuildConfig, base_dir: Path | None = None) -> None:
|
||||
"# Auto-generated from pyproject.toml — do not edit manually",
|
||||
f"export ALFRED_VERSION={config.alfred_version}",
|
||||
f"export PYTHON_VERSION={config.python_version}",
|
||||
f"export PYTHON_VERSION_SHORT={config.python_version_short}",
|
||||
f"export IMAGE_NAME={config.image_name}",
|
||||
f"export SERVICE_NAME={config.service_name}",
|
||||
f"export LIBRECHAT_VERSION={config.librechat_version}",
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate .env.make for CI/CD without generating secrets."""
|
||||
|
||||
import sys
|
||||
|
||||
from config_loader import load_build_config, write_env_make
|
||||
|
||||
|
||||
def main():
|
||||
"""Generate .env.make from pyproject.toml."""
|
||||
try:
|
||||
config = load_build_config()
|
||||
write_env_make(config)
|
||||
print("✅ .env.make generated successfully.")
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to generate .env.make: {e}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user