Code Monkey home page Code Monkey logo

heroku-fork's Introduction

heroku-fork

Heroku CLI plugin to fork an existing app into a new app.

DEPRECATED: Heroku fork is deprecated as a core command. It will no longer be included in the CLI by default 2017-12-01. We recommend using review apps instead of fork if it will work for your use-case:. You may also fork the Github project to continue using this project as a CLI plugin. See Developing CLI Plugins for more information on developing plugins.

Installation

heroku plugins:install heroku-fork

Commands

heroku fork [NEWNAME]

Fork an existing app into a new one

--region specify a region

--skip-pg skip postgres databases

--from app to fork from

--to app to create

-a, --app undefined

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.

Example:

  $ heroku fork --from my-production-app --to my-development-app

Use heroku fork to copy an existing application, including add-ons, config vars, and Heroku Postgres data.

It is a common practice to maintain more than one environment for each application. For example, a staging and production environment for each app along with any number of ephemeral test environments for features in various stages of development. To ensure parity across applications, create new apps as forks from the production environment.

warning Forked applications are created in the account of the user executing heroku fork. The forking user will be the owner of the app and responsible for any application charges. For this reason, your account needs to be verified if the application you're forking contains paid resources.

Setup

You must have the Heroku CLI installed to use the features described here. Verify your CLI installation and update it to the latest version with heroku update.

Fork application

note For the purpose of this guide the originating app is called sourceapp and the new forked app is targetapp.

callout Any add-ons with paid plans on the old app will be provisioned with the same paid plans on the new app. Adjust your add-on plans as needed by up- or down-grading after forking.

Invoke heroku fork to create the target app, copy all Heroku Postgres data and config vars to the new app, and re-provision all add-ons with the same plan. Depending on the size of your database this process may take some time.

warning Only Heroku Postgres data is automatically copied to the new application. All other add-ons are simply re-provisioned and you will need to manually manage any requisite data export/import for these services.

callout Don't create targetapp yourself. heroku fork creates the target app as part of the forking process.

$ heroku fork --from sourceapp --to targetapp
Creating fork targetapp... done
Copying slug... done
Adding heroku-postgresql:dev... done
Creating database backup from sourcapp... .. done
Restoring database backup to targetapp... .. done
Copying config vars... done
Fork complete, view it at http://targetapp.herokuapp.com/

To fork an app to a non-default region, use the --region flag:

$ heroku fork --from sourceapp --to targetapp --region eu

Add-on failures

Some add-ons may fail provisioning if they're no longer available.

$ heroku fork --from sourceapp --to targetapp
Creating fork targetapp... done
Copying slug... ........ done
Adding airbrake:developer... done
Adding bonsai:test... skipped (not found)
...

If the add-ons can't be provisioned because the original plan no longer exists, upgrade the plan on the source app and retry the fork.

callout If you've already run heroku fork you will need to destroy the target app before retrying: heroku destroy -a targetapp.

$ heroku addons:upgrade bonsai:starter -a sourceapp
Upgrading to bonsai:starter on sourceapp... done, v207 (free)

Manual add-on configuration

There are some add-ons that require additional configuration after provisioning. There may be others beyond the add-ons listed so please review your app's add-ons for any that have manually entered configuration.

Heroku Postgres

All Heroku Postgres databases on your application will be copied from your sourceapp to your target app using pg:copy. Heroku Postgres fork is not used for this. If you have followers, this will result in duplicate copies that are not currently following your leader database.

For the larger size databases, this step will take a long time. You can skip this step by passing --skip-pg flag:

$ heroku fork --from sourceapp --to targetapp --skip-pg

With --skip-pg flag, Heroku Postgres databases will not be created on the target app. You can create it manually after heroku fork, or you could also use Heroku Postgres fork.

callout It is recommended to make sure if you have an expected Heroku Postgres setup with your target app. Please run heroku pg:info and/or heroku config command to make sure that everything has copied as you expected. If the copied database is not being the primary database (DATABASE_URL), use heroku pg:promote as described by the Heroku Postgres documentation to make it a primary database.

Custom domains

Since custom domains can only belong to a single app at a time, no custom domains are copied as part of the forking process. If you want to use custom domains in your new environment you will need to add them yourself as well as make the necessary DNS additions.

SSL

warning If your forked app doesn't need to use SSL, remove the add-on with heroku addons:destroy ssl to avoid unnecessary charges.

Although the forking process re-provisions the SSL Endpoint on targetapp it does not add any certs on your behalf. If your app uses custom domains with SSL you need to add new certs to your SSL endpoint instance on targetapp.

$ heroku certs:add server.crt server.key -a targetapp
Resolving trust chain... done
Adding SSL Endpoint to targetapp... done
example now served by tokyo-1234.herokussl.com

Add a new DNS CNAME record utilizing this new endpoint URL to serve requests via HTTPS.

Type Name Target
CNAME www tokyo-1234.herokussl.com

Scheduler

The Heroku Scheduler add-on requires that the job schedule be manually transferred. Open the scheduler dashboard for both sourceapp and targetapp side-by-side to view the diffs and manually copy the jobs.

$ heroku addons:open scheduler -a sourceapp
$ heroku addons:open scheduler -a targetapp

Deploy

Forking your application doesn't automatically create a new git remote in your current project. To deploy to targetapp you will need to establish the git remote yourself. Use heroku info to retrieve the Git URL of the new application and the set it manually.

$ heroku info -a targetapp
=== targetapp
...
Git URL:       [email protected]:targetapp.git
...

Add a git remote named forked representing the deploy URL for targetapp.

$ git remote add forked [email protected]:targetapp.git

Deploy to the new environment with:

$ git push forked master

If you wish to make the new app the default deployment target you can rename the git remotes.

$ git remote rename heroku old
$ git remote rename forked heroku

Forked app state

Forked apps are as close to the source app as possible. However, there are some differences.

Git repository

When forking, the slug currently running in the forked app is copied to the new app. The Git repository contents of old app are not copied to the Git repository of the new app.

Dynos

Forked applications are similar to new apps in that they are scaled to the default dyno formation consisting of a single web dyno and no worker or other dynos.

Scale your forked application's dynos to meet your needs:

$ heroku ps:scale web=1 worker=1 -a targetapp

Collaborators

No users from the source app are transferred over to the forked app. You need to add collaborators yourself.

$ heroku access:add [email protected] -a targetapp

Database followers

The forking process copies all databases present on sourceapp but does not retain any fork/follow relationships between them. Remove extraneous databases yourself and manually re-establish any forks or followers.

Labs features

Any enabled Heroku Labs features on sourceapp are not re-enabled on targetapp.

heroku-fork's People

Contributors

elbandito avatar fivetanley avatar jdx avatar karatecowboy avatar svc-scm avatar tt avatar xavriley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-fork's Issues

Heroku Fork should allow exclusion of add-ons

Should be able to avoid this :

$ heroku fork --from sourceapp --to targetapp
Forking sourceapp... done. Forked to targetapp
Setting buildpacks... done
Adding zerigo_dns:free to targetapp as ZERIGO_DNS... !
▸ Application error.

There was an error forking to targetapp.

In order to avoid being charged for any resources on targetapp, it is being destroyed...
Destroying app targetapp... done

Plugin won't install - npm error

Other plugins seem to be installing fine. This one is throwing an npm error. It looks like its trying to fetch from a nonexistent source...

Any ideas how to remedy this? Is it a problem on my end? I have tried deleting my entire .heroku folder and reinstalling...

$ heroku plugins:install heroku-fork
Installing plugin heroku-fork... ▸ npm ERR! fetch failed http://heroku-plugins-npm.herokuapp.com/ini/-/ini-1.3.4.tgz
▸ npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 404
▸ npm ERR! fetch failed http://heroku-plugins-npm.herokuapp.com/ini/-/ini-1.3.4.tgz
▸ npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 404
▸ npm ERR! fetch failed http://heroku-plugins-npm.herokuapp.com/ini/-/ini-1.3.4.tgz
▸ npm ERR! Darwin 14.1.0
▸ npm ERR! argv "/Users/andrewpalmer/.heroku/iojs-v2.2.1-darwin-x64/bin/iojs" "/Users/andrewpalmer/.heroku/iojs-v2.2.1-darwin-x64/lib/node_modules/npm/cli.js" "install" "heroku-fork"
▸ npm ERR! node v2.2.1
▸ npm ERR! npm v2.11.0

▸ npm ERR! fetch failed with status code 404
▸ npm ERR!
▸ npm ERR! If you need help, you may report this error at:
▸ npm ERR! https://github.com/npm/npm/issues

▸ npm ERR! Please include the following file with any support request:
▸ npm ERR! /Users/andrewpalmer/.heroku/npm-debug.log

--skip-pg will still copy DATABASE_URL

We had one customer who used --skip-pg flag and did manually create a forked database (since it's faster for lots of prod database), but since heroku fork command copied DATABASE_URL during the creation, creating a new database with forked app didn't have it promote as a primary database, so they were accidentally writing the things to the original application.

We should consider skipping copying DATABASE_URL when --skip-pg flag was passed to avoid the mess, or at lease we should super warn this ⚠️

Revert deprecation (please?)

Hi,

I would very much appreciate if you could revert the decision to deprecate heroku fork. I use it quite often to create test and staging apps. It would be very tedious and error prone to have to do this manually.

Using review apps as an alternative doesn't work for us since we don't use github.

So... please?

heroku fork doesn't recognize a primary database properly

When you have a database that is a primary but under the certain circumstances, heroku fork will create a new database within a new app, and do not make it as a primary database within the new app, which will end up copying the old app's DATABASE_URL to the new app. Now your forked app will be pointing to the original app's database, which can cause a nightmare.

Here is roughly what happens:

The reason of the old app's AMBER is not recognized as DATABASE_URL is a long story but it can certainly happen. One workaround that I can think of is to promote such database after the creation manually so that the new app will have a proper DATABASE_URL.
I don't think I'm explaining the issue well enough here, please ping me if you have nay questions. Also I'm happy to discuss about potential fixes.

When forking an application and copying pg data: `SyntaxError: Unexpected token <`

I ran: heroku fork --copy-pg-data --app base-app-name target-app-name

Adding addon sendgrid:starter to target-app-name... done
Adding addon heroku-postgresql:standard-0 to target-app-name... done
Transferring HEROKU_POSTGRESQL_BROWN to HEROKU_POSTGRESQL_ORANGE...
SyntaxError: Unexpected token <
    at Object.parse (native)
    at Request.parseBody (/Users/taylorbrown/.heroku/node_modules/heroku-fork/node_modules/heroku-client/lib/request.js:230:17)
    at Request.handleFailure (/Users/taylorbrown/.heroku/node_modules/heroku-fork/node_modules/heroku-client/lib/request.js:261:19)
    at ConcatStream.directResponse [as cb] (/Users/taylorbrown/.heroku/node_modules/heroku-fork/node_modules/heroku-client/lib/request.js:167:12)
    at ConcatStream.end (/Users/taylorbrown/.heroku/node_modules/heroku-fork/node_modules/heroku-client/node_modules/concat-stream/index.js:44:21)
    at IncomingMessage.onend (_stream_readable.js:489:10)
    at IncomingMessage.g (events.js:257:16)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:163:7)
    at _stream_readable.js:891:16

I echoed the buffer to see what it was trying to convert into an object, and got this:
about to parse buffer <Buffer 3c 68 31 3e 4e 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e>

I haven't translated this into ascii yet.

Suggestion: `heroku fork` should fail if an addon can't be provisioned

Right now, if an addon can't be provisioned, the full command doesn't fail:

00:01:27.862 Deploying build/d to our-app-name... done
00:01:31.992 Adding addon newrelic:wayne to our-app-name... done
00:01:36.095 Adding addon librato:development to our-app-name... done
00:01:36.372 Adding addon scheduler:standard to our-app-name... done
00:02:01.689 Adding addon heroku-postgresql:standard-0 to our-app-name... Skipped addon heroku-postgresql:standard-0
00:02:01.690  !    Could not communicate with vendor, please try again later
00:02:01.690 Copying config vars:
00:02:01.889   DATABASE_URL
00:02:01.890   RACK_ENV
...

In that case, having Postgresql provisioned is essential to the successful deploy of the app, and it of course fails later on in the process with a message about the app not having any databases. I think that if an individual addon can't be provisioned, this should fail so that it can be dealt with accordingly.

`No compatible version found: heroku-cli-util@'>=1.9.0 <2.0.0'`

Just got this error when trying to fork an application. Hopefully it's transient, and if it is, I'll come back and close. Wanted to make you aware as soon as I got it though.

Thanks!

0:17:56.837 + heroku fork --app X Y
00:17:58.696 Installing plugin heroku-fork... npm ERR! Linux 3.13.0-43-generic
00:17:58.717 npm ERR! argv "/home/vagrant/.heroku/iojs-v2.0.0-linux-x64/bin/iojs" "/home/vagrant/.heroku/iojs-v2.0.0-linux-x64/lib/node_modules/npm/cli.js" "install" "heroku-fork"
00:17:58.719 npm ERR! node v2.0.0
00:17:58.720 npm ERR! npm  v2.9.0
00:17:58.721 npm ERR! code ETARGET
00:17:58.721 
00:17:58.722 npm ERR! notarget No compatible version found: heroku-cli-util@'>=1.9.0 <2.0.0'
00:17:58.722 npm ERR! notarget Valid install targets:
00:17:58.723 npm ERR! notarget ["1.0.0","1.0.1","1.1.0","1.2.0","1.3.0","1.4.0","1.5.0","1.7.0","1.8.0","1.8.1"]
00:17:58.724 npm ERR! notarget 
00:17:58.724 npm ERR! notarget This is most likely not a problem with npm itself.
00:17:58.725 npm ERR! notarget In most cases you or one of your dependencies are requesting
00:17:58.726 npm ERR! notarget a package version that doesn't exist.
00:17:58.727 npm ERR! notarget 
00:17:58.727 npm ERR! notarget It was specified as a dependency of 'heroku-fork'
00:17:58.728 npm ERR! notarget 
00:17:58.728 
00:17:58.738 npm ERR! Please include the following file with any support request:
00:17:58.739 npm ERR!     /home/vagrant/.heroku/npm-debug.log
00:17:58.743 ERROR: exit status 1
00:17:59.070 Usage: heroku COMMAND [--app APP] [command-specific-options]
00:17:59.070 
00:17:59.070 Help topics, type "heroku help TOPIC" for more details:
00:17:59.071 
00:17:59.071   heroku version                       # print the version
00:17:59.071   heroku plugins                       # manage plugins
00:17:59.072   heroku update                        # update heroku-cli

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.