103 lines
4.0 KiB
Python
103 lines
4.0 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Script to deploy the Nomad MCP service using the Claude API.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import json
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
def main():
|
|
print("Deploying Nomad MCP service using the Claude API...")
|
|
|
|
# Define the API endpoint
|
|
api_url = "http://localhost:8000/api/claude/create-job"
|
|
|
|
# Create the job specification for the Claude API
|
|
job_spec = {
|
|
"job_id": "nomad-mcp",
|
|
"name": "Nomad MCP Service",
|
|
"type": "service",
|
|
"datacenters": ["jm"],
|
|
"namespace": "development",
|
|
"docker_image": "registry.dev.meisheng.group/nomad_mcp:20250226",
|
|
"count": 1,
|
|
"cpu": 200,
|
|
"memory": 256,
|
|
"ports": [
|
|
{
|
|
"Label": "http",
|
|
"Value": 0,
|
|
"To": 8000
|
|
}
|
|
],
|
|
"env_vars": {
|
|
"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",
|
|
"PYTHONPATH": "/app"
|
|
},
|
|
# Note: The Claude API doesn't directly support command and args,
|
|
# so we'll need to add a note about this limitation
|
|
}
|
|
|
|
try:
|
|
# Make the API request
|
|
print("Sending request to Claude API...")
|
|
response = requests.post(
|
|
api_url,
|
|
json=job_spec,
|
|
headers={"Content-Type": "application/json"}
|
|
)
|
|
|
|
# Check if the request was successful
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("\nJob registration response:")
|
|
print(json.dumps(result, indent=2))
|
|
|
|
if result.get("success"):
|
|
print("\n✅ Nomad MCP service deployed successfully!")
|
|
print(f"Job ID: {result.get('job_id')}")
|
|
print(f"Status: {result.get('status')}")
|
|
print("\nThe service will be available at: https://nomad_mcp.dev.meisheng.group")
|
|
|
|
# Add Traefik configuration and command information
|
|
print("\nImportant Notes:")
|
|
print("1. The Claude API doesn't directly support adding Traefik tags.")
|
|
print(" You may need to update the job manually to add the following tags:")
|
|
print(" - traefik.enable=true")
|
|
print(" - traefik.http.routers.nomad-mcp.entryPoints=https")
|
|
print(" - traefik.http.routers.nomad-mcp.rule=Host(`nomad_mcp.dev.meisheng.group`)")
|
|
print(" - traefik.http.routers.nomad-mcp.middlewares=proxyheaders@consulcatalog")
|
|
print("\n2. The Claude API doesn't directly support specifying command and args.")
|
|
print(" You need to update the job manually to add the following:")
|
|
print(" - command: python")
|
|
print(" - args: [\"-m\", \"uvicorn\", \"app.main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8000\"]")
|
|
print("\n3. The Claude API doesn't support Gitea artifact configuration.")
|
|
print(" You need to update the job manually to add the following:")
|
|
print(" - artifact source: git::ssh://git@gitea.service.mesh:2222/Mei_Sheng_Textiles/nomad_mcp.git")
|
|
print(" - artifact destination: local/nomad_mcp")
|
|
print(" - mount configuration to bind local/nomad_mcp to /app")
|
|
else:
|
|
print("\n❌ Failed to deploy Nomad MCP service.")
|
|
print(f"Message: {result.get('message', 'Unknown error')}")
|
|
else:
|
|
print(f"\n❌ API request failed with status code: {response.status_code}")
|
|
print(f"Response: {response.text}")
|
|
|
|
except Exception as e:
|
|
print(f"Error deploying Nomad MCP service: {str(e)}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main() |