Class: Heroku::Command::Fork
Overview
clone an existing app
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#index ⇒ Object
fork [NEWNAME].
Methods inherited from Base
#api, #app, #heroku, #initialize, namespace
Methods included from Helpers
#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #host_name, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty
Constructor Details
This class inherits a constructor from Heroku::Command::Base
Instance Method Details
#index ⇒ Object
fork [NEWNAME]
Fork an existing app – copy config vars and Heroku Postgres data, and re-provision add-ons to a new app. New app name should not be an existing app. The new app will be created as part of the forking process.
-s, –stack STACK # specify a stack for the new app –region REGION # specify a region
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/heroku/command/fork.rb', line 18 def index from = app to = shift_argument || "#{from}-#{(rand*1000).to_i}" from_info = api.get_app(from).body to_info = action("Creating fork #{to}") do api.post_app({ :name => to, :region => [:region] || from_info["region"], :stack => [:stack] || from_info["stack"], :tier => from_info["tier"] == "legacy" ? "production" : from_info["tier"] }).body end action("Copying slug") do job_location = cisaurus_client.copy_slug(from, to) loop do break if cisaurus_client.job_done?(job_location) sleep 1 end end from_config = api.get_config_vars(from).body from_addons = api.get_addons(from).body from_addons.each do |addon| print "Adding #{addon["name"]}... " begin to_addon = api.post_addon(to, addon["name"]).body puts "done" rescue Heroku::API::Errors::RequestFailed => ex puts "skipped (%s)" % json_decode(ex.response.body)["error"] rescue Heroku::API::Errors::NotFound puts "skipped (not found)" end if addon["name"] =~ /^heroku-postgresql:/ from_var_name = "#{addon["attachment_name"]}_URL" = to_addon["message"].match(/Attached as (\w+)_URL\n/)[1] if from_config[from_var_name] == from_config["DATABASE_URL"] from_config["DATABASE_URL"] = api.get_config_vars(to).body["#{}_URL"] end from_config.delete(from_var_name) plan = addon["name"].split(":").last unless %w(dev basic).include? plan wait_for_db to, to_addon end check_for_pgbackups! from check_for_pgbackups! to migrate_db addon, from, to_addon, to end end to_config = api.get_config_vars(to).body action("Copying config vars") do diff = from_config.inject({}) do |ax, (key, val)| ax[key] = val unless to_config[key] ax end api.put_config_vars to, diff end puts "Fork complete, view it at #{to_info['web_url']}" end |