Handle deployment commands.
(args)
| 449 | |
| 450 | |
| 451 | def handle_deploy_command(args): |
| 452 | """Handle deployment commands.""" |
| 453 | try: |
| 454 | if args.deploy_command == 'github-to-ec2': |
| 455 | # Get credentials |
| 456 | cred_manager = get_credential_manager() |
| 457 | aws_creds = cred_manager.get_aws_credentials(region=args.region) |
| 458 | github_creds = cred_manager.get_github_credentials() |
| 459 | |
| 460 | # Initialize services |
| 461 | ec2 = EC2Service(credentials=aws_creds) |
| 462 | github = GitHubService(token=github_creds.token) |
| 463 | |
| 464 | # Verify GitHub repository exists |
| 465 | repo_info = github.get_repository(args.repo) |
| 466 | logger.info(f"Deploying from repository: {repo_info['full_name']}") |
| 467 | |
| 468 | # Verify EC2 instance exists |
| 469 | instance = ec2.get_instance(args.instance_id) |
| 470 | logger.info(f"Deploying to instance: {args.instance_id}") |
| 471 | |
| 472 | # Deploy from GitHub to EC2 |
| 473 | result = ec2.deploy_from_github( |
| 474 | instance_id=args.instance_id, |
| 475 | repository=args.repo, |
| 476 | branch=args.branch, |
| 477 | deploy_path=args.path, |
| 478 | setup_script=args.setup_script, |
| 479 | github_token=github_creds.token |
| 480 | ) |
| 481 | |
| 482 | status = result.get('status', 'unknown') |
| 483 | if status.lower() in ['success', 'succeeded']: |
| 484 | print(f"{COLORS['green']}Deployment status: {status}{COLORS['reset']}") |
| 485 | else: |
| 486 | print(f"{COLORS['yellow']}Deployment status: {status}{COLORS['reset']}") |
| 487 | |
| 488 | if result.get('output'): |
| 489 | print(f"{COLORS['cyan']}Deployment output:{COLORS['reset']}") |
| 490 | print(result['output']) |
| 491 | if result.get('error'): |
| 492 | print(f"{COLORS['red']}Deployment error:{COLORS['reset']}") |
| 493 | print(result['error']) |
| 494 | |
| 495 | elif args.deploy_command == 'github-to-s3': |
| 496 | print_error( |
| 497 | "S3 deployment not yet implemented", |
| 498 | suggestion="This feature is planned for a future release." |
| 499 | ) |
| 500 | return 1 |
| 501 | |
| 502 | return 0 |
| 503 | |
| 504 | except Exception as e: |
| 505 | return handle_cli_error(e) |
| 506 | |
| 507 | |
| 508 | def main(): |