Fix NPM integration: correct forward host, SSL, and add UDP stream
- Forward proxy to host IP + dashboard_port instead of container name - Remove redundant advanced_config (Caddy handles internal routing) - Add provider: letsencrypt to SSL certificate request - Add NPM UDP stream creation/deletion for STUN/TURN relay ports - Add npm_stream_id to Deployment model with migration - Fix API docs URL in README (/api/docs) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -220,20 +220,19 @@ async def deploy_customer(db: Session, customer_id: int) -> dict[str, Any]:
|
||||
_log_action(db, customer_id, "deploy", "info",
|
||||
"Auto-setup failed — admin must complete setup manually.")
|
||||
|
||||
# Step 9: Create NPM proxy host (production only)
|
||||
# Step 9: Create NPM proxy host + stream (production only)
|
||||
npm_proxy_id = None
|
||||
npm_stream_id = None
|
||||
if not local_mode:
|
||||
caddy_container = f"netbird-kunde{customer_id}-caddy"
|
||||
forward_host = npm_service._get_forward_host(config.npm_api_url)
|
||||
npm_result = await npm_service.create_proxy_host(
|
||||
api_url=config.npm_api_url,
|
||||
npm_email=config.npm_api_email,
|
||||
npm_password=config.npm_api_password,
|
||||
domain=netbird_domain,
|
||||
forward_host=caddy_container,
|
||||
forward_port=80,
|
||||
forward_host=forward_host,
|
||||
forward_port=dashboard_port,
|
||||
admin_email=config.admin_email,
|
||||
subdomain=customer.subdomain,
|
||||
customer_id=customer_id,
|
||||
)
|
||||
npm_proxy_id = npm_result.get("proxy_id")
|
||||
if npm_result.get("error"):
|
||||
@@ -241,8 +240,34 @@ async def deploy_customer(db: Session, customer_id: int) -> dict[str, Any]:
|
||||
db, customer_id, "deploy", "error",
|
||||
f"NPM proxy creation failed: {npm_result['error']}",
|
||||
)
|
||||
else:
|
||||
_log_action(
|
||||
db, customer_id, "deploy", "info",
|
||||
f"NPM proxy host created: {netbird_domain} -> {forward_host}:{dashboard_port}",
|
||||
)
|
||||
|
||||
# Step 9: Create deployment record
|
||||
# Create NPM UDP stream for relay STUN port
|
||||
stream_result = await npm_service.create_stream(
|
||||
api_url=config.npm_api_url,
|
||||
npm_email=config.npm_api_email,
|
||||
npm_password=config.npm_api_password,
|
||||
incoming_port=allocated_port,
|
||||
forwarding_host=forward_host,
|
||||
forwarding_port=allocated_port,
|
||||
)
|
||||
npm_stream_id = stream_result.get("stream_id")
|
||||
if stream_result.get("error"):
|
||||
_log_action(
|
||||
db, customer_id, "deploy", "error",
|
||||
f"NPM stream creation failed: {stream_result['error']}",
|
||||
)
|
||||
else:
|
||||
_log_action(
|
||||
db, customer_id, "deploy", "info",
|
||||
f"NPM UDP stream created: port {allocated_port} -> {forward_host}:{allocated_port}",
|
||||
)
|
||||
|
||||
# Step 10: Create deployment record
|
||||
setup_url = external_url
|
||||
|
||||
deployment = Deployment(
|
||||
@@ -251,6 +276,7 @@ async def deploy_customer(db: Session, customer_id: int) -> dict[str, Any]:
|
||||
relay_udp_port=allocated_port,
|
||||
dashboard_port=dashboard_port,
|
||||
npm_proxy_id=npm_proxy_id,
|
||||
npm_stream_id=npm_stream_id,
|
||||
relay_secret=encrypt_value(relay_secret),
|
||||
setup_url=setup_url,
|
||||
netbird_admin_email=encrypt_value(admin_email) if setup_ok else None,
|
||||
@@ -330,6 +356,17 @@ async def undeploy_customer(db: Session, customer_id: int) -> dict[str, Any]:
|
||||
except Exception as exc:
|
||||
_log_action(db, customer_id, "undeploy", "error", f"NPM removal error: {exc}")
|
||||
|
||||
# Remove NPM stream
|
||||
if deployment.npm_stream_id and config.npm_api_email:
|
||||
try:
|
||||
await npm_service.delete_stream(
|
||||
config.npm_api_url, config.npm_api_email, config.npm_api_password,
|
||||
deployment.npm_stream_id,
|
||||
)
|
||||
_log_action(db, customer_id, "undeploy", "info", "NPM stream removed.")
|
||||
except Exception as exc:
|
||||
_log_action(db, customer_id, "undeploy", "error", f"NPM stream removal error: {exc}")
|
||||
|
||||
# Remove instance directory
|
||||
if os.path.isdir(instance_dir):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user