Giter Club home page Giter Club logo

ci-cdpipeline's Introduction

Python application test with Github Actions

Building CI-CDpipeline

Overview

This project demonstrates how to build GitHub repository from scratch and creating a scaffolding that will assist in performing both Continuous integration and Continuous Delivery. Some of the other actions include

  • Creating Github Actions along with a Makefile, requirement.txt file
  • Application code to perform initial lint, test and install cycle.
  • And lastly integrating the project with Azure Pipelines to enable Continuous Delivery to Azure App Service.

A short demo of the project is included here.

Architectural Diagram

Fine below flow of the project

Architectural Diagram screenshoot

Status

Python application test with Github Actions

Project Plan

Spreedsheet

In this spreedsheet, I have included a quarterly and yearly plan. also included is a estimated week by week deliverables with an estimated time of difficulity for each task.

Trello Board

In the trello board i have included a simple board based flow as below

  • To Do,
  • In Progress and
  • Done

CI: Set Up Azure Cloud Shell

Create the Cloud-Based Development Environment

I created a GitHub Repo then created a ssh-keys in my Azure Cloud Shell environment after which i clone the newly created repo into Azure Cloud Shell, screenshot below

Git clone

Creating the Makefile

  pip install --upgrade pip &&\
  	pip install -r requirements.txt
  
test:
  python -m pytest -vv test_hello.py

lint:
  	pylint --disable=R,C hello.py

all: install lint test

Creating the requirements.txt

pylint
pytest
Flask==2.0.3
pandas==0.24.2
scikit-learn==0.20.3
jinja2==3.0

Creating the Python Virtual Environment and source into it

python3 -m venv ~/.CI-CDpipeline
source ~/.CI-CDpipeline/bin/activate

Local test

(.CI-CDpipeline) lawal@Azure:~/CI-CDpipeline$ make all

Passed make all screenshoot

Testing it locally to check the prediction by running python app.py and running ./make_prediction.sh to see the prediction locally

Running python app.py screenshoot

Local prediction screenshot

CI: Configure GitHub Actions

This is to create a gitHub Actions to test the project upon change events in GitHub. This is a necessary step to performing Continuous Integration remotely.

Enable Github Actions and replace yml code with below:

name: Python application test with Github Actions

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.5
      uses: actions/setup-python@v1
      with:
        python-version: 3.5
    - name: Install dependencies
      run: |
        make install
    - name: Lint with pylint
      run: |
        make lint
    - name: Test with pytest
      run: |
        make test

Lastly i put the changes to GitHub and verify both lint and test

See screenshot below

Git Action screenshot

Continuous Delivery on Azure

Final step in the project is to set Continuous Delivery using Azure technologies. This will involve setting up Azure Pipelines to deploy the Flask starter code to Azure App Services.

Adding-flaskcode screenshot

Deploying to Azure App Services

Deploy the web app to azure using az webapp up -n

(.CI-CDpipeline) lawal@Azure:~/CI-CDpipeline$ az webapp up -n azurecicdpipeline

Deploying web app screenshot

Check if the app is up and running by opening the URL containing the webapp name provided in the previous step: https://azurecicdpipleline.azurewebsites.net/

Deployed webapp Output screenshot

Edit file 'make_predict_azure_app.sh' and replace '< yourappname >' with your webapp name (e.g. azurecicdpipeline).

Test the remote webapp:

Remove prediction screenshot

Logs of your running webapp via Azure Cloud shell

(.CI-CDpipeline) lawal@Azure:~/CI-CDpipeline$ az webapp log tail

Log tail screenshot

Performance validation of the webapp can be performed via a load test using locust. Replace '< yourappname >' in the provided configuration and call locust:

Using the parameters above locust will use 20 users with a spawn rate of 5 users per second and run for 20 seconds:

(.CI-CDpipeline) lawal@Azure:~/CI-CDpipeline$ locust -f locustfile.py --headless -u 20 -r 5 -t 20s

locustfile screenshot

Setting up CI/CD using Azure Pipelines

  • Goto Azure DevOps Organizations, create a new project called CICDAzuredev
  • Ensure you set up a new service connection via Azure Resource Manager and Pipeline
  • Goto organizations setting > new service connection (under pipeline) > Azure Resource Manager
  • Next, select Pipeline and create a new one
  • Create the GitHub Integration
  • Configure python to Linux Web app on Azure
  • Set up the continuous delivery workflow

First build screenshot

Final build screenshot

From now on every change to your code will trigger the CI/CD pipeline and update your webapp accordingly:

See below example of resent work after deployment

Example change screenshot

Final step

From Azure CLI do Git pull and Push so that everything will be up to date

Git pull and push screenshot

Enhancements

Future improvement include

  • Further improvement on the user interface of the application to make it user friendly.
  • Users can eastly use a click button for prediction

Demo Video

Video demonstration here

Final Status, just for check

Python application test with Github Actions

ci-cdpipeline's People

Contributors

miz-kas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.