-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update morpheus module config to use proper device mappings for …
…NVMe EBS volumes
- Loading branch information
Showing
1 changed file
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import sys | ||
| import subprocess | ||
| from typing import Dict, Optional | ||
|
|
||
| # Base directory containing all repositories | ||
| BASE_DIR = "/home/a/arnol377/git" | ||
|
|
||
| # Repository configurations with their commit messages | ||
| REPOS: Dict[str, Dict[str, str]] = { | ||
| "aws-image-pipeline": { | ||
| "message": "fix: update morpheus module config to use proper device mappings for NVMe EBS volumes", | ||
| "branch": "main" | ||
| }, | ||
| "image-pipeline-ansible-playbooks": { | ||
| "message": "fix: update volume mounting to handle NVMe device mapping and add enhanced error checking", | ||
| "branch": "main" | ||
| }, | ||
| "linux-image-pipeline": { | ||
| "message": "fix: update packer configuration to properly handle root volume and NVMe device mappings", | ||
| "branch": "main" | ||
| } | ||
| } | ||
|
|
||
| def run_command(cmd: list[str], cwd: Optional[str] = None) -> tuple[int, str, str]: | ||
| """Run a shell command and return the exit code, stdout, and stderr.""" | ||
| try: | ||
| process = subprocess.Popen( | ||
| cmd, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| cwd=cwd, | ||
| text=True | ||
| ) | ||
| stdout, stderr = process.communicate() | ||
| return process.returncode, stdout, stderr | ||
| except Exception as e: | ||
| return 1, "", str(e) | ||
|
|
||
| def sync_repo(repo_name: str, config: dict) -> bool: | ||
| """Sync (pull/push) a single repository.""" | ||
| repo_path = os.path.join(BASE_DIR, repo_name) | ||
| if not os.path.isdir(repo_path): | ||
| print(f"Error: Directory {repo_path} does not exist") | ||
| return False | ||
|
|
||
| print(f"\nProcessing {repo_name}...") | ||
|
|
||
| # Pull from both remotes | ||
| for remote in ["origin", "hpw"]: | ||
| print(f"Pulling from {remote}...") | ||
| code, out, err = run_command( | ||
| ["git", "pull", remote, config["branch"]], | ||
| repo_path | ||
| ) | ||
| if code != 0: | ||
| print(f"Warning: Failed to pull from {remote}") | ||
| print(f"Error: {err}") | ||
|
|
||
| # Check for changes | ||
| code, out, err = run_command(["git", "status", "--porcelain"], repo_path) | ||
| if code != 0: | ||
| print(f"Error checking git status: {err}") | ||
| return False | ||
|
|
||
| if out.strip(): | ||
| print(f"Changes detected in {repo_name}, committing...") | ||
|
|
||
| # Add all changes | ||
| code, out, err = run_command(["git", "add", "."], repo_path) | ||
| if code != 0: | ||
| print(f"Error adding files: {err}") | ||
| return False | ||
|
|
||
| # Commit changes | ||
| code, out, err = run_command( | ||
| ["git", "commit", "-m", config["message"]], | ||
| repo_path | ||
| ) | ||
| if code != 0: | ||
| print(f"Error committing changes: {err}") | ||
| return False | ||
|
|
||
| # Push to both remotes | ||
| for remote in ["hpw", "origin"]: | ||
| print(f"Pushing to {remote}...") | ||
| code, out, err = run_command( | ||
| ["git", "push", remote, config["branch"]], | ||
| repo_path | ||
| ) | ||
| if code != 0: | ||
| print(f"Warning: Failed to push to {remote}") | ||
| print(f"Error: {err}") | ||
| else: | ||
| print(f"No changes to commit in {repo_name}") | ||
|
|
||
| return True | ||
|
|
||
| def main(): | ||
| """Main function to sync all repositories.""" | ||
| success = True | ||
|
|
||
| # Process each repository | ||
| for repo_name, config in REPOS.items(): | ||
| try: | ||
| if not sync_repo(repo_name, config): | ||
| success = False | ||
| except Exception as e: | ||
| print(f"Error processing {repo_name}: {e}") | ||
| success = False | ||
|
|
||
| if success: | ||
| print("\nAll repositories processed successfully!") | ||
| sys.exit(0) | ||
| else: | ||
| print("\nSome repositories failed to process") | ||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |