5
6
7
8
9
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
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/opsworks/cli/subcommands/apps.rb', line 5
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
option :layer, type: :string
define_method 'apps:deploy' do |name|
stacks = parse_stacks(options.merge(active: true))
deployments = stacks.map do |stack|
next unless (app = stack.find_app_by_name(name))
say "Deploying to #{stack.name}..."
dpl = stack.deploy_app(
app,
layer: options[:layer],
args: { 'migrate' => [options[:migrate].to_s] }
)
next unless dpl
[stack, dpl]
end.compact
OpsWorks::Deployment.wait(deployments.map(&:last),
options[:timeout])
failures = deployments.map do |stack, deployment|
next if deployment.success?
stack
end.compact
unless failures.empty?
raise "Deploy failed on #{failures.map(&:name).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|
table = parse_stacks(options).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
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?(options[:type])
raise "Unsupported type: #{options[:type]}"
end
raise 'Git URL not yet supported' if options[:git_url]
stacks = parse_stacks(options)
stacks.each do |stack|
next if stack.apps.map(&:name).include?(name)
say "Creating app on #{stack.name}."
stack.create_app(name, options)
end
end
desc 'apps:revision:update APP REVISION [--stack STACK]',
'Set the revision for an app'
option :stack, type: :array
define_method 'apps:revision:update' do |app_name, revision|
stacks = parse_stacks(options.merge(active: true))
stacks.each do |stack|
next unless (app = stack.find_app_by_name(app_name))
say "Updating #{stack.name} (from: #{app.revision})..."
app.update_revision(revision)
end
end
private
def formatted_time(timestamp)
timestamp.strftime('%Y-%m-%d %H:%M:%S %Z')
end
end
end
|