Development

Setting up development workstation

All of the tools and technologies required to develop the application are avaialble free of charge and/or open sourced. The following setup instructions provide the links to where the tools and frameworks can be obtained.

The development workstation can be either Mac or Windows based. The team uses bothe, Apple Mac (Mac) and Windows workstation for developing the application. A Mac is preferred due to low friction in getting the prerequisites installed, availability of package manager for installing applications. The following instructions assume you have a Mac based workstation.

If you find yourself having to use sudo for running node, please see this page on how to resolve the issue http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo

Basic setup

  1. Install XCode and OS X Command Line Tools reference - https://developer.apple.com/xcode/downloads/

  2. Use the instructions from here https://github.com/18F/laptop to setup your developer box with the required software $ curl --remote-name https://raw.githubusercontent.com/18F/laptop/master/mac $ bash mac 2>&1 | tee ~/laptop.log

  3. Install mongo

$ brew install mongodb

reference - http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

  1. Install Sourcetree reference - https://www.sourcetreeapp.com/download/

  2. Install Virtual box

reference - https://www.virtualbox.org/wiki/Downloads

  1. Install boot2docker

reference - http://boot2docker.io/ Instructions - https://docs.docker.com/installation/mac/

  1. Install Textwrangler

reference - http://www.barebones.com/products/textwrangler/

  1. Install mongo gui client

reference - http://robomongo.org/

Install VirtualBox - https://www.virtualbox.org/wiki/Downloads

  1. Install ruby gems for working on documentation branch (gh-pages)
$ gem install jekyll
$ gem install kramdown
  1. Install grunt's command line interface
$ npm install -g grunt-cli

reference - https://github.com/cfpb/DOCter/blob/gh-pages/README.md

Optional - You can use sublime , TextWrangler or webstorm

If you haven't done so already, please create an account on github, dockerhub The project administrator should also add you to the project team on github, dockerhub, codeship, Jira, confluence and Amazon Cloud

Prerequisites for developing the application

It is assumed you have the editor, and development environment mentioned above already setup. If you are new to git please use the following resources to learn git and gitflow git gitflow github pages git branching

if you are using the command line to work with github, please use good judgement before merging and/or rebasing. Google or SO are your friends.

Repository branches

Please refer to Configuration Management - branches for details source code branching.

Use the develop branch for development, bug fixes and enhancement unless you are working on a feature or a patch in which case a branch will be created for you by the scrum master or configuration manager.

The master branch is used for releasing to production. Please do not check in code into this branch. Sprint testing and UAT is done on the test branch. Code is deployed daily to dev-integration branch. Please use the dev-integration branch to verify development is complete before closing the ticket.

To clone the develop branch of the repository on your desktop use the following command from Terminal

$ git clone -b develop https://github.com/GoswamiVijay/APIPrototype.git

To checkout the develop branch

$ cd APIPrototype
$ git checkout -b develop

Development workflow

The development workflow is pretty simple

  1. If you are working on a an issue, please make sure the the issue is recorded in Jira or Github issues list and is in the current sprint (if not, create the ticket/issue and and/or move it to current sprint)

  2. When closing the issue, reference the ticket number in the commit message, this allows for referencing the files that were modified when the issue was resolved.

  3. Only check in working code, use stash to switch work branches or suspend the current activity.

  4. Err on the side of more documentation. If there are configuration settings your are adding or dependecies or steps for building or testing the application, pleas record it in confluence and/or github pages

Building and running the application

  1. Start mongodb database using the following command in terminal window
$ sudo mongod
  1. Run the application In a new terminal window, navigate to the folder where you have cloned the repository. Run the following command to update the node modules used in the project
$ npm install

To run the application, run the nodemon command. nodemon will watch file changes and restart the application.

$ nodemon

Building and running docker images

The following instructions for building the docker images assume you have checked out the develop branch on your workstation and in terminal/command prompt in that folder. It's recommended but not required to create an account on docker hub so you can push your images to docker for others to test. If you are running boot2docker, it is assumed you are in the boot2docker shell (run boot2docker from Application folder on mac or windows). Substitute your account name with goswamivijay when building or running the images

Build mongo db image

Navigate to Docker-db folder (this is one level down from the application folder)

$ cd Docker-db

run the following command to build the image

$ docker build -t goswamivijay/apiprototype-db-develop .

Verify image exist by running the following command. You should see the image listed.

$ docker images

Build webapp images

Navigate to application folder (this is the folder where you checked out the repository)

$ docker build -t goswamivijay/apiprototype-web-develop .

Verify image exist by running

$ docker images

Navigate to Docker-nginx folder (this is one level down from the application folder)

$ cd Docker-nginx

run the following command to build the image

$ docker build -t goswamivijay/apiprototype-nginx-develop .

Verify image exist by running the following command. You should see the image listed.

$ docker images

Once you have the docker images you can run the images

Run database server

docker run -p 27017:27017 --name mymedlookupdb -d goswamivijay/apiprototype-db-develop

please note the container id that is displayed after you run the command, we will refer to it as the database container id.

Run web server

docker run -p 4000:4000 --name mymedlookupweb1 -d --link mymedlookupdb:mymedlookupdb goswamivijay/apiprototype-web-develop 

please note the container id that is displayed after you run the command, we will refer to it as the web container id.

Navigate to http://<server address>:4000/ in your browser

To find the <server address> if you are running boot2docker, enter the following command

$ boot2docker ip 

To stop the containers, run the following command

$ docker stop <web container id>
$ docker stop <db container id>

the web container id and the web container id are the ids that were diplayed when you used the run command. If you don't have the container id, you can query the conatiner id by running the following command

$ docker stop ps

The container id will be listed with the corresponding name of the container (mymedlookupweb1 for web and mymedlookupdb for database)

Refer to /APIPrototype/testing/ for details on running the docker images. Use the following references to learn more about running docker images locally.

https://docs.docker.com/userguide/ https://docs.docker.com/reference/builder/

Alternatively, you can use the docker-compose commands to build and run the images/containers

To build all the images, start boot2docker and navigate to the folder where you have cloned the repository. Run the following command to build all the images

$ docker-compose build

Run the containers

$ docker-compose up -d

To find the port numbers the containers are listening on

$ docker ps

You can now navigate to the nginx url or the web application containers to test the application. To find the ip address use the the following command.

$ boot2docker ip

The browser response might be slow by few seconds the first time you run the containers.

To remove the containers use the following command

$ docker-compose rm

Optional -- you can use the -v option to map your working folder to the container so changes in your folder are reflected in the application.