module Heaven
Constants
- VERSION
Public Class Methods
List all available applications by name
Returns an array of applications you can ship
# File lib/heaven.rb, line 126 def self.all_available_applications (available_capistrano_applications | available_heroku_applications | available_constructable_applications).sort end
Find a deployable application by name
Needs to be defined in config/apps.yml
# File lib/heaven.rb, line 10 def self.app_for(name) Heaven::App.app_for(name) end
List the available receipts
Returns an array of available rackspace application names
# File lib/heaven.rb, line 105 def self.available_capistrano_applications Heaven::Targets::Capistrano.available_applications end
List the available constructable speakeasy applications
Returns an array of available constructable speakeasy application names
# File lib/heaven.rb, line 119 def self.available_constructable_applications Heaven::Targets::Speakeasy.all.map { |app| app.name.downcase } end
List the available heroku applications
Returns an array of available heroku application names
# File lib/heaven.rb, line 112 def self.available_heroku_applications Heaven::Targets::Heroku.deployments.map { |app| app.name } end
The installed gems base directory
We reference files inside of the gem after installation. This gives you easy access to files in local development and when installed via rubygems
# File lib/heaven.rb, line 38 def self.base File.expand_path("../", __FILE__) end
The current sha1 that the code is running under
Returns the short sha for the running process
# File lib/heaven.rb, line 23 def self.current_sha @current_sha ||= `cd #{root} && git rev-parse HEAD`[0..7] end
The user on the remote system that capistrano commands are issued as
If you're not running inside the VPN, your user probably isn't git
Returns the UNIX username of the deploy user on the remote system
# File lib/heaven.rb, line 47 def self.deploy_user @deploy_user ||= 'git' end
Set the deploy user capistrano commands are invoked as
If you're not running inside the VPN, your user probably isn't git. Use this method to set the user.
Returns the UNIX username of the deploy user on the remote system
# File lib/heaven.rb, line 57 def self.deploy_user=(username) @deploy_user = username end
Domain suffix based on environment
# File lib/heaven.rb, line 145 def self.domain_suffix(environment) case environment when "production","lab" ".rs.github.com" else ".stg.github.com" end end
Expand requested hosts to wildcard match for convenience
For subset deployments you can specify the hosts you want as comma delimited matches
- “fe”
-
> [“fe1.rs.github.com”, “fe2.rs.github.com”, “fe3.rs.github.com”,¶ ↑
"fe4.rs.github.com", "fe5.rs.github.com", "fe6.rs.github.com", "fe7.rs.github.com"]
- “fe1”,“fe2”
-
> [“fe1.rs.github.com”, “fe2.rs.github.com”]¶ ↑
- “fs”
-
> [“fs1a.rs.github.com”, “fs1b.rs.github.com”, “fs2a.rs.github.com”, “fs2b.rs.github.com”, … ]¶ ↑
- “fe1”,“fs2”
-
> [“fe1.rs.github.com”, “fs2a.rs.github.com”, “fs2b.rs.github.com”]¶ ↑
# File lib/heaven.rb, line 242 def self.expand_hosts(prefixes, environment) suffix = domain_suffix(environment) prefixes.map do |host_prefix| case host_prefix when /fe$/ hosts_for_fes(environment) when /fs$/ hosts_for_fses(environment) when /worker$/ hosts_for_workers(environment) when /fs\d+$/ "#{host_prefix}a#{suffix},#{host_prefix}b#{suffix}" when /staff$/ "#{host_prefix}1#{suffix}" when /\.aws\.github\.net$/ host_prefix else "#{host_prefix}#{suffix}" end end.join(",") end
Get all file servers in the given environment
Returns an array of full domain names for all file servers
# File lib/heaven.rb, line 166 def self.file_servers(environment) if environment == 'machine-room' return [ 'github-fs102a-cp1-prd.iad.github.net', 'github-fs102b-cp1-prd.iad.github.net' ] end hosts = [ ] suffix = domain_suffix(environment) 1.upto(host_info[environment]["fs"]) do |i| hosts << "fs#{i}a#{suffix}" hosts << "fs#{i}b#{suffix}" end filter_hosts(hosts) end
Given a list of hosts, exclude the current offline hosts
Returns a filtered list of full hostnames to deploy to
# File lib/heaven.rb, line 157 def self.filter_hosts(hosts) hosts.map do |host| offline_hosts.include?(host) ? nil : host end.compact end
Get all frontends in the given environment
Returns an array of full domain names for all frontends
# File lib/heaven.rb, line 185 def self.frontends(environment) return ['github-staff2-pe1-prd.aws.github.net'] if environment == 'garage' return ['github-staff3-pe1-prd.aws.github.net'] if environment == 'spider-skull-island' return ['github-staff4-cp1-prd.iad.github.net'] if environment == 'machine-room' hosts = [ ] prefix = environment == 'lab' ? 'staff' : 'fe' suffix = domain_suffix(environment) 1.upto(host_info[environment]["fe"]) do |i| hosts << "#{prefix}#{i}#{suffix}" end filter_hosts(hosts) end
The number of fe and fs machines we have for an environment
fe3.stg.github.com is available but excluded because its rebuild so often
A Hash based on environment keys that keeps count
# File lib/heaven.rb, line 66 def self.host_info @host_info ||= { 'staging' => { 'fe' => 2, 'fs' => 1, 'worker' => 0 }, 'production' => { 'fe' => 19, 'fs' => 37, 'worker' => 6 }, 'lab' => { 'fe' => 1, 'fs' => 0, 'worker' => 0 }, 'garage' => { 'fe' => 1, 'fs' => 0, 'worker' => 0 }, 'spider-skull-island' => { 'fe' => 1, 'fs' => 0, 'worker' => 0 }, 'machine-room' => { 'fe' => 1, 'fs' => 1, 'worker' => 0 }, } end
Get all frontends in the given environment
Returns a comma delimited string of of the full hostnames for all frontends
# File lib/heaven.rb, line 215 def self.hosts_for_fes(environment) frontends(environment).join(",") end
Get all file servers in the given environment
Returns a comma delimited string of of the full hostnames for all frontends
# File lib/heaven.rb, line 222 def self.hosts_for_fses(environment) file_servers(environment).join(",") end
Get all worker servers in the given environment
Returns a comma delimited string of of the full hostnames for all frontends
# File lib/heaven.rb, line 229 def self.hosts_for_workers(environment) workers(environment).join(",") end
Logger for sending output to syslog easily
# File lib/heaven.rb, line 16 def self.logger @logger ||= Syslog.open("heaven") end
List of full hostnames that are offline for now
Can be comma delimited for more than one host Only useful for fileserver and frontends
Returns an array of full hostnames
# File lib/heaven.rb, line 83 def self.offline_hosts @offline_hosts ||= %w(fe5.rs.github.com fe6.rs.github.com fe7.rs.github.com fe8.rs.github.com fe9.rs.github.com fe10.rs.github.com fe11.rs.github.com fe12.rs.github.com fe14.rs.github.com fe15.rs.github.com db2a.rs.github.com fe1.stg.github.com fs1a.rs.github.com fs1b.rs.github.com fs24a.rs.github.com fs24b.rs.github.com) end
Print the apps that you can deploy
Defaults to stdout
Returns nil
# File lib/heaven.rb, line 135 def self.print_available_applications(out = $stdout) out.puts "Available Applications:" out.puts "-" * 23 Heaven.all_available_applications.each do |app| out.printf "%023s\n", app end out.puts end
The root of the heaven project directory
Returns the absolute path to the heaven project on disk
# File lib/heaven.rb, line 30 def self.root @root ||= File.expand_path(File.join(File.dirname(__FILE__), "..")) end
Get all workers in the given environment
Returns an array of full domain names for all frontends
# File lib/heaven.rb, line 202 def self.workers(environment) hosts = [ ] suffix = domain_suffix(environment) 1.upto(host_info[environment]["worker"]) do |i| hosts << "worker#{i}#{suffix}" end hosts << "github-worker7-cp1-prd.iad.github.net" if environment == "production" filter_hosts(hosts) end