Add config gen and better formatting

This commit is contained in:
Kohaku-Blueleaf
2025-10-20 12:04:49 +08:00
parent 151199b089
commit 69a271cfaf
4 changed files with 130 additions and 40 deletions

View File

@@ -45,6 +45,14 @@ def main():
print("\nKohakuHub Code Formatter")
print("=" * 60)
# Step 3: Format UI
run_command(["npm", "run", "format"], cwd=ui_dir, description="Formatting UI code")
# Step 4: Format Admin
run_command(
["npm", "run", "format"], cwd=admin_dir, description="Formatting Admin code"
)
# Step 1: Build UI (generates router/component definitions)
run_command(
["npm", "run", "build"],
@@ -59,14 +67,6 @@ def main():
description="Building Admin (generating router/component info)",
)
# Step 3: Format UI
run_command(["npm", "run", "format"], cwd=ui_dir, description="Formatting UI code")
# Step 4: Format Admin
run_command(
["npm", "run", "format"], cwd=admin_dir, description="Formatting Admin code"
)
# Step 5: Format Python
run_command(["black", "."], cwd=root_dir, description="Formatting Python code")

View File

@@ -732,22 +732,116 @@ def interactive_config() -> dict:
return config
def generate_config_toml(config: dict) -> str:
"""Generate config.toml for local dev server."""
# Adapt endpoints for localhost dev server
if config["postgres_builtin"]:
db_url = f"postgresql://{config['postgres_user']}:{config['postgres_password']}@localhost:25432/{config['postgres_db']}"
else:
db_url = f"postgresql://{config['postgres_user']}:{config['postgres_password']}@{config['postgres_host']}:{config['postgres_port']}/{config['postgres_db']}"
# S3 configuration for dev
if config["s3_builtin"]:
s3_endpoint_internal = "http://localhost:29001"
s3_endpoint_public = "http://localhost:29001"
s3_region = "us-east-1"
else:
s3_endpoint_internal = config["s3_endpoint"]
s3_endpoint_public = config["s3_endpoint"]
s3_region = config.get("s3_region", "us-east-1")
toml_content = f"""# KohakuHub Configuration File (TOML)
# Generated by KohakuHub docker-compose generator
# Use this for local development server
[app]
base_url = "http://localhost:48888" # Dev server URL
api_base = "/api"
site_name = "KohakuHub"
workers = 1 # Single worker for dev
[database]
backend = "postgres"
url = "{db_url}"
auto_migrate = true # Auto-confirm migrations
[s3]
endpoint = "{s3_endpoint_internal}"
public_endpoint = "{s3_endpoint_public}"
access_key = "{config['s3_access_key']}"
secret_key = "{config['s3_secret_key']}"
bucket = "hub-storage"
region = "{s3_region}"
"""
# Add signature_version only if set (for external S3)
if config.get("s3_signature_version"):
toml_content += f'signature_version = "{config["s3_signature_version"]}"\n'
toml_content += f"""
[lakefs]
endpoint = "http://localhost:28000"
repo_namespace = "hf"
# Credentials auto-generated on first start
[lfs]
threshold_bytes = 1_000_000 # 1MB
keep_versions = 5
auto_gc = true
[auth]
session_secret = "{config['session_secret']}"
session_expire_hours = 168 # 7 days
token_expire_days = 365
require_email_verification = false
invitation_only = false
[admin]
enabled = true
secret_token = "{config['admin_secret']}"
[smtp]
enabled = false
host = "smtp.gmail.com"
port = 587
username = ""
password = ""
from = "noreply@kohakuhub.local"
tls = true
[quota]
default_user_private_bytes = 10_000_000 # 10MB
default_user_public_bytes = 100_000_000 # 100MB
default_org_private_bytes = 10_000_000 # 10MB
default_org_public_bytes = 100_000_000 # 100MB
"""
return toml_content
def generate_and_write_files(config: dict):
"""Generate and write docker-compose.yml and related files."""
print()
print("=" * 60)
print("Generating docker-compose.yml...")
print("Generating docker-compose.yml and config.toml...")
print("=" * 60)
# Generate docker-compose content
content = generate_docker_compose(config)
compose_content = generate_docker_compose(config)
# Write to file
output_path = Path(__file__).parent.parent / "docker-compose.yml"
output_path.write_text(content, encoding="utf-8")
# Write docker-compose.yml
compose_path = Path(__file__).parent.parent / "docker-compose.yml"
compose_path.write_text(compose_content, encoding="utf-8")
print()
print(f"[OK] Successfully generated: {output_path}")
print(f"[OK] Successfully generated: {compose_path}")
# Generate and write config.toml
config_content = generate_config_toml(config)
config_path = Path(__file__).parent.parent / "config.toml"
config_path.write_text(config_content, encoding="utf-8")
print(f"[OK] Successfully generated: {config_path}")
if config["lakefs_use_postgres"]:
print(
@@ -789,8 +883,13 @@ def generate_and_write_files(config: dict):
step_num += 1
print()
print(f"{step_num}. Review the generated docker-compose.yml")
print(f"{step_num}. Review the generated files:")
print(" - docker-compose.yml (for Docker deployment)")
print(" - config.toml (for local dev server)")
step_num += 1
print()
print("For Docker deployment:")
print(f"{step_num}. Build frontend: npm run build --prefix ./src/kohaku-hub-ui")
step_num += 1
print(f"{step_num}. Start services: docker-compose up -d")
@@ -804,6 +903,18 @@ def generate_and_write_files(config: dict):
print(f"{step_num}. Access at: http://localhost:28080")
print()
print("For local dev server:")
print(
f"{step_num}. Start infrastructure: docker-compose up -d postgres minio lakefs"
)
step_num += 1
print(
f"{step_num}. Run dev server: uvicorn kohakuhub.main:app --reload --port 48888"
)
step_num += 1
print(f"{step_num}. Access at: http://localhost:48888")
print()
if __name__ == "__main__":
try:

View File

@@ -692,7 +692,6 @@
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/lodash": "*"
}
@@ -1218,7 +1217,6 @@
"resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.5.22.tgz",
"integrity": "sha512-tbTR1zKGce4Lj+JLzFXDq36K4vcSZbJ1RBu8FxcDv1IGRz//Dh2EBqksyGVypz3kXpshIfWKGOCcqpSbyGWRJQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/parser": "^7.28.4",
"@vue/compiler-core": "3.5.22",
@@ -1613,7 +1611,6 @@
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.1.tgz",
"integrity": "sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==",
"license": "MIT",
"peer": true,
"dependencies": {
"@kurkle/color": "^0.3.0"
},
@@ -2510,15 +2507,13 @@
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-unified": {
"version": "1.0.3",
@@ -3040,7 +3035,6 @@
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -3439,7 +3433,6 @@
"integrity": "sha512-eSiiRJmovt8qDJkGyZuLnbxAOAdie6NCmmd0NkTC0RJI9duiSBTfr8X2mBYJOUFzxQa2USaHmL99J9uMxkjCyw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@oxc-project/runtime": "0.92.0",
"fdir": "^6.5.0",
@@ -3534,7 +3527,6 @@
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -3547,7 +3539,6 @@
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.22.tgz",
"integrity": "sha512-toaZjQ3a/G/mYaLSbV+QsQhIdMo9x5rrqIpYRObsJ6T/J+RyCSFwN2LHNVH9v8uIcljDNa3QzPVdv3Y6b9hAJQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@vue/compiler-dom": "3.5.22",
"@vue/compiler-sfc": "3.5.22",

View File

@@ -732,7 +732,6 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
},
@@ -777,7 +776,6 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
}
@@ -1713,7 +1711,6 @@
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/lodash": "*"
}
@@ -2246,7 +2243,6 @@
"resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.5.22.tgz",
"integrity": "sha512-tbTR1zKGce4Lj+JLzFXDq36K4vcSZbJ1RBu8FxcDv1IGRz//Dh2EBqksyGVypz3kXpshIfWKGOCcqpSbyGWRJQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/parser": "^7.28.4",
"@vue/compiler-core": "3.5.22",
@@ -2679,7 +2675,6 @@
"resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-11.0.3.tgz",
"integrity": "sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==",
"license": "Apache-2.0",
"peer": true,
"dependencies": {
"@chevrotain/cst-dts-gen": "11.0.3",
"@chevrotain/gast": "11.0.3",
@@ -2863,7 +2858,6 @@
"resolved": "https://registry.npmjs.org/cytoscape/-/cytoscape-3.33.1.tgz",
"integrity": "sha512-iJc4TwyANnOGR1OmWhsS9ayRS3s+XQ185FmuHObThD+5AeJCakAAbWv8KimMTt08xCCLNgneQwFp+JRJOr9qGQ==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=0.10"
}
@@ -3264,7 +3258,6 @@
"resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz",
"integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==",
"license": "ISC",
"peer": true,
"engines": {
"node": ">=12"
}
@@ -4407,15 +4400,13 @@
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-unified": {
"version": "1.0.3",
@@ -4836,7 +4827,6 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@@ -5540,7 +5530,6 @@
"integrity": "sha512-eSiiRJmovt8qDJkGyZuLnbxAOAdie6NCmmd0NkTC0RJI9duiSBTfr8X2mBYJOUFzxQa2USaHmL99J9uMxkjCyw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@oxc-project/runtime": "0.92.0",
"fdir": "^6.5.0",
@@ -5665,7 +5654,6 @@
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.22.tgz",
"integrity": "sha512-toaZjQ3a/G/mYaLSbV+QsQhIdMo9x5rrqIpYRObsJ6T/J+RyCSFwN2LHNVH9v8uIcljDNa3QzPVdv3Y6b9hAJQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@vue/compiler-dom": "3.5.22",
"@vue/compiler-sfc": "3.5.22",