From 1500695b469db7771791ad1dff0494aefd01b21d Mon Sep 17 00:00:00 2001 From: ndm621 Date: Mon, 22 Jan 2024 21:12:27 +0000 Subject: [PATCH 01/26] Adds feature delivery-date --- app.py | 3 + templates/orders.html | 184 ++++++++++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 70 deletions(-) diff --git a/app.py b/app.py index 50f4e29d..aa9ed721 100644 --- a/app.py +++ b/app.py @@ -46,6 +46,7 @@ class Order(Base): product_quantity = Column('Product Quantity', Integer) order_date = Column('Order Date', DateTime) shipping_date = Column('Shipping Date', DateTime) + delivery_date = Column('Delivery Date', DateTime) # Add this line # define routes # route to display orders @@ -85,6 +86,7 @@ def add_order(): product_quantity = request.form.get('product_quantity') order_date = request.form.get('order_date') shipping_date = request.form.get('shipping_date') + delivery_date = request.form['delivery_date'] # Add this line # Create a session to interact with the database session = Session() @@ -99,6 +101,7 @@ def add_order(): product_quantity=product_quantity, order_date=order_date, shipping_date=shipping_date + delivery_date=delivery_date# Add this line ) # Add the new order to the session and commit to the database diff --git a/templates/orders.html b/templates/orders.html index 9372e2d0..8610e406 100644 --- a/templates/orders.html +++ b/templates/orders.html @@ -1,82 +1,126 @@ - + Order Management - - - + + +
-

Fictional Company Name

+

Fictional Company Name

- - + +
- +
-
-

Order List

- - - - - - - - - - - - - - - {% for order in orders %} - - - - - - - - - - - {% endfor %} - -
Date UUIDUser IDCard NumberStore CodeProduct CodeProduct QuantityOrder DateShipping Date
{{ order.date_uuid }}{{ order.user_id }}{{ order.card_number }}{{ order.store_code }}{{ order.product_code }}{{ order.product_quantity }}{{ order.order_date }}{{ order.shipping_date }}
- -
- - + From c7ddbce400f80c4d14a102a5364bc5a7816931d5 Mon Sep 17 00:00:00 2001 From: ndm621 Date: Mon, 22 Jan 2024 21:18:29 +0000 Subject: [PATCH 02/26] Revert "Adds feature delivery-date" This reverts commit 1500695b469db7771791ad1dff0494aefd01b21d. --- app.py | 3 - templates/orders.html | 184 ++++++++++++++++-------------------------- 2 files changed, 70 insertions(+), 117 deletions(-) diff --git a/app.py b/app.py index aa9ed721..50f4e29d 100644 --- a/app.py +++ b/app.py @@ -46,7 +46,6 @@ class Order(Base): product_quantity = Column('Product Quantity', Integer) order_date = Column('Order Date', DateTime) shipping_date = Column('Shipping Date', DateTime) - delivery_date = Column('Delivery Date', DateTime) # Add this line # define routes # route to display orders @@ -86,7 +85,6 @@ def add_order(): product_quantity = request.form.get('product_quantity') order_date = request.form.get('order_date') shipping_date = request.form.get('shipping_date') - delivery_date = request.form['delivery_date'] # Add this line # Create a session to interact with the database session = Session() @@ -101,7 +99,6 @@ def add_order(): product_quantity=product_quantity, order_date=order_date, shipping_date=shipping_date - delivery_date=delivery_date# Add this line ) # Add the new order to the session and commit to the database diff --git a/templates/orders.html b/templates/orders.html index 8610e406..9372e2d0 100644 --- a/templates/orders.html +++ b/templates/orders.html @@ -1,126 +1,82 @@ - + Order Management - - - + + +
-

Fictional Company Name

+

Fictional Company Name

- - + +
- +
-
-

Order List

- - - - - - - - - - - - - - - - - {% for order in orders %} - - - - - - - - - - - - - {% endfor %} - -
Date UUIDUser IDCard NumberStore CodeProduct CodeProduct QuantityOrder DateShipping DateDelivery Date
{{ order.date_uuid }}{{ order.user_id }}{{ order.card_number }}{{ order.store_code }}{{ order.product_code }}{{ order.product_quantity }}{{ order.order_date }}{{ order.shipping_date }}{{ order.delivery_date }}
- -
- + From 03181e8e4c121a33888044fbd1e143ef2a5687ec Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sat, 10 Feb 2024 12:38:57 +0000 Subject: [PATCH 03/26] Set up CI with Azure Pipelines Initial setup of the pipeline [skip ci] --- azure-pipelines.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..f53e97b6 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,19 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +pool: + vmImage: ubuntu-latest + +steps: +- script: echo Hello, world! + displayName: 'Run a one-line script' + +- script: | + echo Add other tasks to build, test, and deploy your project. + echo See https://aka.ms/yaml + displayName: 'Run a multi-line script' From e9f2f89a918ab8a66c4427d34676c82033b2a660 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sat, 10 Feb 2024 13:38:45 +0000 Subject: [PATCH 04/26] Update azure-pipelines.yml for Azure Pipelines Pipeline updates for Docker web-app-img --- azure-pipelines.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f53e97b6..93c47455 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,10 +10,10 @@ pool: vmImage: ubuntu-latest steps: -- script: echo Hello, world! - displayName: 'Run a one-line script' - -- script: | - echo Add other tasks to build, test, and deploy your project. - echo See https://aka.ms/yaml - displayName: 'Run a multi-line script' +- task: Docker@2 + inputs: + containerRegistry: 'Docker Hub' + repository: 'ndm621/web-app-img' + command: 'buildAndPush' + Dockerfile: '**/Dockerfile' + tags: 'latest' From 8554868b6f85ce7c346b4232ce58599e0a46755a Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sat, 10 Feb 2024 17:34:09 +0000 Subject: [PATCH 05/26] Update azure-pipelines.yml for Azure Pipelines added parallel:1 to the pool section --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 93c47455..ad475e85 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,6 +8,7 @@ trigger: pool: vmImage: ubuntu-latest + parallel: 1 steps: - task: Docker@2 From 0cc6608e4feb6f9bb7aec78f230da7424d2c23bc Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sun, 11 Feb 2024 14:36:23 +0000 Subject: [PATCH 06/26] Update azure-pipelines.yml for Azure Pipelines removes the line parallel = 1 --- azure-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ad475e85..93c47455 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,7 +8,6 @@ trigger: pool: vmImage: ubuntu-latest - parallel: 1 steps: - task: Docker@2 From 5d3d575bd3e2209266b49ddfcf706e87f3211e4e Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sun, 11 Feb 2024 14:39:10 +0000 Subject: [PATCH 07/26] Update azure-pipelines.yml for Azure Pipelines adds parallel: 1 --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 93c47455..ad475e85 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,6 +8,7 @@ trigger: pool: vmImage: ubuntu-latest + parallel: 1 steps: - task: Docker@2 From 520623147197ab281026adebe59a94c0c7dbda7f Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Sun, 11 Feb 2024 15:08:18 +0000 Subject: [PATCH 08/26] Update azure-pipelines.yml for Azure Pipelines corrects spelling mistake --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ad475e85..0f59b87c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -16,5 +16,5 @@ steps: containerRegistry: 'Docker Hub' repository: 'ndm621/web-app-img' command: 'buildAndPush' - Dockerfile: '**/Dockerfile' + Dockerfile: '**/dockerfile' tags: 'latest' From eda3a89912ff46c6be6b62c97481a9d813427be3 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Mon, 12 Feb 2024 00:46:47 +0000 Subject: [PATCH 09/26] Update azure-pipelines.yml for Azure Pipelines corrects spellings for Dockerfile --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0f59b87c..ad475e85 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -16,5 +16,5 @@ steps: containerRegistry: 'Docker Hub' repository: 'ndm621/web-app-img' command: 'buildAndPush' - Dockerfile: '**/dockerfile' + Dockerfile: '**/Dockerfile' tags: 'latest' From 13f9d58db0df08384d51aa61142be6bbc48a624f Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Mon, 12 Feb 2024 01:47:56 +0000 Subject: [PATCH 10/26] Create Dockerfile Dockerfile added for the Azure DevOps pipeline to work --- Dockerfile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..24b543b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Step 1 - Use an official Python runtime as a parent image. You can use `python:3.8-slim`. +FROM python:3.8-slim +# Step 2 - Set the working directory in the container +WORKDIR /app +# Step 3 Copy the application files in the container +COPY . ./app +# Install system dependencies and ODBC driver +RUN apt-get update && apt-get install -y \ + unixodbc unixodbc-dev odbcinst odbcinst1debian2 libpq-dev gcc && \ + apt-get install -y gnupg && \ + apt-get install -y wget && \ + wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ + wget -qO- https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \ + apt-get update && \ + ACCEPT_EULA=Y apt-get install -y msodbcsql18 && \ + apt-get purge -y --auto-remove wget && \ + apt-get clean + +# Install pip and setuptools +RUN pip install --upgrade pip setuptools + +# Step 4 - Install Python packages specified in requirements.txt +RUN pip install --trusted-host pypi.python.org -r ./app/requirements.txt +# Step 5 - Expose port +EXPOSE 5000 +# Step 6 - Define Startup Command +# CMD [ "flask", "run","--host","127.0.0.1","--port","5000"] +entrypoint ["python", "./app/app.py"] From 98bbac51b5febbb07fbed30fbb137297e931923d Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:07:53 +0000 Subject: [PATCH 11/26] Create main.tf Adds main.tf --- aka-terraform/main.tf | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 aka-terraform/main.tf diff --git a/aka-terraform/main.tf b/aka-terraform/main.tf new file mode 100644 index 00000000..dc2f8c45 --- /dev/null +++ b/aka-terraform/main.tf @@ -0,0 +1,45 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "=3.0.0" + } + } +} + +provider "azurerm" { + features {} + client_id = var.client_id + client_secret = var.client_secret + subscription_id = "07bd18f6-a3df-4eda-91a2-e133a16dbf5c" + tenant_id = "47d4542c-f112-47f4-92c7-a838d8a5e8ef" +} + +module "networking" { + source = "./networking-module" + + # Input variables for the networking module + resource_group_name = "networking-rg" + location = "UK South" + vnet_address_space = ["10.0.0.0/16"] + + # Define more input variables as needed... +} + +module "aks_cluster" { + source = "./aks-cluster-module" + + # Input variables for the AKS cluster module + cluster_name = "terraform-aks-cluster" + cluster_location = "UK South" + dns_prefix = "myaks-project" + kubernetes_version = "1.26.6" # Adjust the version as needed + service_principal_client_id = var.client_id + service_principal_client_secret = var.client_secret + + # Input variables referencing outputs from the networking module + resource_group_name = module.networking.resource_group_name + vnet_id = module.networking.vnet_id + control_plane_subnet_id = module.networking.control_plane_subnet_id + worker_node_subnet_id = module.networking.worker_node_subnet_id +} From c1b42ce337a0b4c585adac0794c2ad28413965ed Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:09:47 +0000 Subject: [PATCH 12/26] Add files via upload --- aka-terraform/application-manifest.yaml | 40 +++++++++++++++++++++++++ aka-terraform/variables.tf | 13 ++++++++ 2 files changed, 53 insertions(+) create mode 100644 aka-terraform/application-manifest.yaml create mode 100644 aka-terraform/variables.tf diff --git a/aka-terraform/application-manifest.yaml b/aka-terraform/application-manifest.yaml new file mode 100644 index 00000000..7cbf5271 --- /dev/null +++ b/aka-terraform/application-manifest.yaml @@ -0,0 +1,40 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-app-deployment + labels: + app: flask-app +spec: + replicas: 2 + selector: + matchLabels: + app: flask-app + template: + metadata: + labels: + app: flask-app + spec: + containers: + - name: flask-app + image: ndm621/web-app-img:v1.0 + ports: + - containerPort: 5000 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + +--- +apiVersion: v1 +kind: Service +metadata: + name: flask-app-service +spec: + selector: + app: flask-app + type: ClusterIP + ports: + - protocol: TCP + port: 80 + targetPort: 5000 diff --git a/aka-terraform/variables.tf b/aka-terraform/variables.tf new file mode 100644 index 00000000..69e2ec35 --- /dev/null +++ b/aka-terraform/variables.tf @@ -0,0 +1,13 @@ +# variables.tf + +variable "client_id" { + description = "Access key for the provider" + type = string + sensitive = true +} + +variable "client_secret" { + description = "Secret key for the provider" + type = string + sensitive = true +} \ No newline at end of file From 03cbe984d3e00ad71691c0388224862eb9e37af8 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:11:00 +0000 Subject: [PATCH 13/26] Create main.tf --- aka-terraform/aks-cluster-module/main.tf | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 aka-terraform/aks-cluster-module/main.tf diff --git a/aka-terraform/aks-cluster-module/main.tf b/aka-terraform/aks-cluster-module/main.tf new file mode 100644 index 00000000..70034dc6 --- /dev/null +++ b/aka-terraform/aks-cluster-module/main.tf @@ -0,0 +1,23 @@ +# aks-cluster-module/main.tf +# Create the AKS cluster +resource "azurerm_kubernetes_cluster" "aks_cluster" { + name = var.cluster_name + location = var.cluster_location + resource_group_name = var.resource_group_name + dns_prefix = var.dns_prefix + kubernetes_version = var.kubernetes_version + + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" + enable_auto_scaling = true + min_count = 1 + max_count = 3 + } + + service_principal { + client_id = var.service_principal_client_id + client_secret = var.service_principal_client_secret + } +} From 3c6b317c8692b996947282541933a48b2517d6ce Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:11:37 +0000 Subject: [PATCH 14/26] Add files via upload --- aka-terraform/aks-cluster-module/outputs.tf | 14 +++++ aka-terraform/aks-cluster-module/variables.tf | 59 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 aka-terraform/aks-cluster-module/outputs.tf create mode 100644 aka-terraform/aks-cluster-module/variables.tf diff --git a/aka-terraform/aks-cluster-module/outputs.tf b/aka-terraform/aks-cluster-module/outputs.tf new file mode 100644 index 00000000..7842343c --- /dev/null +++ b/aka-terraform/aks-cluster-module/outputs.tf @@ -0,0 +1,14 @@ +output "cluster_name" { + description = "Name of the AKS cluster." + value = azurerm_kubernetes_cluster.aks_cluster.name +} + +output "aks_cluster_id" { + description = "ID of the AKS cluster." + value = azurerm_kubernetes_cluster.aks_cluster.id +} + +output "aks_kubeconfig" { + description = "Kubeconfig file for accessing the AKS cluster." + value = azurerm_kubernetes_cluster.aks_cluster.kube_config_raw +} \ No newline at end of file diff --git a/aka-terraform/aks-cluster-module/variables.tf b/aka-terraform/aks-cluster-module/variables.tf new file mode 100644 index 00000000..0baf5b53 --- /dev/null +++ b/aka-terraform/aks-cluster-module/variables.tf @@ -0,0 +1,59 @@ +variable "cluster_name" { + description = "The name of the AKS cluster" + type = string + default = "aks-cluster" +} + +variable "cluster_location" { + description = "The Azure Region of the AKS cluster" + type = string + default = "UK South" +} + +variable "dns_prefix" { + description = "DNS prefix of the AKS cluster" + type = string + default = "value" +} + +variable "kubernetes_version" { + description = "Kubernetes version of the AKS cluster" + type = string + default = "value" +} + +variable "service_principal_client_id" { + description = "Client ID of the service principal of the AKS cluster" + type = string + default = "value" +} + +variable "service_principal_client_secret" { + description = "Client Secret of the service principal" + type = string + default = "value" +} + +variable "resource_group_name" { + description = "Resource Group Name in Azure" + type = string + default = "aks-resources" +} + +variable "vnet_id" { + description = "ID of the previously created VNet" + type = string + default = "aks-vnet" +} + +variable "control_plane_subnet_id" { + description = "ID of the control plane subnet within the VNet" + type = string + default = "control-plane-subnet" +} + +variable "worker_node_subnet_id" { + description = "ID of the worker node subnet within the VNet" + type = string + default = "worker-node-subnet" +} \ No newline at end of file From 838ceffea9b7c65cb32b2f20b2da78c6a4751e02 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:13:46 +0000 Subject: [PATCH 15/26] Create main.tf --- aka-terraform/networking-module/main.tf | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 aka-terraform/networking-module/main.tf diff --git a/aka-terraform/networking-module/main.tf b/aka-terraform/networking-module/main.tf new file mode 100644 index 00000000..565addeb --- /dev/null +++ b/aka-terraform/networking-module/main.tf @@ -0,0 +1,75 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "=3.0.0" + } + } +} + +provider "azurerm" { + features {} +} + +# 1. Define the Azure resource group resource +resource "azurerm_resource_group" "aks" { + name = var.resource_group_name + location = "UK South" +} + +# 2. Define Virtual Network (VNet) +resource "azurerm_virtual_network" "aks_vnet" { + name = "aks-vnet" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.aks.location + resource_group_name = azurerm_resource_group.aks.name + depends_on = [ azurerm_resource_group.aks ] +} + +resource "azurerm_subnet" "control_plane_subnet" { + name = "control-plane-subnet" + resource_group_name = azurerm_resource_group.aks.name + virtual_network_name = azurerm_virtual_network.aks_vnet.name + address_prefixes = ["10.0.1.0/24"] +} + +resource "azurerm_subnet" "worker_node_subnet" { + name = "worker-node-subnet" + resource_group_name = azurerm_resource_group.aks.name + virtual_network_name = azurerm_virtual_network.aks_vnet.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_network_security_group" "aks_nsg" { + name = "aks-nsg" + location = azurerm_resource_group.aks.location + resource_group_name = azurerm_resource_group.aks.name +} + +resource "azurerm_network_security_rule" "kube_apiserver_rule" { + name = "kube-apiserver" + resource_group_name = azurerm_resource_group.aks.name + network_security_group_name = azurerm_network_security_group.aks_nsg.name + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "6443" + source_address_prefix = "*" + destination_address_prefix = "*" +} + +resource "azurerm_network_security_rule" "ssh_rule" { + name = "ssh " + resource_group_name = azurerm_resource_group.aks.name + network_security_group_name = azurerm_network_security_group.aks_nsg.name + priority = 1002 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" +} From f98ab81eaab44ee2358c65acacca1b1e68efbbfa Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 13 Feb 2024 16:14:26 +0000 Subject: [PATCH 16/26] Add files via upload --- aka-terraform/networking-module/outputs.tf | 27 ++++++++++++++++++++ aka-terraform/networking-module/variables.tf | 17 ++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 aka-terraform/networking-module/outputs.tf create mode 100644 aka-terraform/networking-module/variables.tf diff --git a/aka-terraform/networking-module/outputs.tf b/aka-terraform/networking-module/outputs.tf new file mode 100644 index 00000000..48736e4b --- /dev/null +++ b/aka-terraform/networking-module/outputs.tf @@ -0,0 +1,27 @@ +# networking-module/outputs.tf + +output "vnet_id" { + description = "ID of the Virtual Network (VNet)." + value = azurerm_virtual_network.aks_vnet.id +} + +output "control_plane_subnet_id" { + description = "ID of the control plane subnet." + value = azurerm_subnet.control_plane_subnet.id +} + +output "worker_node_subnet_id" { + description = "ID of the worker node subnet." + value = azurerm_subnet.worker_node_subnet.id +} + +output "resource_group_name" { + description = "Name of the Azure Resource Group for networking resources." + value = azurerm_resource_group.aks.name +} + +# Define more output variables as needed... +output "aks_nsg_id" { + description = "ID of the Network Security Group (NSG) for AKS." + value = azurerm_network_security_group.aks_nsg.id +} \ No newline at end of file diff --git a/aka-terraform/networking-module/variables.tf b/aka-terraform/networking-module/variables.tf new file mode 100644 index 00000000..c1c1d49a --- /dev/null +++ b/aka-terraform/networking-module/variables.tf @@ -0,0 +1,17 @@ +variable "resource_group_name" { + description = "Resource Group Name in Azure" + type = string + default = "aks-resources" +} + +variable "location" { + description = "location of account" + type = string + default = "UK South" +} + +variable "vnet_address_space" { + description = "Address space for the Virtual Network" + type = list(string) + default = ["10.0.0.0/16"] +} \ No newline at end of file From 2a99bd5988bf55be18a06c565a99a6cec1e2bd5b Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Wed, 14 Feb 2024 08:51:56 +0000 Subject: [PATCH 17/26] Update variables.tf --- aka-terraform/aks-cluster-module/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aka-terraform/aks-cluster-module/variables.tf b/aka-terraform/aks-cluster-module/variables.tf index 0baf5b53..d349f6e3 100644 --- a/aka-terraform/aks-cluster-module/variables.tf +++ b/aka-terraform/aks-cluster-module/variables.tf @@ -56,4 +56,4 @@ variable "worker_node_subnet_id" { description = "ID of the worker node subnet within the VNet" type = string default = "worker-node-subnet" -} \ No newline at end of file +} From a6057d8b08b839c1edabcb9cbf174348bf15d7c5 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Wed, 14 Feb 2024 08:53:11 +0000 Subject: [PATCH 18/26] Update outputs.tf --- aka-terraform/aks-cluster-module/outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aka-terraform/aks-cluster-module/outputs.tf b/aka-terraform/aks-cluster-module/outputs.tf index 7842343c..edf63788 100644 --- a/aka-terraform/aks-cluster-module/outputs.tf +++ b/aka-terraform/aks-cluster-module/outputs.tf @@ -11,4 +11,4 @@ output "aks_cluster_id" { output "aks_kubeconfig" { description = "Kubeconfig file for accessing the AKS cluster." value = azurerm_kubernetes_cluster.aks_cluster.kube_config_raw -} \ No newline at end of file +} From 836bb1426fb43a09e86f2ff957672931142fab12 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Wed, 14 Feb 2024 09:30:03 +0000 Subject: [PATCH 19/26] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ad475e85..f7984cfa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -18,3 +18,12 @@ steps: command: 'buildAndPush' Dockerfile: '**/Dockerfile' tags: 'latest' +- task: KubernetesManifest@1 + inputs: + action: 'deploy' + connectionType: 'azureResourceManager' + azureSubscriptionConnection: 'webapp' + azureResourceGroup: 'networking-rg' + kubernetesCluster: 'terraform-aks-cluster' + useClusterAdmin: true + manifests: 'application-manifest.yaml' \ No newline at end of file From 281908b92bf7831608427d264d5a6ba1c03fc003 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Wed, 14 Feb 2024 09:42:35 +0000 Subject: [PATCH 20/26] Create aks-terraform --- aks-terraform | 1 + 1 file changed, 1 insertion(+) create mode 100644 aks-terraform diff --git a/aks-terraform b/aks-terraform new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/aks-terraform @@ -0,0 +1 @@ + From f5def7233d219ec3b909bd5831abf740835f8f5d Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Wed, 14 Feb 2024 09:46:12 +0000 Subject: [PATCH 21/26] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f7984cfa..b353fec6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -26,4 +26,4 @@ steps: azureResourceGroup: 'networking-rg' kubernetesCluster: 'terraform-aks-cluster' useClusterAdmin: true - manifests: 'application-manifest.yaml' \ No newline at end of file + manifests: './aka-terraform/application-manifest.yaml' \ No newline at end of file From abff016653af6e4151b73beb72e80663ef7f277d Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Mon, 19 Feb 2024 18:49:36 +0000 Subject: [PATCH 22/26] Update app.py Adds Key Vault Secrets --- app.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 50f4e29d..045f4b26 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +from azure.identity import ManagedIdentityCredential +from azure.keyvault.secrets import SecretClient from flask import Flask, render_template, request, redirect, url_for from sqlalchemy import create_engine, Column, Integer, String, DateTime from sqlalchemy.orm import sessionmaker @@ -6,14 +8,26 @@ import pyodbc import os +# Key Vault details +key_vault_url = "https://AzureDevOpsProject.vault.azure.net/" + +# Set up Azure Key Vault client with Managed Identity +credential = ManagedIdentityCredential() +secret_client = SecretClient(vault_url=key_vault_url, credential=credential) + # Initialise Flask App app = Flask(__name__) # database connection -server = 'devops-project-server.database.windows.net' -database = 'orders-db' -username = 'maya' -password = 'AiCore1237' +# Access the secret values from Key Vault +secret = secret_client.get_secret("server") +server = secret.value +secret = secret_client.get_secret("databse") +database = secret.value +secret = secret_client.get_secret("username") +username = secret.value +secret = secret_client.get_secret("password") +password = secret.value driver= '{ODBC Driver 18 for SQL Server}' # Create the connection string From efa842445ef7b95d901ec2186049864826e7f2d2 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Mon, 19 Feb 2024 18:50:47 +0000 Subject: [PATCH 23/26] Update requirements.txt adds azure-identity and azure-keyvault-secrets --- requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 47ec762e..1fda926e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ flask==2.2.2 pyodbc==4.0.39 SQLAlchemy==2.0.21 -werkzeug===2.2.3 \ No newline at end of file +werkzeug===2.2.3 +azure-identity +azure-keyvault-secrets From 7939d3b0cde3cf815704b3c562057c78e2b5afe1 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Mon, 19 Feb 2024 23:45:20 +0000 Subject: [PATCH 24/26] Update README.md updates the README.md with the information on Docker File, Kubernetes and AKS --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 08407749..387b12c5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ For the application to succesfully run, you need to install the following packag - pyodbc (version 4.0.39) - SQLAlchemy (version 2.0.21) - werkzeug (version 2.2.3) +- azure-identity +- azure-keyvault-secrets ### Usage @@ -53,9 +55,41 @@ To run the application, you simply need to run the `app.py` script in this repos - **Database:** The application employs an Azure SQL Database as its database system to store order-related data. +## Developer Inforamtion + +** Future Modifications ** +** Delivery Date:** Any new feature to be added in future will need to modify code in both the app.py and orders.html files. For example, Delivery Date feature can be added by by modifying the order class, @app_route and new_order sections in the app.py. Also Delivery Date will need to be added to the order.html in the table and form elements. + +** Containerization Process ** +Containerization involves: +- Creating a Docker File where base image, work directory, required libraries and dependencies and necessary commands are listed +- Building Docker Image using the Docker File + docker build -t +- Run the Docker Image to test all the features + docker run -p 5000:5000 +- Tag and Push the image to the Docker Hub + docker tag docker-user-name>/:tag +- Verify the Docker Hub Image by pulling it from the hub +- Cleanup + Romove Containers + docker ps -a + docker rm + + Remove Images + docker images -a + docker rmi + +** Infrastructure as Code IaC ** +The folder aka-terraform has all the necessary files to provision the resources on the Kubernetes and then to AKS. These details include the following: +- Terraform Modules +- Cluster Module +- Networking Modules +- Input and Output Variables + ## Contributors - [Maya Iuga]([https://github.com/yourusername](https://github.com/maya-a-iuga)) +- [Muhammad Nadeem Khan]([https://github.com/ndm621](https://github.com/ndm621)) ## License From 1c7159aabd2292c8810473356ef5ee3c97ce5dda Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 20 Feb 2024 10:19:43 +0000 Subject: [PATCH 25/26] Update README.md updates README.md with Developer Information. --- README.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 387b12c5..c041f6a3 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Welcome to the Web App DevOps Project repo! This application allows you to effic - [Features](#features) - [Getting Started](#getting-started) - [Technology Stack](#technology-stack) +- [Developer Information](#developer-information) - [Contributors](#contributors) - [License](#license) @@ -57,29 +58,29 @@ To run the application, you simply need to run the `app.py` script in this repos ## Developer Inforamtion -** Future Modifications ** -** Delivery Date:** Any new feature to be added in future will need to modify code in both the app.py and orders.html files. For example, Delivery Date feature can be added by by modifying the order class, @app_route and new_order sections in the app.py. Also Delivery Date will need to be added to the order.html in the table and form elements. +- **Future Modifications:** +Any new feature to be added in future will need to modify code in both the app.py and orders.html files. For example, Delivery Date feature can be added by by modifying the order class, @app_route and new_order sections in the app.py. Also Delivery Date will need to be added to the order.html in the table and form elements. -** Containerization Process ** +- **Containerization Process:** Containerization involves: -- Creating a Docker File where base image, work directory, required libraries and dependencies and necessary commands are listed -- Building Docker Image using the Docker File +1. Creating a Docker File where base image, work directory, required libraries and dependencies and necessary commands are listed +1. Building Docker Image using the Docker File docker build -t -- Run the Docker Image to test all the features +1. Run the Docker Image to test all the features docker run -p 5000:5000 -- Tag and Push the image to the Docker Hub +1. Tag and Push the image to the Docker Hub docker tag docker-user-name>/:tag -- Verify the Docker Hub Image by pulling it from the hub -- Cleanup - Romove Containers - docker ps -a - docker rm +1. Verify the Docker Hub Image by pulling it from the hub +1. Cleanup + - Romove Containers + - docker ps -a + - docker rm - Remove Images - docker images -a - docker rmi + - Remove Images + - docker images -a + - docker rmi -** Infrastructure as Code IaC ** +- **Infrastructure as Code IaC:** The folder aka-terraform has all the necessary files to provision the resources on the Kubernetes and then to AKS. These details include the following: - Terraform Modules - Cluster Module From e8d3776b27a1b809a9cd91ab25d79f75d44d2ff1 Mon Sep 17 00:00:00 2001 From: Nadeem Khan Date: Tue, 20 Feb 2024 10:24:48 +0000 Subject: [PATCH 26/26] Update README.md Fixes Developer Information link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c041f6a3..cd0f17d9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ To run the application, you simply need to run the `app.py` script in this repos - **Database:** The application employs an Azure SQL Database as its database system to store order-related data. -## Developer Inforamtion +## Developer Information - **Future Modifications:** Any new feature to be added in future will need to modify code in both the app.py and orders.html files. For example, Delivery Date feature can be added by by modifying the order class, @app_route and new_order sections in the app.py. Also Delivery Date will need to be added to the order.html in the table and form elements.