Devops Portfolio Management API

View on GitHub Open Swagger Download .zip Download .tar.gz Open Pydoc

Portfolio Management RESTful API

The project was developed for the DevOps course of New York University (CSCI-GA.3033-014).

I - What is it?

  • It is a RESTful API for a portfolio management.
  • It uses many technologies: Python, Flask, Vagrant, Swagger, Redis, Docker, ...
  • It can be run locally on a virtual machine with Vagrant or on Bluemix (IBM) remotely.
  • The Redis database is stored on IBM Bluemix

II - Access the API

  • Access the root URL of the API on Bluemix at https://portfoliomgmt.mybluemix.net (not valid anymore)
  • Access the root URL of the API on the Bluemix container at http://portfoliocontainer.mybluemix.net/ (not valid anymore)
  • Access it on your virtual Vagrant machine at localhost:5000
  • The root URL uses Swagger to show a descriptive list of all available RESTful calls such as POST, DELETE, PUT and GET.

III - Obtain the source code and minimum requirements

  1. Install Vagrant from vagrantup.com
  2. Download the project
    • Without git
      • Download the ZIP file by clicking here.
      • Extract the ZIP file.
    • With git (recommended)
      • Install git if you don't have it from git-scm.com or use apt-get install git.
      • Open a terminal and enter git clone https://github.com/qdm12/Devops_RESTful.git
  3. Go to the project directory with a terminal with cd Devops_RESTFUL

IV - Run it on your machine with Vagrant

  1. Make sure to follow the steps of III - Obtain the source code and minimum requirements.
  2. Enter vagrant up && vagrant ssh (this will install the box, docker etc.)
  3. Enter python /vagrant/server.py (in the virtual machine you just logged in)
  4. Access the Python Flask server with your browser at localhost:5000. You can then make API calls with Swagger.
  5. You can also use the Chrome extension Postman for example to send RESTful requests such as POST. Install it here.
  6. To update Swagger, refer to the information in the Github static directory.

V - Run it on Bluemix

  1. Make sure to follow the steps of III - Obtain the source code and minimum requirements although you don't need Vagrant.
  2. Login to Bluemix as follows:
    • cf login https://api.ng.bluemix.net -u username -o organization -s "Portfolio Management"
    • Enter the API endpoint as https://api.ng.bluemix.net
    • Enter your password
  3. Enter cf push PortfolioMgmt
  4. You can then access it at https://portfoliomgmt.mybluemix.net (not valid anymore)

VI - Run it on a Docker container

A) Build and run it on Vagrant

  1. Make sure to follow the steps of III - Obtain the source code and minimum requirements.
  2. Enter vagrant up && vagrant ssh (this will install the box, docker etc.)
  3. Enter cd /vagrant (in the virtual machine you just logged in)
  4. Enter docker build -t docker-portfoliomgmt .
    • Don't forget the '.' !
    • This builds a Docker image docker-portfoliomgmt from the Dockerfile description file.
    • You can list your local Docker images with docker images to make sure it was created.
  5. Run the Docker image with docker run --rm -p 5000:5000 --link redis docker-portfoliomgmt.
    • The --rm option automatically removes the container when it exits.
    • The -p 5000:5000 option publishes the container's 5000 port to the host.
    • The --link redis option links the docker-portfoliomgmt to the redis container.
    • You can check the container is runnig with docker ps -a.
  6. As for IV, you can access the Python Flask server with your browser at localhost:5000. You can then make API calls with Swagger.

B) Push and run it on Bluemix

  1. Make sure you had followed the steps of A) Build and run it on Vagrant.
  2. In Vagrant (vagrant up && vagrant ssh), login in the bluemix server as follows:
    • cf login https://api.ng.bluemix.net -u username -o organization -s "Portfolio Management"
    • Enter the API endpoint as https://api.ng.bluemix.net
    • Enter your password
    • TEMPORARY: Enter echo Y | cf install-plugin https://static-ice.ng.bluemix.net/ibm-containers-linux_x64 to install cf ic.
    • cf ic login
  3. If not done already, create your namespace with cf ic namespace set portfoliocontainer
  4. Tag the Docker image with the remote container name registry.ng.bluemix.net/portfoliocontainer/devops-hw2 with the following command: docker tag docker-portfoliomgmt registry.ng.bluemix.net/portfoliocontainer/devops-hw2
  5. Push it with docker push registry.ng.bluemix.net/portfoliocontainer/devops-hw2
  6. The Docker image should be on the Bluemix webpage. Click on it to create a container.
  7. Access the URL showing as Routes under Group details to access the running container. You can access it at http://portfoliocontainer.mybluemix.net

VII - Test driven development and PyUnit

  1. If not on Vagrant, install pip and enter pip install nose rednose coverage
  2. Run the server tests and find the test coverage with nosetests --rednose -v --with-coverage --cover-package=server
  3. Or you can use coverage run server_test.py && coverage report -m --include=server.py

For ongoing work, please refer to this page:

https://github.com/rofrano/nyu-homework-2

  • PART 1: Deploy the service in Docker Containers on Bluemix (submit URL of service on Bluemix)
  • PART 2: BDD and TDD Automated Testing (Good testing coverage required)
  • PART 3: Add an automated CI/CD DevOps Pipeline

To contribute

  • Send me an email at quentin.mcgaw @ gmail . com with your Github username and a reason.
  • To update the Swagger documentation, please refer to the readme.md in the static folder here