Class: Belt::CLI::DeployCommand
- Inherits:
-
Object
- Object
- Belt::CLI::DeployCommand
- Defined in:
- lib/belt/cli/deploy_command.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(env, auto_approve: false, extra_args: []) ⇒ DeployCommand
constructor
A new instance of DeployCommand.
- #run ⇒ Object
- #run_rebuild ⇒ Object
Constructor Details
#initialize(env, auto_approve: false, extra_args: []) ⇒ DeployCommand
Returns a new instance of DeployCommand.
105 106 107 108 109 110 111 |
# File 'lib/belt/cli/deploy_command.rb', line 105 def initialize(env, auto_approve: false, extra_args: []) @env = env @auto_approve = auto_approve @extra_args = extra_args @infra_dir = TerraformCommand.find_infrastructure_dir @project_root = find_project_root end |
Class Method Details
.help_text ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/belt/cli/deploy_command.rb', line 71 def self.help_text <<~HELP Deploy your Belt application to AWS. Usage: belt deploy [environment] [options] belt deploy frontend <environment> This runs the full deployment lifecycle: 1. Ensure Gemfile.lock is consistent (fix stale PATH refs) 2. terraform init (initialize providers/modules) 3. terraform plan (preview changes) 4. Prompt for confirmation (unless --auto) 5. terraform apply (deploy changes) Options: --auto, --yes, -y Skip confirmation prompt (auto-approve) --rebuild Rebuild and push Lambda code directly (bypasses Terraform). Much faster for code-only changes ā packages gems via Docker, zips, and pushes with `aws lambda update-function-code`. -h, --help Show this help Environment: Defaults to BELT_ENV if set, otherwise the first available environment. Examples: belt deploy # Deploy dev (or BELT_ENV) belt deploy prod # Deploy to prod belt deploy dev --auto # Deploy without confirmation (CI mode) belt deploy --rebuild # Fast code push to dev (no infra changes) belt deploy prod --rebuild # Fast code push to prod belt deploy frontend dev # Deploy frontend assets only HELP end |
.run(args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/belt/cli/deploy_command.rb', line 13 def self.run(args) # Handle `belt deploy frontend <env>` as before if args.first == 'frontend' args.shift Belt::CLI::FrontendDeployCommand.run(args) return end auto_approve = false rebuild = false filtered_args = [] args.each do |arg| case arg when '--auto', '--yes', '-y' auto_approve = true when '--rebuild' rebuild = true when '-h', '--help' puts help_text exit 0 else filtered_args << arg end end env = EnvResolver.resolve(filtered_args) # Default to the first available environment when none specified if env.nil? available = TerraformCommand.list_environments if available.any? env = available.first else puts 'Usage: belt deploy [environment] [options]' puts "\nDefaults to BELT_ENV or the first available environment." puts "\nOptions:" puts ' --auto, --yes, -y Skip confirmation prompt (auto-approve)' puts ' --rebuild Rebuild and push Lambda code directly (bypasses Terraform)' puts ' -h, --help Show this help' puts "\nExamples:" puts ' belt deploy # Deploy dev (or BELT_ENV)' puts ' belt deploy prod # Deploy to prod' puts ' belt deploy dev --auto # Deploy without confirmation' puts ' belt deploy --rebuild # Fast code push (no infra changes)' puts ' belt deploy frontend dev # Deploy frontend only' puts "\nNo environments found. Run `belt generate environment dev` first." exit 1 end end if rebuild new(env, auto_approve: auto_approve, extra_args: filtered_args).run_rebuild else new(env, auto_approve: auto_approve, extra_args: filtered_args).run end end |
Instance Method Details
#run ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/belt/cli/deploy_command.rb', line 113 def run validate! env_dir = File.join(@infra_dir, @env) puts "belt ā deploying #{@env} (in #{env_dir}/)\n\n" ensure_lockfile_consistent! Dir.chdir(env_dir) do run_init run_plan return unless confirm_apply run_apply end puts "\nā Deployed #{@env} successfully!" print_outputs(env_dir) puts "\n Run `belt server` to view your app locally (auto-connects to the deployed API)." end |
#run_rebuild ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/belt/cli/deploy_command.rb', line 133 def run_rebuild validate! validate_aws! puts "belt ā rebuilding Lambda for #{@env}\n\n" lambda_dir = find_lambda_dir abort 'Error: Cannot find lambda/ directory.' unless lambda_dir function_name = find_lambda_function_name abort 'Error: Cannot determine Lambda function name from Terraform state.' unless function_name ensure_lockfile_consistent! generate_routes(lambda_dir) build_and_deploy(lambda_dir, function_name) end |