Update README.md
This commit is contained in:
152
deploy_nomad_mcp.py
Normal file
152
deploy_nomad_mcp.py
Normal file
@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Script to deploy the Nomad MCP service using our own Nomad client.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
from app.services.nomad_client import NomadService
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
def read_job_spec(file_path):
|
||||
"""Read the Nomad job specification from a file."""
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Convert HCL to JSON (simplified approach)
|
||||
# In a real scenario, you might want to use a proper HCL parser
|
||||
# This is a very basic approach that assumes the job spec is valid
|
||||
job_id = "nomad-mcp"
|
||||
|
||||
# Create a basic job structure
|
||||
job_spec = {
|
||||
"ID": job_id,
|
||||
"Name": job_id,
|
||||
"Type": "service",
|
||||
"Datacenters": ["jm"],
|
||||
"Namespace": "development",
|
||||
"TaskGroups": [
|
||||
{
|
||||
"Name": "app",
|
||||
"Count": 1,
|
||||
"Networks": [
|
||||
{
|
||||
"DynamicPorts": [
|
||||
{
|
||||
"Label": "http",
|
||||
"To": 8000
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Tasks": [
|
||||
{
|
||||
"Name": "nomad-mcp",
|
||||
"Driver": "docker",
|
||||
"Config": {
|
||||
"image": "registry.dev.meisheng.group/nomad_mcp:20250226",
|
||||
"ports": ["http"],
|
||||
"command": "python",
|
||||
"args": ["-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
},
|
||||
"Env": {
|
||||
"NOMAD_ADDR": "http://pjmldk01.ds.meisheng.group:4646",
|
||||
"NOMAD_NAMESPACE": "development",
|
||||
"NOMAD_SKIP_VERIFY": "true",
|
||||
"PORT": "8000",
|
||||
"HOST": "0.0.0.0",
|
||||
"LOG_LEVEL": "INFO",
|
||||
"RELOAD": "true"
|
||||
},
|
||||
"Resources": {
|
||||
"CPU": 200,
|
||||
"MemoryMB": 256
|
||||
},
|
||||
"Services": [
|
||||
{
|
||||
"Name": "nomad-mcp",
|
||||
"PortLabel": "http",
|
||||
"Tags": [
|
||||
"traefik.enable=true",
|
||||
"traefik.http.routers.nomad-mcp.entryPoints=https",
|
||||
"traefik.http.routers.nomad-mcp.rule=Host(`nomad_mcp.dev.meisheng.group`)",
|
||||
"traefik.http.routers.nomad-mcp.middlewares=proxyheaders@consulcatalog"
|
||||
],
|
||||
"Checks": [
|
||||
{
|
||||
"Type": "http",
|
||||
"Path": "/api/health",
|
||||
"Interval": 10000000000,
|
||||
"Timeout": 2000000000,
|
||||
"CheckRestart": {
|
||||
"Limit": 3,
|
||||
"Grace": 60000000000
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Update": {
|
||||
"MaxParallel": 1,
|
||||
"MinHealthyTime": 30000000000,
|
||||
"HealthyDeadline": 300000000000,
|
||||
"AutoRevert": True
|
||||
}
|
||||
}
|
||||
|
||||
return job_spec
|
||||
except Exception as e:
|
||||
print(f"Error reading job specification: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
print("Deploying Nomad MCP service using our own Nomad client...")
|
||||
|
||||
# Check if NOMAD_ADDR is configured
|
||||
nomad_addr = os.getenv("NOMAD_ADDR")
|
||||
if not nomad_addr:
|
||||
print("Error: NOMAD_ADDR is not configured in .env file.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Connecting to Nomad at: {nomad_addr}")
|
||||
|
||||
try:
|
||||
# Initialize the Nomad service
|
||||
nomad_service = NomadService()
|
||||
|
||||
# Read the job specification
|
||||
job_spec = read_job_spec("nomad_mcp_job.nomad")
|
||||
print("Job specification loaded successfully.")
|
||||
|
||||
# Start the job
|
||||
print("Registering and starting the nomad-mcp job...")
|
||||
response = nomad_service.start_job(job_spec)
|
||||
|
||||
print("\nJob registration response:")
|
||||
print(json.dumps(response, indent=2))
|
||||
|
||||
if response.get("status") == "started":
|
||||
print("\n✅ Nomad MCP service deployed successfully!")
|
||||
print(f"Job ID: {response.get('job_id')}")
|
||||
print(f"Evaluation ID: {response.get('eval_id')}")
|
||||
print("\nThe service will be available at: https://nomad_mcp.dev.meisheng.group")
|
||||
else:
|
||||
print("\n❌ Failed to deploy Nomad MCP service.")
|
||||
print(f"Status: {response.get('status')}")
|
||||
print(f"Message: {response.get('message', 'Unknown error')}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error deploying Nomad MCP service: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user