class DokkuCli::Cli
Public Instance Methods
config()
click to toggle source
# File lib/dokku_cli/config.rb, line 10 def config run_command "config #{app_name}" end
config_get(key)
click to toggle source
# File lib/dokku_cli/config.rb, line 15 def config_get(key) run_command "config:get #{app_name} #{key}" end
config_set(*args)
click to toggle source
# File lib/dokku_cli/config.rb, line 20 def config_set(*args) # FIXME: Requires root to send config values with spaces user = "dokku" args = args.map{|arg| key_value = arg.split("=") if key_value.length == 2 if key_value[1].index(" ") user = "root" return_value = "#{key_value[0]}=" return_value += '\"' return_value += key_value[1].gsub(/"|'/, "") return_value += '\"' return_value else "#{key_value[0]}=#{key_value[1].gsub(/"|'/, "")}" end else arg end } command = "ssh -p #{port} #{user}@#{domain} " command += user == "root" ? "dokku " : "" command += "config:set #{app_name} #{args.join(' ')}" puts "Running #{command}..." exec(command) end
config_set_file(config_file)
click to toggle source
# File lib/dokku_cli/config.rb, line 56 def config_set_file(config_file) config_params = "" if File.exists?(config_file) File.open(config_file).each_line do |line| config_params += line.strip + " " unless line.start_with? "#" || line.strip == "" end config_set(config_params) else puts "File #{config_file} does not exist." end end
config_unset(*args)
click to toggle source
# File lib/dokku_cli/config.rb, line 51 def config_unset(*args) run_command "config:unset #{app_name} #{args.join(' ')}" end
domains()
click to toggle source
# File lib/dokku_cli/domains.rb, line 5 def domains run_command "domains #{app_name}" end
events()
click to toggle source
# File lib/dokku_cli/events.rb, line 9 def events run_command "events #{app_name}" end
events_list()
click to toggle source
# File lib/dokku_cli/events.rb, line 14 def events_list run_command "events:list #{app_name}" end
events_off()
click to toggle source
# File lib/dokku_cli/events.rb, line 24 def events_off run_command "events:off #{app_name}" end
events_on()
click to toggle source
# File lib/dokku_cli/events.rb, line 19 def events_on run_command "events:on #{app_name}" end
help(method = nil)
click to toggle source
Calls superclass method
# File lib/dokku_cli.rb, line 68 def help(method = nil) method = "walk" if method == "run" super end
keys_add(path, description)
click to toggle source
# File lib/dokku_cli/keys.rb, line 7 def keys_add(path, description) command = "cat #{path} | ssh -p #{port} root@#{domain} 'sudo sshcommand acl-add dokku #{description}'" puts "Adding #{path} to your dokku machine..." exec(command) end
logs()
click to toggle source
# File lib/dokku_cli.rb, line 25 def logs args = options.map{|k, v| "-#{k} #{v}"}.join(" ") if args.empty? run_command "logs #{app_name}" else # remove unnecessary mapped remote option args = args.gsub(/-remote [\S]*/, '') command = "ssh -t -p #{port} dokku@#{domain} logs #{app_name} #{args}" puts "Running #{command}..." exec(command) end end
nginx_access_logs()
click to toggle source
# File lib/dokku_cli/nginx.rb, line 14 def nginx_access_logs run_command "nginx:access-logs #{app_name}" end
nginx_build()
click to toggle source
# File lib/dokku_cli/nginx.rb, line 9 def nginx_build run_command "nginx:build-config #{app_name}" end
nginx_error_logs()
click to toggle source
# File lib/dokku_cli/nginx.rb, line 19 def nginx_error_logs run_command "nginx:error-logs #{app_name}" end
open()
click to toggle source
# File lib/dokku_cli.rb, line 39 def open url = %x[yugen urls --remote #{app_name}].split("\r").first exec("open #{url}") end
ps()
click to toggle source
# File lib/dokku_cli/ps.rb, line 11 def ps run_command "ps #{app_name}" end
ps_rebuild()
click to toggle source
# File lib/dokku_cli/ps.rb, line 16 def ps_rebuild run_command "ps:rebuild #{app_name}" end
ps_restart()
click to toggle source
# File lib/dokku_cli/ps.rb, line 21 def ps_restart run_command "ps:restart #{app_name}" end
ps_scale(*processes)
click to toggle source
# File lib/dokku_cli/ps.rb, line 36 def ps_scale(*processes) if processes.empty? run_command "ps:scale #{app_name}" else run_command "ps:scale #{app_name} #{processes.join(' ')}" end end
ps_start()
click to toggle source
# File lib/dokku_cli/ps.rb, line 26 def ps_start run_command "ps:start #{app_name}" end
ps_stop()
click to toggle source
# File lib/dokku_cli/ps.rb, line 31 def ps_stop run_command "ps:stop #{app_name}" end
url()
click to toggle source
# File lib/dokku_cli.rb, line 59 def url run_command "url #{app_name}" end
urls()
click to toggle source
# File lib/dokku_cli.rb, line 64 def urls run_command "urls #{app_name}" end
walk(*args)
click to toggle source
# File lib/dokku_cli.rb, line 45 def walk(*args) command = "#{args.join(' ')}" case command.gsub(" ", "") when "rakedb:drop" puts "You cannot use `rake db:drop`. Use Dokku directly to delete the database." when "rakedb:create" puts "You cannot use `rake db:create`. Use Dokku directly to create the database." else run_command "run #{app_name} #{command}" end end
Private Instance Methods
app_name()
click to toggle source
# File lib/dokku_cli.rb, line 75 def app_name @app_name ||= git_config["app_name"] end
domain()
click to toggle source
# File lib/dokku_cli.rb, line 79 def domain @domain ||= git_config["domain"] end
git_config()
click to toggle source
# File lib/dokku_cli.rb, line 87 def git_config remote = "yugen" remote = options[:remote] if options[:remote] @git_config ||= begin config_path = File.join(Dir.pwd, ".git", "config") exit unless File.exist?(config_path) config_file = File.read(config_path) # Default dokku config: dokku@host.com:app default_style_regex = /\[remote "#{remote}"\]\s+url \= dokku@(?<domain>.*):(?<app_name>.*)$/ match ||= config_file.match(default_style_regex) # SSH dokku config: ssh://dokku@host.com:1337/app ssh_style_regex = /\[remote "#{remote}"\]\s+url \= ssh:\/\/dokku@(?<domain>.*):(?<port>.*)\/(?<app_name>.*)$/ match ||= config_file.match(ssh_style_regex) exit unless match match = Hash[match.names.zip(match.captures)] match["port"] ||= 22 match end end
port()
click to toggle source
# File lib/dokku_cli.rb, line 83 def port @port ||= git_config["port"] end
run_command(command)
click to toggle source
# File lib/dokku_cli.rb, line 112 def run_command(command) command = command.gsub(/ --remote=[\S]*/, '') dokku_command = "ssh -t -p #{port} dokku@#{domain} #{command}" puts "Connecting to #{app_name}..." exec(dokku_command) end