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,PUTandGET.
III - Obtain the source code and minimum requirements
- Install Vagrant from vagrantup.com
- 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
- Install git if you don't have it from git-scm.com or use
- Without git
- Go to the project directory with a terminal with
cd Devops_RESTFUL
IV - Run it on your machine with Vagrant
- Make sure to follow the steps of III - Obtain the source code and minimum requirements.
- Enter
vagrant up && vagrant ssh(this will install the box, docker etc.) - Enter
python /vagrant/server.py(in the virtual machine you just logged in) - Access the Python Flask server with your browser at localhost:5000. You can then make API calls with Swagger.
- You can also use the Chrome extension
Postmanfor example to send RESTful requests such asPOST. Install it here. - To update Swagger, refer to the information in the Github
staticdirectory.
V - Run it on Bluemix
- Make sure to follow the steps of III - Obtain the source code and minimum requirements although you don't need Vagrant.
- 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
- Enter
cf push PortfolioMgmt - 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
- Make sure to follow the steps of III - Obtain the source code and minimum requirements.
- Enter
vagrant up && vagrant ssh(this will install the box, docker etc.) - Enter
cd /vagrant(in the virtual machine you just logged in) - Enter
docker build -t docker-portfoliomgmt .- Don't forget the '.' !
- This builds a Docker image
docker-portfoliomgmtfrom theDockerfiledescription file. - You can list your local Docker images with
docker imagesto make sure it was created.
- Run the Docker image with
docker run --rm -p 5000:5000 --link redis docker-portfoliomgmt.- The
--rmoption automatically removes the container when it exits. - The
-p 5000:5000option publishes the container's 5000 port to the host. - The
--link redisoption links thedocker-portfoliomgmtto therediscontainer. - You can check the container is runnig with
docker ps -a.
- The
- 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
- Make sure you had followed the steps of A) Build and run it on Vagrant.
- 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_x64to install cf ic. cf ic login
- If not done already, create your namespace with
cf ic namespace set portfoliocontainer - Tag the Docker image with the remote container name
registry.ng.bluemix.net/portfoliocontainer/devops-hw2with the following command:docker tag docker-portfoliomgmt registry.ng.bluemix.net/portfoliocontainer/devops-hw2 - Push it with
docker push registry.ng.bluemix.net/portfoliocontainer/devops-hw2 - The Docker image should be on the Bluemix webpage. Click on it to create a container.
- 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
- If not on Vagrant, install pip and enter
pip install nose rednose coverage - Run the server tests and find the test coverage with
nosetests --rednose -v --with-coverage --cover-package=server - 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