Skip to content

aliartiza75/flask-cicd-using-travis-heroku

Repository files navigation

Flask Application CI/CD using Heroku and Travic CI

Build Status

Overview

This repository contains code for get name api endpoints.

Install Packages

  1. Install python 3.7.

  2. Install pip3

sudo apt install python3-pip
  1. Install packages:
sudo pip3 install -r requirements.txt

Configure Application With Travis CI for CI pipeline.

A file .travisyml exists that contains configuration for the CI pipeline. Once travis ci is configured to use this application, the pipeline will be trigerred automatically.

Deploy Application Locally

1.1. Deploy application locally:

python3 app.py

NOTE In the app.py file the default port is 5000 because flask server uses it(not manditory). If you want to change the port just change it in the app.py file and run the comamnd given above.

If you use flask run command it will not use the port specified in the app.py file. So to change the port run the command given below:

flask run -p <5121>
  1. List of endpoints:
# endpoint to get the webpage
http://localhost:5000/


# endpoint to get the json response
http://localhost:5000/message?name=Irtiza

1.2. Application is deploy on heroku on this link

# endpoint to get the webpage
https://irtiza-get-name.herokuapp.com/

# endpoint to get the json response, either open in a browser or use cli
https://irtiza-get-name.herokuapp.com/message?name=Irtiza

Deploy Application on Heroku

  1. Create virtual env:
python3 -m venv venv/
  1. Activate the virtual environment:
source venv/bin/activate
  1. Install packages:
pip3 install -r requirements.txt
  1. Create a Procfile, it is already created. This file tells heroku to run a commands. The web command tells Heroku to start a web server for the application, using gunicorn. Application is called app.py, therfore app name has been set as app.

  2. Configure heroku repository:

heroku create flask-cicd-using-travis-heroku
  1. Heroku maintains the repository itself, to check it use the command given below:
cat .git/config

# you can see that a remote orgin named heroku has been added
  1. Push your code to the repository:
git push heroku master

Once the above command is executed successfully it will output the deployed application url.

Testing

  1. To the the linting:
./pycheck
  1. To test the code:
# Make sure server is running locally before executing the command below
python3 test_datetime_service.py

About

CI/CD Pipeline for Flask API using travis and heroku

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published