Class: Deploy::CLI
- Inherits:
-
Object
show all
- Defined in:
- lib/deploy/cli.rb,
lib/deploy/cli/websocket_client.rb,
lib/deploy/cli/deployment_progress_output.rb
Defined Under Namespace
Classes: DeploymentProgressOutput, WebsocketClient
Constant Summary
collapse
- PROTOCOL_NAME =
Constants for formatting output
{ ssh: 'SSH/SFTP', ftp: 'FTP', s3: 'Amazon S3', rackspace: 'Rackspace CloudFiles' }.freeze
Class Method Summary
collapse
Class Method Details
.ask_config_question(question_text, valid_format = /.+/) ⇒ Object
169
170
171
172
173
174
175
176
177
|
# File 'lib/deploy/cli.rb', line 169
def ask_config_question(question_text, valid_format = /.+/)
question_text = "#{question_text}: "
ask(question_text) do |q|
q.whitespace = :remove
q.responses[:not_valid] = 'That answer is not valid'
q.responses[:ask_on_error] = :question
q.validate = valid_format
end
end
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/deploy/cli.rb', line 148
def configure
configuration = {
account: ask_config_question('Account Domain (e.g. https://atech.deployhq.com)',
/\Ahttps?:\/\/[a-z0-9.-]+.deployhq.com\z/),
username: ask_config_question('Username or e-mail address'),
api_key: ask_config_question('API key (You can find this in Settings -> Security)'),
project: ask_config_question('Default project to use (please use permalink from web URL)')
}
confirmation = true
if File.exist?(@options.config_file)
confirmation = agree("File already exists at #{@options.config_file}. Overwrite? ")
end
return unless confirmation
file_data = JSON.pretty_generate(configuration)
File.write(@options.config_file, file_data)
say("File written to #{@options.config_file}")
end
|
.deploy ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/deploy/cli.rb', line 118
def deploy
@ungrouped_servers = @project.servers
@server_groups = @project.server_groups
parent = nil
while parent.nil?
parent = choose do ||
.prompt = 'Please choose a server or group to deploy to:'
.choices(*(@ungrouped_servers + @server_groups))
.choice('List Server Details') do
server_list
nil
end
end
end
if @options.config_files_deployment
$stdout.print "\nStarting config files deployment\n"
deployment = @project.config_files_deployment(parent.identifier)
else
$stdout.print "\nStarting deployment\n"
latest_revision = @project.latest_revision(parent.preferred_branch)
deployment = @project.deploy(parent.identifier, parent.last_revision, latest_revision)
end
$stdout.print 'Waiting for an available deployment slot...'
DeploymentProgressOutput.new(deployment).monitor
end
|
.invoke(args) ⇒ Object
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
98
99
|
# File 'lib/deploy/cli.rb', line 25
def invoke(args)
@options = OptionsStruct.new
parser = OptionParser.new do |opts| opts.banner = 'Usage: deployhq [options] command'
opts.separator ''
opts.separator 'Commands:'
opts.separator "deploy\t\t Start a new deployment"
opts.separator "servers\t\t List configured servers and server groups"
opts.separator "configure\t\t Create a new configuration file for this tool"
opts.separator ''
opts.separator 'Common Options:'
@options.config_file = './Deployfile'
opts.on('-c', '--config path', 'Configuration file path') do |config_file_path|
@options.config_file = config_file_path
end
opts.on('-p', '--project project',
'Project to operate on (default is read from project: in config file)') do |project_permalink|
@options.project = project_permalink
end
@options.config_files_deployment = false
opts.on('--config-files', 'Config files deployment') do |_config_files_deployment|
@options.config_files_deployment = true
end
opts.on_tail('-v', '--version', 'Shows Version') do
puts Deploy::VERSION
exit
end
opts.on_tail('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
begin
parser.parse!(args)
command = args.pop
rescue OptionParser::InvalidOption
warn parser
exit 1
end
unless command == 'configure'
begin
Deploy.configuration_file = @options.config_file
rescue Errno::ENOENT
warn "Couldn't find configuration file at #{@options.config_file.inspect}"
exit 1
end
project_permalink = @options.project || Deploy.configuration.project
if project_permalink.nil?
warn 'Project must be specified in config file or as --project argument'
exit 1
end
@project = Deploy::Project.find(project_permalink)
end
case command
when 'deploy'
deploy
when 'servers'
server_list
when 'configure'
configure
else
warn parser
end
end
|
.server_list ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/deploy/cli.rb', line 101
def server_list
@server_groups ||= @project.server_groups
if @server_groups.count.positive?
@server_groups.each do |group|
puts "Group: #{group.name}"
puts group.servers.map { |server| format_server(server) }.join("\n\n")
end
end
@ungrouped_servers ||= @project.servers
return unless @ungrouped_servers.count.positive?
puts "\n" if @server_groups.count.positive?
puts 'Ungrouped Servers'
puts @ungrouped_servers.map { |server| format_server(server) }.join("\n\n")
end
|