Friday, 20 May 2016

ParseServer: managing Heroku test environment

Prerequisites

You have completed the setup of app in both
  1. local, i.e your own computer
  2. hosted on heroku, i.e this is the app that you deployed using "git push heroku master"
Refer to this heroku page for the details on creating staging, integration environments for the same application.  All the command below need to be ran in the heroku directory.  Heroku toolbelt is installed and you are logon using your heroku credential.

Objective

Setup a staging Heroku application.  A staging application is useful for testing new features in a production lookalike environment before releasing to production.

Checking your existing Git Remote

All applications on heroku are created with the default git remote as "heroku".  You can check the git remote using this command:
git remote -v
The command returns remotes as follows.  The heroku remote is the app that I deployed to the heroku.  The origin remote came from the git clone command when I clone from the parse-server-example git.
> origin    https://github.com/ParsePlatform/parse-server-example.git (fetch)
> origin    https://github.com/ParsePlatform/parse-server-example.git (push)
> heroku    https://git.heroku.com/elochallenge.git (fetch)
> heroku    https://git.heroku.com/elochallenge.git (push)
 

In this setup, I want to create elochallengestaging app from elochallenge app.  After the setup, I will have these 2 applications in Heroku.
  1. elochallenge
  2. elochallengestaging

Creating a Staging Environment

Run the following command to create a staging environment.
heroku fork --from elochallenge --to elochallengestaging
Add a new git remote using this command.
git remote add elochallengestaging https://git.heroku.com/elochallengestaging.git
Run this again to confirm that remote is created successfully.
 git remote -v

Setting Configuration Variables

After the new environment is created.  You will need to set the configuration variables.  Run these command line.
  1. heroku config:set DATABASE_URI=xxx --remote  elochallengestaging
  2. heroku config:set MASTER_KEY=xxx --remote  elochallengestaging
  3. heroku config:set SERVER_URL=xxx --remote  elochallengestaging
You can also update the configuration variable using Heroku web admin page.

Publish Changes to Staging and Production Environment

When you are ready to test your code in staging, run the following command to push to staging.
git push elochallengestaging master
After testing in the staging environment is completed, you may push your changes to production.
git push heroku master

Pulling latest code from ParseServer github

The git remote that you checked out the source code via "git clone" will be updated with new releases.  Once you are ready to get the latest release, run one of the git pull command below from your local git folder.

  • git pull https://github.com/ParsePlatform/parse-server-example.git
  • git pull origin

If you see conflicts, check for the filename with conflict and use editor to resolve the merge conflict manually.  For example, this is a conflict in package.json
remote: Counting objects: 11, done.
remote: Total 11 (delta 6), reused 6 (delta 6), pack-reused 5Unpacking objects: 100% (11/11), done.
From https://github.com/ParsePlatform/parse-server-example   5eea333..084fa07  master     -> origin/master * [new branch]      parse-server-version -> origin/parse-server-versionAuto-merging package.json
CONFLICT (content): Merge conflict in package.json
Auto-merging index.jsAutomatic merge failed; fix conflicts and then commit the result.

After resolving conflicts, run the npm to get the latest.
  • npm outdated : to list the outdated modules. Sample output as follows.
Package       Current  Wanted  Latest  Locationexpress        4.13.4  4.13.4  4.14.0  express parse-server   2.2.10  2.2.14  2.2.14  parse-server
  • npm update : to get the latest modules to local computer
  • npm list : to list all the modules installed locally
Once you are ready, do a git add, git commit and deploy it to the staging environment by using git push command.
  • git push elochallengestaging master

Setting Git Defaults

You can set the git push defaults to the staging environment.  Run the following command to list all the git config.
git config -l
Run this to setup the push default to elochallengestaging.
git config push.default elochallengestaging
After setting up the default, you can push to the elochallengestaging by running this command.
git push

No comments:

Post a Comment