Module: OpsWorks::CLI::Subcommands::Apps
- Included in:
- Agent
- Defined in:
- lib/opsworks/cli/subcommands/apps.rb
Class Method Summary collapse
-
.included(thor) ⇒ Object
rubocop:disable MethodLength rubocop:disable CyclomaticComplexity rubocop:disable PerceivedComplexity.
Class Method Details
.included(thor) ⇒ Object
rubocop:disable MethodLength rubocop:disable CyclomaticComplexity rubocop:disable PerceivedComplexity
10 11 12 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/opsworks/cli/subcommands/apps.rb', line 10 def self.included(thor) thor.class_eval do desc 'apps:deploy APP [--stack STACK]', 'Deploy an OpsWorks app' option :stack, type: :array option :timeout, type: :numeric, default: 300 option :migrate, type: :boolean, default: false define_method 'apps:deploy' do |name| fetch_credentials unless env_credentials? stacks = parse_stacks(.merge(active: true)) deployments = stacks.map do |stack| next unless (app = stack.find_app_by_name(name)) say "Deploying to #{stack.name}..." stack.deploy_app(app, 'migrate' => [[:migrate].to_s]) end deployments.compact! OpsWorks::Deployment.wait(deployments, [:timeout]) unless deployments.all?(&:success?) failures = [] deployments.each_with_index do |deployment, i| failures << stacks[i].name unless deployment.success? end fail "Deploy failed on #{failures.join(', ')}" end end desc 'apps:status APP [--stack STACK]', 'Display the most recent deployment of an app' option :stack, type: :array define_method 'apps:status' do |name| fetch_credentials unless env_credentials? table = parse_stacks().map do |stack| next unless (app = stack.find_app_by_name(name)) if (deployment = app.last_deployment) deployed_at = formatted_time(deployment.created_at) else deployed_at = '-' end [stack.name, name, "(#{app.revision})", deployed_at] end # Sort output in descending date order table.compact! table.sort! { |x, y| y.last <=> x.last } print_table table end desc 'apps:create APP [--stack STACK]', 'Create a new OpsWorks app' option :stack, type: :array option :type, default: 'other' option :git_url option :shortname define_method 'apps:create' do |name| unless %w(other).include?([:type]) fail "Unsupported type: #{[:type]}" end fail 'Git URL not yet supported' if [:git_url] fetch_credentials unless env_credentials? stacks = parse_stacks() stacks.each do |stack| next if stack.apps.map(&:name).include?(name) say "Creating app on #{stack.name}." stack.create_app(name, ) end end private def formatted_time() .strftime('%Y-%m-%d %H:%M:%S %Z') end end end |