Welcome to the Web App DevOps Project repository! This project focuses on building a web application for managing and tracking orders within a business environment. It provides a user-friendly interface for viewing existing orders, adding new orders, and ensuring data validation for accuracy.
- Features
- Getting Started
- Technology Stack
- Infrastructure as Code (IaC) with Terraform for Azure Networking Services
- Provisioning an AKS Cluster with Terraform
- Deployment to Azure Kubernetes Service (AKS)
- Continuous Integration and Continuous Deployment (CI/CD) with Azure DevOps
- Testing and Validation
- Contributing
- License
-
Order List: View a comprehensive list of orders including details like date UUID, user ID, card number, store code, product code, product quantity, order date, and shipping date.
-
Pagination: Navigate through multiple pages of orders using built-in pagination controls.
-
Add New Order: Fill out a user-friendly form to add new orders to the system with necessary information.
-
Data Validation: Ensure data accuracy and completeness with required fields, date restrictions, and card number validation.
Before running the application or deploying infrastructure, ensure the following tools are installed:
- Python 3.x
- Flask 2.2.2
- PyODBC 4.0.39
- SQLAlchemy 2.0.21
- Werkzeug 2.2.3
- Terraform
- Azure CLI
- Clone Repository:
git clone https://github.com/maya-a-iuga/Web-App-DevOps-Project.git cd Web-App-DevOps-Project
python app.py
-
Backend: Flask handles routing, data processing, and interactions with the Azure SQL Database.
-
Frontend: Utilizes HTML, CSS, and JavaScript for an intuitive user interface.
-
Database: Azure SQL Database stores and manages order-related data securely.
This section details the provisioning of Azure networking services using Infrastructure as Code (IaC) with Terraform. The infrastructure setup includes creating an Azure Resource Group, a Virtual Network (VNet), subnets for the control plane and worker nodes, and a Network Security Group (NSG).
Ensure you have the following tools installed and configured:
- Terraform
- Azure CLI
- networking-module: Terraform configuration for Azure networking services.
- aks-cluster-module: Terraform configuration for AKS cluster provisioning.
git clone https://github.com/maya-a-iuga/Web-App-DevOps-Project.git cd Web-App-DevOps-Project/networking-module
terraform init
terraform apply
Follow the prompts to provision networking resources in Azure.
The networking module accepts input variables such as:
resource_group_name: Name of the Azure Resource Group. location: Azure region for resource deployment. vnet_address_space: Address space for the Virtual Network (VNet).
After provisioning, obtain output variables such as:
- vnet_id: ID of the Virtual Network (VNet).
- control_plane_subnet_id: ID of the control plane subnet.
- worker_node_subnet_id: ID of the worker node subnet.
- networking_resource_group_name: Name of the Azure Resource Group.
- aks_nsg_id: ID of the Network Security Group (NSG).
Provisioning an AKS Cluster with Terraform
This section demonstrates provisioning an Azure Kubernetes Service (AKS) cluster using Infrastructure as Code (IaC) with Terraform. It automates AKS cluster creation, integrates with previously provisioned networking resources, and configures necessary settings.
Ensure the following tools are installed and configured:
- Terraform
- Azure CLI
The project is structured into modules:
- networking-module: Handles Azure networking services.
- aks-cluster-module: Manages AKS cluster provisioning.
cd Web-App-DevOps-Project/aks-cluster-module
terraform init
terraform apply
Proceed with provisioning the AKS cluster, providing necessary input variables.
The AKS cluster module requires input variables such as:
- aks_cluster_name: Name of the AKS cluster.
- cluster_location: Azure region for AKS deployment.
- dns_prefix: DNS prefix for AKS cluster.
- kubernetes_version: Kubernetes version used.
- service_principal_client_id: Client ID for AKS service principal.
- service_principal_secret: Client Secret for AKS service principal.
- resource_group_name: Name of Azure Resource Group for networking.
- vnet_id: ID of the Virtual Network (VNet) used.
- control_plane_subnet_id: ID of the control plane subnet.
- worker_node_subnet_id: ID of the worker node subnet.
- Output Variables
After AKS cluster provisioning, retrieve output variables such as:
- aks_cluster_name: Name of the AKS cluster.
- aks_kubeconfig: Kubernetes configuration file for the AKS cluster.
This section focuses on deploying your application to Azure Kubernetes Service (AKS) using Kubernetes manifests for both Deployment and Service.
- Deployment Name: flask-app-deployment for managing the containerized application.
- Replicas: Configured for two replicas to ensure scalability and high availability.
- Labels: Uses app: flask-app for selector and pod template metadata, connecting pods with the application.
- Container: Specifies the Docker Hub container image for deployment on port 5000.
- Strategy: Implements Rolling Updates to maintain application availability during updates.
apiVersion: apps/v1 kind: Deployment metadata: name: flask-app-deployment spec: replicas: 2 selector: matchLabels: app: flask-app template: metadata: labels: app: flask-app spec: containers: - name: flask-app-container image: your-docker-hub-image:tag ports: - containerPort: 5000 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 Kubernetes Service Manifest
Service Name: flask-app-service for accessing the application within the AKS cluster. Port Mapping: Exposes port 80 on the AKS cluster to port 5000 on the application containers. Selector: Matches pods labeled with app: flask-app to route traffic to deployed instances.
apiVersion: v1 kind: Service metadata: name: flask-app-service spec: ports: - protocol: TCP port: 80 targetPort: 5000 selector: app: flask-app type: LoadBalancer
##Apply Deployment Manifest: kubectl apply -f application-manifest.yaml ##Apply Service Manifest: kubectl apply -f service-manifest.yaml Access your application using the public IP provided by the Load Balancer associated with the flask-app-service.
Continuous Integration and Continuous Deployment (CI/CD) with Azure DevOps
This section outlines setting up CI/CD pipelines using Azure DevOps to automate build, test, and deployment processes for your web application.
Navigate to Azure DevOps and create a new project for your application.
Connect Azure DevOps to your GitHub repository containing the application code.
Configure service connections to Azure resources (Azure Subscription, AKS Cluster).
Define build tasks to compile code, run tests, and build Docker images.
Configure release stages to deploy application artifacts to AKS.
Example azure-pipelines.yml for build pipeline:
trigger:
- main
pool: vmImage: 'ubuntu-latest'
steps:
-
task: UsePythonVersion@0 inputs: versionSpec: '3.x' addToPath: true
-
script: | pip install flask pyodbc SQLAlchemy werkzeug displayName: 'Install dependencies'
-
script: | pytest --junitxml=test-results/test-results.xml displayName: 'Run tests'
-
script: | docker build -t your-docker-hub-image:$(Build.BuildId) . docker push your-docker-hub-image:$(Build.BuildId) displayName: 'Build and push Docker image'
Release Pipeline Configuration
Configure release stages to deploy Docker images to AKS using Kubernetes manifests (application-manifest.yaml).
Define Environment: Create a new environment for AKS.
Add Stage: Use Kubernetes deployment task to apply manifests.
Approvals and Gates: Implement approval gates for deployment to production environments
-
Ensure thorough testing and validation of your application and infrastructure components:
-
Unit Testing: Test individual components and functions to verify correctness.
-
Integration Testing: Validate interactions between different parts of the application.
-
End-to-End Testing: Test the entire application flow from user interaction to database updates.
-
Performance Testing: Evaluate application performance under expected load conditions.
-
Security Testing: Assess application and infrastructure security measures.
Contributions are welcome! Please fork the repository and create a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.