Add git status check before Nomad MCP deployment
- Implement comprehensive git status verification in deploy_nomad_mcp.py - Add warning and interactive prompts for uncommitted changes - Check local branch status against remote repository - Provide options to continue or abort deployment - Update Nomad job configuration to use DEBUG logging level
This commit is contained in:
@ -13,9 +13,95 @@ from app.services.nomad_client import NomadService
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
def check_git_status():
|
||||
"""Check if there are uncommitted changes in the git repository."""
|
||||
try:
|
||||
# Check for uncommitted changes
|
||||
result = subprocess.run(
|
||||
["git", "status", "--porcelain"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
if result.stdout.strip():
|
||||
print("\n⚠️ WARNING: You have uncommitted changes in your repository!")
|
||||
print("The Nomad job will pull code from Gitea, not your local changes.")
|
||||
print("Uncommitted files:")
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
print(f" - {line}")
|
||||
|
||||
# Check if we're behind the remote
|
||||
result = subprocess.run(
|
||||
["git", "status", "-sb"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
if "behind" in result.stdout:
|
||||
print("\n⚠️ Your local branch is behind the remote repository!")
|
||||
print("The deployed code will be from the remote repository, not your local version.")
|
||||
|
||||
print("\nDo you want to:")
|
||||
print("1. Continue deployment anyway (will use the code in Gitea)")
|
||||
print("2. Abort to commit and push your changes first")
|
||||
|
||||
choice = input("\nEnter your choice (1 or 2): ").strip()
|
||||
if choice == "2":
|
||||
print("\nDeployment aborted. Please commit and push your changes first:")
|
||||
print(" git add .")
|
||||
print(" git commit -m \"Your commit message\"")
|
||||
print(" git push")
|
||||
sys.exit(0)
|
||||
elif choice == "1":
|
||||
print("\nContinuing with deployment using the code in Gitea...")
|
||||
else:
|
||||
print("\nInvalid choice. Aborting deployment.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Check if we're up to date with remote
|
||||
result = subprocess.run(
|
||||
["git", "status", "-sb"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
if "behind" in result.stdout:
|
||||
print("\n⚠️ Your local branch is behind the remote repository!")
|
||||
print("The deployed code will be from the remote repository, not your local version.")
|
||||
print("Do you want to pull the latest changes before checking? (y/n)")
|
||||
|
||||
choice = input().strip().lower()
|
||||
if choice == "y":
|
||||
subprocess.run(["git", "pull"], check=True)
|
||||
print("Successfully pulled latest changes.")
|
||||
else:
|
||||
print("Continuing with deployment using the code in Gitea...")
|
||||
else:
|
||||
print("✅ Git repository is clean and up to date with remote.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"\n⚠️ Warning: Failed to check git status: {e}")
|
||||
print("Unable to verify if all changes are committed and pushed.")
|
||||
print("Please ensure your code is committed and pushed to Gitea before deploying.")
|
||||
|
||||
print("\nDo you want to continue anyway? (y/n)")
|
||||
choice = input().strip().lower()
|
||||
if choice != "y":
|
||||
print("Deployment aborted.")
|
||||
sys.exit(0)
|
||||
except Exception as e:
|
||||
print(f"\n⚠️ Warning: Error checking git status: {str(e)}")
|
||||
print("Unable to verify if all changes are committed and pushed.")
|
||||
print("Please ensure your code is committed and pushed to Gitea before deploying.")
|
||||
|
||||
def main():
|
||||
print("Deploying Nomad MCP service using our own Nomad client...")
|
||||
|
||||
# Check git status before deployment
|
||||
check_git_status()
|
||||
|
||||
# Check if NOMAD_ADDR is configured
|
||||
nomad_addr = os.getenv("NOMAD_ADDR")
|
||||
if not nomad_addr:
|
||||
|
Reference in New Issue
Block a user