GithubHelp home page GithubHelp logo

balajidevopstesting's Introduction

Automating Deployment of Polls App using Django Framework and PostgresDB

Before you begin

  1. Ensure have Azure subscription and Azure DevOps organization setup
  2. Create Azure DevOps project for this Lab and clone this reposistory for source code
  3. Create Service principal which you will use to create Azure services

Instructions for Automating Deployments using Azure Pipeline

  1. We have Project code and Reposistory setup
  2. create Azure Pipleline to setup Azure services at first place
  3. Create Azure Pipeline to Build Python code and publish that to Appservice
  4. Work on updating Database as code by Create Polls Questions using pSql Scripts

Task 1 : Create First Pipeline for Azure Webapp and PostresDB Service Creation

servicecreation

Azure CLI commands for Azure CLI task

az group create --name $(RESOURCEGROUP) --location $(LOCATION)
az postgres server create --resource-group $(RESOURCEGROUP) --name $(POSTGRESSERVER)  --location $(LOCATION) --admin-user $(POSTGREDBADMIN) --admin-password $(POSTGREDBPASS) --sku-name B_Gen5_2
az postgres server firewall-rule create --resource-group $(RESOURCEGROUP) --server $(POSTGRESSERVER) --name AllowMyIP --start-ip-address $(ALLOWCLIENTIP)  --end-ip-address $(ALLOWCLIENTIP)
az postgres db create -g $(RESOURCEGROUP) -s $(POSTGRESSERVER) -n $(POSTGRESDB) 
az appservice plan create -g $(RESOURCEGROUP) -n $(APPPLAN) --is-linux --sku S1 -l $(LOCATION)
az webapp create -g $(RESOURCEGROUP) --plan $(APPPLAN) --name $(APPSERVICE) --runtime "PYTHON|3.8"
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBNAME=$(POSTGRESDB)
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBUSER=$(POSTGREDBADMIN)
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBPASS=$(POSTGREDBPASS)
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBHOST=$(POSTGRESSERVER)
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBPORT=5432

Task 2 : Create Second Pipeline to Build Python Code for Django and publish to Webapp

CodeBuildandPushImage

Azure CLI commands for Azure CLI task

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py migrate
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DISABLE_COLLECTSTATIC=true
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings POST_BUILD_COMMAND='python manage.py makemigrations && python manage.py migrate'
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DJANGO_ENV=production
az webapp config appsettings set -g $(RESOURCEGROUP) -n $(APPSERVICE) --settings DBPORT=5432

Task 3: Create Super User account Finally Third Pipeline to Push Code to Azure Webapp and MySQL Database

Use Azure CloudShell to SSH into Webapp and create superuser account

az webapp ssh -n  vijaydjangopostgresdevops -g vijaydjangopostgresdevops
python manage.py createsuperuser

Finaly browse your website <WebsiteName/admin>

djangoappadminportal

Check Login to Admin Website using Super User acccount Created in above step.

djangopollsquestions

Now Browse to Polls Website to submit your choice for Polls Questions

djangopollschoiceselect

djangopollschoiceenter

Task 4: Update your Polls Questions using Database as code SQL script with PostgresdbUpdate Release Pipeline

Summary

In this Lab we implemented

1. Azure Services for Webapp and PostgresDB

2. Build and Deploy Django App and update PostgresDB

3. Update Polls Questions using PostgresDB Database update using Automation workflow

4. Verified your Polls Questions appear while submitting your choice

balajidevopstesting's People

Contributors

jethanivijay avatar

Watchers

 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.