Class: Deploy::CLI

Inherits:
Object
  • 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"}

Class Method Summary collapse

Class Method Details

.ask_config_question(question_text, valid_format = /.+/) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/deploy/cli.rb', line 149

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

.configureObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/deploy/cli.rb', line 128

def configure
  configuration = {
    account: ask_config_question("Account Domain (e.g. https://atech.deployhq.com)",
      %r{\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.exists?(@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

.deployObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/deploy/cli.rb', line 104

def deploy
  @ungrouped_servers = @project.servers
  @server_groups = @project.server_groups

  parent = nil
  while parent.nil?
    parent = choose do |menu|
      menu.prompt = "Please choose a server or group to deploy to:"

      menu.choices(*(@ungrouped_servers + @server_groups))
      menu.choice("List Server Details") do
        server_list
        nil
      end
    end
  end

  latest_revision = @project.latest_revision(parent.preferred_branch)
  deployment = @project.deploy(parent.identifier, parent.last_revision, latest_revision)

  STDOUT.print "Waiting for an available deployment slot..."
  DeploymentProgressOutput.new(deployment).monitor
end

.invoke(args) ⇒ Object



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
# File 'lib/deploy/cli.rb', line 16

def invoke(args)
  @options = OpenStruct.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

    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
    STDERR.puts parser.to_s
    exit 1
  end

  unless command == 'configure'
    begin
      Deploy.configuration_file = @options.config_file
    rescue Errno::ENOENT
      STDERR.puts "Couldn't find configuration file at #{@options.config_file.inspect}"
      exit 1
    end

    project_permalink = @options.project || Deploy.configuration.project
    if project_permalink.nil?
      STDERR.puts "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
    STDERR.puts parser.to_s
  end
end

.server_listObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/deploy/cli.rb', line 87

def server_list
  @server_groups ||= @project.server_groups
  if @server_groups.count > 0
    @server_groups.each do |group|
      puts "Group: #{group.name}".bold
      puts group.servers.map {|server| format_server(server) }.join("\n\n")
    end
  end

  @ungrouped_servers ||= @project.servers
  if @ungrouped_servers.count > 0
    puts "\n" if @server_groups.count > 0
    puts "Ungrouped Servers".bold
    puts @ungrouped_servers.map {|server| format_server(server) }.join("\n\n")
  end
end