class Dogids::Cli
Public Class Methods
This is the directory where your templates should be placed.
# File lib/dogids/base.rb, line 38 def self.source_root File.expand_path("../../../resources", __FILE__) end
Public Instance Methods
# File lib/dogids/cache.rb, line 9 def cache(env_name = nil) puts " " puts "Cache Commands:" puts " " puts " Use the following format:" puts " dogids cache:<environment> <machine> <action>" puts " " puts " Here are some basic examples:" puts " " puts " dogids cache:dev dev clear # Clear whole cache for the dogids.dev storefront" puts " dogids cache:dev dev category # Clear category cache for the dogids.dev storefront" puts " dogids cache:dev dev css # Clear CSS cache for the dogids.dev storefront" puts " dogids cache:dev dev javascript # Clear Javascript cache for the dogids.dev storefront" puts " dogids cache:dev dev qa # Clear Q&A cache for the dogids.dev storefront" puts " " puts " dogids cache:staging staging clear # Clear whole cache for the staging.dogids.com storefront" puts " dogids cache:staging staging category # Clear category cache for the staging.dogids.com storefront" puts " dogids cache:staging staging css # Clear CSS cache for the staging.dogids.com storefront" puts " dogids cache:staging staging javascript # Clear Javascript cache for the staging.dogids.com storefront" puts " dogids cache:staging staging qa # Clear Q&A cache for the staging.dogids.com storefront" puts " " puts " dogids cache:production web clear # Clear whole cache for the dogids.com storefront" puts " dogids cache:production web category # Clear category cache for the dogids.dev storefront" puts " dogids cache:production web css # Clear CSS cache for the production.dogids.com storefront" puts " dogids cache:production web javascript # Clear Javascript cache for the production.dogids.com storefront" puts " dogids cache:production web qa # Clear Q&A cache for the dogids.com storefront" puts " " end
# File lib/dogids/cache/development.rb, line 7 def cache_dev(vm_name = nil, cache = nil) ssh_address = get_config_url("dev",vm_name) return if ssh_address == false case cache when "category" print_heading("Checking the category items cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_category_cache_files_dev_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the DEV category items cache? [no]") print_heading("Clearing the development category items cache") ssh.exec!(clear_category_cache_dev_command) do |_channel, _stream, data| end end end when "clear" print_heading("Let's start clearing the entire dev cache") cache_dev(vm_name,"category") cache_dev(vm_name,"qa") cache_dev(vm_name,"javascript") cache_dev(vm_name,"css") when "css" print_heading("Checking the CSS cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_css_cache_files_dev_command) do |_channel, _stream, data| print_command("Current CSS cache files: " + data) end if yes?("-----> Continue with clearing the DEV CSS cache? [no]") print_heading("Clearing the development CSS cache") ssh.exec!(clear_css_cache_dev_command) do |_channel, _stream, data| end end end when "javascript" print_heading("Checking the Javascript cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_javascript_cache_files_dev_command) do |_channel, _stream, data| print_command("Current Javascript cache files: " + data) end if yes?("-----> Continue with clearing the DEV Javascript cache? [no]") print_heading("Clearing the development Javascript cache") ssh.exec!(clear_javascript_cache_dev_command) do |_channel, _stream, data| end end end when "qa" print_heading("Checking the product Q&A cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_qa_cache_files_dev_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the DEV product Q&A cache? [no]") print_heading("Clearing the development Q&A cache") ssh.exec!(clear_qa_cache_dev_command) do |_channel, _stream, data| end end end else cache end end
# File lib/dogids/cache/production.rb, line 7 def cache_production(vm_name = nil, cache = nil) ssh_address = get_config_url("production",vm_name) return if ssh_address == false case cache when "category" print_heading("Checking the category items cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_category_cache_files_production_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the PRODUCTION category items cache? [no]") print_heading("Clearing the production category items cache") ssh.exec!(clear_category_cache_production_command) do |_channel, _stream, data| end end end when "clear" print_heading("Let's start clearing the entire production cache") cache_production(vm_name,"category") cache_production(vm_name,"qa") cache_production(vm_name,"javascript") cache_production(vm_name,"css") when "css" print_heading("Checking the CSS cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_css_cache_files_production_command) do |_channel, _stream, data| print_command("Current CSS cache files: " + data) end if yes?("-----> Continue with clearing the PRODUCTION CSS cache? [no]") print_heading("Clearing the development CSS cache") ssh.exec!(clear_css_cache_production_command) do |_channel, _stream, data| end end end when "javascript" print_heading("Checking the Javascript cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_javascript_cache_files_production_command) do |_channel, _stream, data| print_command("Current Javascript cache files: " + data) end if yes?("-----> Continue with clearing the PRODUCTION Javascript cache? [no]") print_heading("Clearing the development Javascript cache") ssh.exec!(clear_javascript_cache_production_command) do |_channel, _stream, data| end end end when "qa" print_heading("Checking the product Q&A cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_qa_cache_files_production_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the PRODUCTION product Q&A cache? [no]") print_heading("Clearing the production product Q&A cache") ssh.exec!(clear_qa_cache_production_command) do |_channel, _stream, data| end end end else cache end end
# File lib/dogids/cache/staging.rb, line 7 def cache_staging(vm_name = nil, cache = nil) ssh_address = get_config_url("staging",vm_name) return if ssh_address == false case cache when "category" print_heading("Checking the category reviews cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_category_cache_files_staging_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the STAGING category item cache? [no]") print_heading("Clearing the staging category cache") ssh.exec!(clear_category_cache_staging_command) do |_channel, _stream, data| end end end when "clear" print_heading("Let's start clearing the entire staging cache") cache_staging(vm_name,"category") cache_staging(vm_name,"qa") cache_staging(vm_name,"javascript") cache_staging(vm_name,"css") when "css" print_heading("Checking the CSS cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_css_cache_files_staging_command) do |_channel, _stream, data| print_command("Current CSS cache files: " + data) end if yes?("-----> Continue with clearing the STAGING CSS cache? [no]") print_heading("Clearing the development CSS cache") ssh.exec!(clear_css_cache_staging_command) do |_channel, _stream, data| end end end when "javascript" print_heading("Checking the Javascript cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_javascript_cache_files_staging_command) do |_channel, _stream, data| print_command("Current Javascript cache files: " + data) end if yes?("-----> Continue with clearing the STAGING Javascript cache? [no]") print_heading("Clearing the development Javascript cache") ssh.exec!(clear_javascript_cache_staging_command) do |_channel, _stream, data| end end end when "qa" print_heading("Checking the product Q&A cache") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| ssh.exec!(count_qa_cache_files_staging_command) do |_channel, _stream, data| print_command("Current category reviews: " + data) end if yes?("-----> Continue with clearing the STAGING product Q&A cache? [no]") print_heading("Clearing the staging QA cache") ssh.exec!(clear_qa_cache_staging_command) do |_channel, _stream, data| end end end else cache end end
# File lib/dogids/cache/development.rb, line 101 def clear_category_cache_dev_command commands = [] commands << "cd /apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'category*' -delete" commands.join("&&") end
# File lib/dogids/cache/production.rb, line 101 def clear_category_cache_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'category*' -delete" commands.join("&&") end
# File lib/dogids/cache/staging.rb, line 100 def clear_category_cache_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'category*' -delete" commands.join("&&") end
# File lib/dogids/cache/development.rb, line 108 def clear_css_cache_dev_command commands = [] commands << "cd /apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.css.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/production.rb, line 115 def clear_css_cache_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.css.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/staging.rb, line 114 def clear_css_cache_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.css.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/development.rb, line 115 def clear_javascript_cache_dev_command commands = [] commands << "cd /apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.javascript.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/production.rb, line 122 def clear_javascript_cache_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.javascript.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/staging.rb, line 121 def clear_javascript_cache_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "sudo find . -type f -iname '*.javascript.gz' -delete" commands.join("&&") end
# File lib/dogids/cache/development.rb, line 122 def clear_qa_cache_dev_command commands = [] commands << "cd /apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'turnto*' -delete" commands.join("&&") end
# File lib/dogids/cache/production.rb, line 108 def clear_qa_cache_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'turnto*' -delete" commands.join("&&") end
# File lib/dogids/cache/staging.rb, line 107 def clear_qa_cache_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "sudo find . -type f -iname 'turnto*' -delete" commands.join("&&") end
# File lib/dogids/config.rb, line 7 def config(command = nil) # Commands case command when "list" list when "clear" if yes?("------->Remove all configurations? [no]") system("rm ~/.dogids/conf.yaml") puts " " say("All configurations removed","\e[31m") set_default_configuration puts " " list else say("Fine, I didn't want to remove anything anyway","\e[31m") end else puts " " puts "Config Commands:" puts " " puts " Use the following so set environments:" puts " dogids config:<environment> <machine>" puts " " puts " dogids config list # List all current configurations" puts " " puts " dogids config:dev # Set URL/IP for Development Machines" puts " dogids config:production # Set URL/IP for Production Machines" puts " dogids config:staging # Set URL/IP for Staging machines" puts " " end end
Config dev environment @param [string] location
# File lib/dogids/config.rb, line 43 def config_dev(location = nil) location ? set_config("dev",location) : config end
Config production environment @param [string] location
# File lib/dogids/config.rb, line 55 def config_production(location = nil) location ? set_config("production",location) : config end
Config staging environment @param [string] location
# File lib/dogids/config.rb, line 49 def config_staging(location = nil) location ? set_config("staging",location) : config end
# File lib/dogids/cache/development.rb, line 73 def count_category_cache_files_dev_command commands = [] commands << "cd /apps/dogids.com/ls_file_cache" commands << "find . -iname 'category*' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/production.rb, line 73 def count_category_cache_files_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "find . -iname 'category*' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/staging.rb, line 72 def count_category_cache_files_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "find . -iname 'category*' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/development.rb, line 94 def count_css_cache_files_dev_command commands = [] commands << "cd /apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.css.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/production.rb, line 94 def count_css_cache_files_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.css.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/staging.rb, line 93 def count_css_cache_files_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.css.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/development.rb, line 87 def count_javascript_cache_files_dev_command commands = [] commands << "cd /apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.javascript.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/production.rb, line 87 def count_javascript_cache_files_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.javascript.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/staging.rb, line 86 def count_javascript_cache_files_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/temp/resource_cache" commands << "find . -iname '*.javascript.gz' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/development.rb, line 80 def count_qa_cache_files_dev_command commands = [] commands << "cd /apps/dogids.com/ls_file_cache" commands << "find . -iname 'turnto*' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/production.rb, line 80 def count_qa_cache_files_production_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "find . -iname 'turnto*' | wc -l" commands.join("&& ") end
# File lib/dogids/cache/staging.rb, line 79 def count_qa_cache_files_staging_command commands = [] commands << "cd /home/dogids/apps/dogids.com/ls_file_cache" commands << "find . -iname 'turnto*' | wc -l" commands.join("&& ") end
# File lib/dogids/deploy.rb, line 11 def deploy(app_name = nil) deploy_command = "deploy_#{app_name}" return self.send(deploy_command) if self.respond_to?(deploy_command) puts "Deployment Commands:" puts " dogids deploy backend # Deploy the new backend" puts " dogids deploy staging # Deploy the staging.dogids.com storefront" puts " dogids deploy testing # Deploy the new backend to testing" puts " dogids deploy web # Deploy the dogids.com storefront" puts " dogids deploy worker # Deploy the dogids-backgrounder app" puts " " end
# File lib/dogids/deploy/backend.rb, line 7 def deploy_backend print_heading("Deploying backend to admin.dogids.com") server_addresses = [ "admin" ] server_addresses.each do |server_address| ssh_address = get_config_url("production","#{server_address}") next if ssh_address == false print_command("Server(#{server_address}): #{ssh_address}") Net::SSH.start(ssh_address, "dogids") do |ssh| print_command("Checking the current git status") ssh.exec!(backend_git_status_command) do |_channel, _stream, data| print_command(data) end if yes?("-----> Continue with deployment? [no]") print_command("Pulling latest from master") ssh.exec!(backend_git_pull_command) do |_channel, _stream, data| print_command(data) end ssh.exec!(backend_composer_commands) do |_channel, _stream, data| print_command(data) end ssh.exec!(backend_deployment_commands) do |_channel, _stream, data| print_command(data) end end end end print_heading("Done.") end
# File lib/dogids/deploy/staging.rb, line 7 def deploy_staging print_heading("Deploying dogids.com site to staging server") server_addresses = [ "staging" ] server_addresses.each do |server_address| ssh_address = get_config_url("staging",server_address) next if ssh_address == false Net::SSH.start("#{ssh_address}", "dogids") do |ssh| print_command("Checking the current git status") ssh.exec!(staging_git_status_command) do |_channel, _stream, data| print_command(data) end current_branch = ssh.exec!("cd /home/dogids/apps/dogids.com && git rev-parse --abbrev-ref HEAD").strip print_heading("Current Branch: #{current_branch}") print_heading("Available Branches:") ssh.exec!("cd /home/dogids/apps/dogids.com && git branch -r --no-merged master") do |_channel, _stream, data| print_command("master") data.split("\n").each do |branch| print_command(branch.gsub("origin/", "")) end end branch = ask("-----> Which branch would you like to deploy?").strip break print_command("Fine, be that way.") if branch.length == 0 print_command("Pulling latest from #{branch}") ssh.exec!(staging_git_pull_command(branch)) do |_channel, _stream, data| print_command(data) end print_command("Updating file permissions") ssh.exec!(web_update_permissions_command) do |_channel, _stream, data| print_command(data) end git_sha = "Unknown" ssh.exec!(web_git_get_sha) do |_channel, _stream, data| git_sha = data.strip end print_command("Current git SHA: #{git_sha}") end end print_heading("Done.") end
# File lib/dogids/deploy/testing.rb, line 7 def deploy_testing print_heading("Deploying backend to testing.dogids.com") server_addresses = [ "testing" ] server_addresses.each do |server_address| ssh_address = get_config_url("staging","#{server_address}") next if ssh_address == false print_command("Server(#{server_address}): #{ssh_address}") Net::SSH.start(ssh_address, "dogids") do |ssh| print_command("Checking the current git status") ssh.exec!(backend_git_status_command) do |_channel, _stream, data| print_command(data) end current_branch = ssh.exec!("cd /home/dogids/apps/dogids-backend && git rev-parse --abbrev-ref HEAD").strip print_heading("Current Branch: #{current_branch}") branch = ask("-----> Which branch would you like to deploy? [#{current_branch}]").strip break print_command("Fine, be that way.") if branch.downcase == "cancel" branch = current_branch if branch.length == 0 print_command("Pulling latest from #{branch}") ssh.exec!(backend_git_pull_command(branch)) do |_channel, _stream, data| print_command(data) end ssh.exec!(backend_composer_commands) do |_channel, _stream, data| print_command(data) end ssh.exec!(backend_deployment_commands) do |_channel, _stream, data| print_command(data) end end end print_heading("Done.") end
# File lib/dogids/deploy/web.rb, line 7 def deploy_web print_heading("Deploying dogids.com") # Get each production server matching "web" for deploy server_addresses = [] production_servers = get_config_url("production") production_servers.map do |key, ip_address| if key.include? "web" server_addresses << key end end server_addresses.each do |server_address| ssh_address = get_config_url("production","#{server_address}") next if ssh_address == false print_command("Server(#{server_address}): #{ssh_address}") Net::SSH.start(ssh_address, "dogids") do |ssh| print_command("Checking the current git status") ssh.exec!(web_git_status_command) do |_channel, _stream, data| print_command(data) end if yes?("-----> Continue with deployment? [no]") print_command("Pulling latest from master") ssh.exec!(web_git_pull_command) do |_channel, _stream, data| print_command(data) end print_command("Updating file permissions") ssh.exec!(web_update_permissions_command) do |_channel, _stream, data| print_command(data) end git_sha = "Unknown" ssh.exec!(web_git_get_sha) do |_channel, _stream, data| git_sha = data.strip end print_command("Current git SHA: #{git_sha}") print_command("Sending release to sentry") ssh.exec!(web_sentry_create_release(git_sha)) do |_channel, _stream, data| print_command(data) end ssh.exec!(web_sentry_set_commits(git_sha)) do |_channel, _stream, data| print_command(data) end ssh.exec!(web_sentry_finalize(git_sha)) do |_channel, _stream, data| print_command(data) end print_command("Sending deployment to sentry") ssh.exec!(web_sentry_deploy(git_sha)) do |_channel, _stream, data| print_command(data) end end end end print_heading("Done.") print_cloudflare_warning end
# File lib/dogids/deploy/worker.rb, line 7 def deploy_worker ssh_address = get_config_url("production","worker") return if ssh_address == false print_heading("Deploying dogids-backgrounder") Net::SSH.start("#{ssh_address}", "dogids") do |ssh| print_command("Pulling latest from master") ssh.exec!(worker_git_pull_command) do |_channel, _stream, data| print_command(data) end print_heading("Building application") ssh.exec!(worker_build_command) do |_channel, _stream, data| print_command(data) end print_heading("Restarting") %w(clock web worker).each do |process| # First stop each process command = "sudo stop dogids-#{process}" ssh.exec!(command) do |_channel, _stream, data| print_command(data) end # Then start each process (restart doesn't work if not running) command = "sudo start dogids-#{process}" ssh.exec!(command) do |_channel, _stream, data| print_command(data) end end print_heading("Cleaning up") ssh.exec!(clean_up_command) do |_channel, _stream, data| print_command(data) end end print_heading("Done.") end
Run the development site @param [string] app_name
# File lib/dogids/run.rb, line 9 def dev(app_name = nil) system("cd ~/dogids-backend && yarn install && yarn run dev") end
Add the ablitity to print help for commands like:
`dogids help development:install`
This would print help for the method:
`development_install`
@param method [String]
# File lib/dogids/base.rb, line 14 def help(method = nil) if method.to_s.split(":").length >= 2 method = method.to_s.gsub(":", "_") elsif method.to_s == "run" method = "walk" end super end
# File lib/dogids/config.rb, line 59 def list dogids_config = set_config_location if dogids_config.any? then say("The following configurations are set: \n") dogids_config.each do |environment, locations| say("\n##### #{environment}") print_table(locations) end else say("No configuration values have been set. Here's the command list:") config end end
Add the ablitity to run commands like:
`dogids development:install`
This would run the defined method:
`development_install`
# File lib/dogids/base.rb, line 27 def method_missing(method, *args, &block) if method.to_s.split(":").length >= 2 self.send(method.to_s.gsub(":", "_"), *args) elsif method.to_s == "run" self.walk(*args) else super end end
Reload the specified environment TODO add environments @param [string] app_name
# File lib/dogids/reload.rb, line 10 def reload(app_name = nil) ssh_address = get_config_url("dev","dev") if yes?("-----> Reload development? [no]") reload_development_machine restart_lamp(ssh_address, "dogids") elsif yes?("-----> Restart LAMP stack? [no]") restart_lamp(ssh_address, "dogids") elsif yes?("-----> Restart LB and LAMP stack? [no]") restart_all elsif yes?("-----> Update Vagrant Box? (NOT RECOMMENDED) [no]") update_vagrant_box else say("Fine, I didn't want you to do anything anyway.") end end
Reloads development machine
# File lib/dogids/reload.rb, line 41 def reload_development_machine say("-----> Reloading the development machine...","\e[32m") system("cd ~/dogids-vagrant && vagrant reload") end
Restarts HAProxy, Apache, HHVM, and MySQL
# File lib/dogids/reload.rb, line 47 def restart_all dev_machines = get_config_url("dev") dev_machines.each do |key,dev_machine| ssh_address = get_config_url("dev",dev_machine) restart_lamp(ssh_address, "dogids") if dev_machine == dev restart_lb(ssh_address, "dogids") if dev_machine == lb end end
# File lib/dogids/reload.rb, line 56 def restart_lamp(ssh_address,user) Net::SSH.start(ssh_address, "dogids") do |ssh| lamp_restart_command = "sudo service apache2 restart && sudo service hhvm restart && sudo service mysql restart" ssh.exec!(lamp_restart_command) do |_channel, _stream, data| print_command(data) end end end
# File lib/dogids/reload.rb, line 65 def restart_lb(ssh_address,user) Net::SSH.start(ssh_address, "dogids") do |ssh| lb_restart_command = "sudo service haproxy restart" ssh.exec!(lb_restart_command) do |_channel, _stream, data| print_command(data) end end end
Set configuration files based on environment and location @param [string] environment @param [string] location
# File lib/dogids/config.rb, line 76 def set_config(environment,location) dogids_config = set_config_location environment_configuration = Hash.new if dogids_config["#{environment}"] environment_configuration = dogids_config["#{environment}"].to_hash end current_value = "" if dogids_config["#{environment}"] != nil && dogids_config["#{environment}"]["#{location}"] != nil then current_value = get_config_url(environment, location) say("Current #{location} URL/IP: #{current_value} \n","\e[32m") set_new = yes?("-------> Do you want to enter a new value?[no]") return if set_new != true end new_value = ask("Enter in a URL/IP for #{location}: ").strip if (new_value == "" || new_value == current_value )then say("Now you're just being silly. ") if (new_value == "") then say("In case it wasn't clear, you are supposed to set a value...") confirm_string = "REMOVE the old value" else say("You are literally about to change nothing") confirm_string = "literally do nothing" end confirm = yes?("-------> Do you want to #{confirm_string}?[no]") return if confirm != true end environment_configuration[location] = new_value dogids_config["#{environment}"] = environment_configuration dogids_config.save say("The new URL/IP for #{location}: #{new_value}","\e[32m") end
# File lib/dogids/config.rb, line 108 def set_default_configuration dogids_config = set_config_location dogids_config["dev"] = {"lb"=>"55.55.55.20","dev"=>"55.55.55.30"} dogids_config.save end
# File lib/dogids/ssh.rb, line 9 def ssh(vm_name = nil) case vm_name when "dev" ssh_dev(vm_name) when "staging" ssh_staging(vm_name) else puts "Development SSH Commands:" puts " dogids ssh:dev dev # SSH into local development VM" puts " dogids ssh:dev lb # SSH into local development LB" puts " " puts "Staging SSH Commands:" puts " dogids ssh:staging lb # SSH into staging LB" puts " dogids ssh:staging staging # SSH into staging Apache/PHP/MySQL VM" puts " " puts "Production SSH Commands:" puts " dogids ssh:production lb # SSH into production LB" puts " dogids ssh:production railgun # SSH into production railgun instance" puts " dogids ssh:production admin # SSH into VM for long running admin processes" puts " dogids ssh:production db # SSH into production MySQL/Redis VM" puts " dogids ssh:production web # SSH into production Apache/PHP VM" puts " dogids ssh:production worker # SSH into production Ruby/Sidekiq VM" puts " " end end
# File lib/dogids/ssh/development.rb, line 6 def ssh_dev(vm_name = nil) dev_machines = get_config_url("dev") if dev_machines.has_key?(vm_name) ssh_address = get_config_url("dev",vm_name) if vm_name == "lb" if yes?("----> Have you set up the dogIDs user for the development LB? [no]") puts "Running: dogids@#{ssh_address}" exec("ssh dogids@#{ssh_address}") else puts "Running: `cd ~/dogids-vagrant && vagrant ssh loadbalancer`" exec("cd ~/dogids-vagrant && vagrant ssh loadbalancer") end else puts "Running: `ssh -R 52698:localhost:52698 dogids@#{ssh_address}`" exec("ssh -R 52698:localhost:52698 dogids@#{ssh_address}") end else ssh end end
# File lib/dogids/ssh/production.rb, line 6 def ssh_production(vm_name = nil) production_machines = get_config_url("production") if production_machines.has_key?(vm_name) ssh_address = get_config_url("production",vm_name) if vm_name == "lb" || vm_name == "railgun" puts "Running: `ssh root@#{ssh_address}`" exec("ssh root@#{ssh_address}") else puts "Running: `ssh -R 52698:localhost:52698 dogids@#{ssh_address}`" exec("ssh -R 52698:localhost:52698 dogids@#{ssh_address}") end else ssh end end
# File lib/dogids/ssh/staging.rb, line 6 def ssh_staging(vm_name = nil) staging_machines = get_config_url("staging") if staging_machines.has_key?(vm_name) ssh_address = get_config_url("staging",vm_name) if vm_name == "lb" puts "Running: `ssh root@#{ssh_address}`" exec("ssh root@#{ssh_address}") else puts "Running: `ssh -R 52698:localhost:52698 dogids@#{ssh_address}`" exec("ssh -R 52698:localhost:52698 dogids@#{ssh_address}") end else ssh end end
# File lib/dogids/version.rb, line 10 def update command = "gem install dogids-cli" puts "Running #{command}" exec(command) end
Upgrade local vagrant box (default is ubuntu/trusty64)
# File lib/dogids/reload.rb, line 29 def update_vagrant_box say("-----> Updating the vagrant box...","\e[32m") system("cd ~/dogids-vagrant && vagrant box update") system("cd ~/dogids-vagrant && vagrant box list") if yes?("-----> Remove old boxes? (NOT RECOMMENDED) [no]") system("cd ~/dogids-vagrant && vagrant box remove --all") system("cd ~/dogids-vagrant && vagrant box add ubuntu/trusty64") end reload_development_machine end
# File lib/dogids/version.rb, line 17 def version gem_version = "v#{Dogids::VERSION}" # Grab the latest version of the RubyGem rubygems_json = open("https://rubygems.org/api/v1/gems/dogids-cli.json").read rubygems_version = "v#{JSON.parse(rubygems_json)['version'].strip}" upgrade_message = "" if gem_version != rubygems_version upgrade_message = " Run `dogids update` to install" end puts puts "Dogids CLI" puts " Installed: #{gem_version}" puts " Latest: #{rubygems_version}#{upgrade_message}" puts end
Private Instance Methods
# File lib/dogids/deploy/backend.rb, line 55 def backend_composer_commands commands = [] commands << "cd /home/dogids/apps/dogids-backend" commands << "composer install --no-dev --optimize-autoloader" commands.join(" && ") end
# File lib/dogids/deploy/backend.rb, line 48 def backend_deployment_commands commands = [] commands << "cd /home/dogids/apps/dogids-backend" commands << "php artisan deploy --progress" commands.join(" && ") end
# File lib/dogids/deploy/backend.rb, line 62 def backend_git_pull_command(branch = "master") commands = [] commands << "cd /home/dogids/apps/dogids-backend" commands << "git fetch origin #{branch}" commands << "git checkout #{branch}" commands << "git pull origin #{branch}" commands.join(" && ") end
# File lib/dogids/deploy/backend.rb, line 71 def backend_git_status_command commands = [] commands << "cd /home/dogids/apps/dogids-backend" commands << "git status -s" commands.join(" && ") end
# File lib/dogids/deploy/worker.rb, line 50 def clean_up_command commands = [] # Delete any SQL backups that failed to be deleted after uploading to S3 commands << "sudo find /var/lib/docker/ -type f -name '*.sql' -delete" # Delete any old docker containers to free up space commands << "sudo docker ps -a -f status=exited -q | xargs -r sudo docker rm -v" commands.join(" && ") end
Get configuration for environment and location @param [string] environment @param [string] location (Optional)
# File lib/dogids/base.rb, line 47 def get_config_url(environment, location = nil) config_file = set_config_location if location return config_file[environment][location] if config_file[environment].has_key?(location) elsif config_file.has_key?(environment) return config_file[environment] else say("URL/IP hasn't been set for #{location} \n") say("Please set this first by running: \n") say("dogids config:#{environment} #{location}","\e[32m") return false end end
# File lib/dogids/deploy/web.rb, line 73 def print_cloudflare_warning puts "" puts "================================================================================" puts " DON'T FORGET TO PURGE THE CLOUDFLARE CACHE!" puts " https://www.cloudflare.com/a/caching/dogids.com" puts "================================================================================" puts "" end
Print a message to the terminal about a command that's going to run. @param [String] command
# File lib/dogids/base.rb, line 69 def print_command(command) command.split("\n").each do |line| print_wrapped(line, indent: 7) end end
Print a heading to the terminal for commands that are going to be run. @param [String] heading
# File lib/dogids/base.rb, line 63 def print_heading(heading) puts "-----> #{heading}" end
Run a command with Bash after first printing the command to the terminal. @param [String] command
# File lib/dogids/base.rb, line 77 def run_command(command) print_command(command) `#{command}` end
Access local configuration file
# File lib/dogids/base.rb, line 83 def set_config_location config = UserConfig.new('.dogids') config['conf.yaml'] end
# File lib/dogids/deploy/staging.rb, line 65 def staging_git_pull_command(branch) commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sudo chown dogids:www-data -R blog/wp-content" commands << "sudo chown dogids:www-data -R resources" commands << "sudo chown dogids:www-data -R templates" commands << "git fetch origin #{branch}" commands << "git checkout #{branch}" commands << "git pull origin #{branch}" commands.join("&& ") end
# File lib/dogids/deploy/staging.rb, line 77 def staging_git_status_command commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "git status -s" commands.join("&& ") end
# File lib/dogids/deploy/web.rb, line 93 def web_git_get_sha commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "git log --pretty='%H' -n1 HEAD" commands.join("&& ") end
# File lib/dogids/deploy/web.rb, line 82 def web_git_pull_command commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sudo chown dogids:dogids -R .git" commands << "sudo chown dogids:www-data -R blog/wp-content" commands << "sudo chown dogids:www-data -R resources" commands << "sudo chown dogids:www-data -R templates" commands << "git pull origin master" commands.join("&& ") end
# File lib/dogids/deploy/web.rb, line 100 def web_git_status_command commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "git status -s" commands.join("&& ") end
SENTRY COMMANDS ###
# File lib/dogids/deploy/web.rb, line 132 def web_sentry_create_release(git_sha) commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sentry-cli releases new #{git_sha}" commands.join(" && ") end
# File lib/dogids/deploy/web.rb, line 153 def web_sentry_deploy(git_sha) commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sentry-cli releases deploys #{git_sha} new -e production" commands.join(" && ") end
# File lib/dogids/deploy/web.rb, line 146 def web_sentry_finalize(git_sha) commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sentry-cli releases finalize #{git_sha}" commands.join(" && ") end
# File lib/dogids/deploy/web.rb, line 139 def web_sentry_set_commits(git_sha) commands = [] commands << "cd /home/dogids/apps/dogids.com" commands << "sentry-cli releases set-commits #{git_sha} --auto" commands.join(" && ") end
# File lib/dogids/deploy/web.rb, line 107 def web_update_permissions_command commands = [] app_path = "/home/dogids/apps/dogids.com" writable_directories = [ "blog/wp-content", "feeds", "logs", "ls_file_cache", "resources", "reviews_cache", "temp", "templates", "uploaded" ] writable_directories.each do |directory| full_path = File.join(app_path, directory) commands << "sudo chown www-data:www-data -R #{full_path}" commands << "sudo chmod 775 -R #{full_path}" end commands.join("&& ") end
# File lib/dogids/deploy/worker.rb, line 59 def worker_build_command commands = [] commands << "cd /home/dogids/apps/dogids-backgrounder" commands << "git archive master | docker run -v /tmp/dogids-backgrounder-cache:/tmp/cache:rw -i -a stdin -a stderr -a stdout flynn/slugbuilder - > slug.tgz" commands.join("&& ") end
# File lib/dogids/deploy/worker.rb, line 66 def worker_git_pull_command commands = [] commands << "cd /home/dogids/apps/dogids-backgrounder" commands << "git pull origin master" commands.join("&& ") end