From b52b9953fd45373624b924a7c97fc299de3f6899 Mon Sep 17 00:00:00 2001 From: Hermas Amaewhule Date: Fri, 2 Feb 2024 04:44:05 +0000 Subject: [PATCH 1/4] updates to app.py and orders.html files with delivery date feature --- app.py | 3 + templates/orders.html | 180 ++++++++++++++++++++++++++---------------- 2 files changed, 113 insertions(+), 70 deletions(-) diff --git a/app.py b/app.py index 50f4e29d..26b02d47 100644 --- a/app.py +++ b/app.py @@ -39,6 +39,7 @@ class Order(Base): __tablename__ = 'orders' date_uuid = Column('date_uuid', String, primary_key=True) + delivery_date = column('Delivery Date', DateTime) user_id = Column('User ID', String, primary_key=True) card_number = Column('Card Number', String) store_code = Column('Store Code', String) @@ -78,6 +79,7 @@ def display_orders(): @app.route('/add_order', methods=['POST']) def add_order(): date_uuid = request.form.get('date_uuid') + delivery_date = request.form['delivery_date'] user_id = request.form.get('user_id') card_number = request.form.get('card_number') store_code = request.form.get('store_code') @@ -99,6 +101,7 @@ def add_order(): product_quantity=product_quantity, order_date=order_date, shipping_date=shipping_date + delivery_date=delivery_date ) # Add the new order to the session and commit to the database diff --git a/templates/orders.html b/templates/orders.html index 9372e2d0..03bb325c 100644 --- a/templates/orders.html +++ b/templates/orders.html @@ -1,82 +1,122 @@ - + 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 2b165e25b9ac8e8b0618bcb3546418c6d62ea743 Mon Sep 17 00:00:00 2001 From: Hermas Amaewhule Date: Fri, 2 Feb 2024 05:15:08 +0000 Subject: [PATCH 2/4] updates to app.py and orders.html files with delivery date feature --- app.py | 8 ++++++-- templates/orders.html | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 50f4e29d..6f7d68cf 100644 --- a/app.py +++ b/app.py @@ -9,7 +9,7 @@ # Initialise Flask App app = Flask(__name__) -# database connection +# database connection server = 'devops-project-server.database.windows.net' database = 'orders-db' username = 'maya' @@ -39,6 +39,7 @@ class Order(Base): __tablename__ = 'orders' date_uuid = Column('date_uuid', String, primary_key=True) + delivery_date = Column('Delivery Date', DateTime) user_id = Column('User ID', String, primary_key=True) card_number = Column('Card Number', String) store_code = Column('Store Code', String) @@ -78,6 +79,7 @@ def display_orders(): @app.route('/add_order', methods=['POST']) def add_order(): date_uuid = request.form.get('date_uuid') + delivery_date = request.form['delivery_date'] user_id = request.form.get('user_id') card_number = request.form.get('card_number') store_code = request.form.get('store_code') @@ -85,7 +87,8 @@ def add_order(): product_quantity = request.form.get('product_quantity') order_date = request.form.get('order_date') shipping_date = request.form.get('shipping_date') - + + # Create a session to interact with the database session = Session() @@ -99,6 +102,7 @@ def add_order(): product_quantity=product_quantity, order_date=order_date, shipping_date=shipping_date + delivery_date=delivery_date ) # Add the new order to the session and commit to the database diff --git a/templates/orders.html b/templates/orders.html index 9372e2d0..204a33d1 100644 --- a/templates/orders.html +++ b/templates/orders.html @@ -12,7 +12,7 @@

Fictional Company Name

- +

Order List

@@ -27,6 +27,7 @@

Order List

Product Quantity Order Date Shipping Date + Delivery Date @@ -40,6 +41,7 @@

Order List

{{ order.product_quantity }} {{ order.order_date }} {{ order.shipping_date }} + {{ order.delivery Date }} {% endfor %} @@ -73,6 +75,8 @@

Add New Order



+ +

From 55b312f4d3650017c602f019e67f5a3d56275aa8 Mon Sep 17 00:00:00 2001 From: Hermas Amaewhule Date: Sun, 4 Feb 2024 11:06:21 +0000 Subject: [PATCH 3/4] Updates to App.py, orders.htmlfiles and creation of docker documentation --- Docker Image documentation.odt | Bin 0 -> 7324 bytes app.py | 5 +++-- docker-image-documentation.txt | 18 ++++++++++++++++++ dockerfile | 32 ++++++++++++++++++++++++++++++++ templates/orders.html | 2 +- ~$cker Image documentation.odt | Bin 0 -> 162 bytes 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Docker Image documentation.odt create mode 100644 docker-image-documentation.txt create mode 100644 dockerfile create mode 100644 ~$cker Image documentation.odt diff --git a/Docker Image documentation.odt b/Docker Image documentation.odt new file mode 100644 index 0000000000000000000000000000000000000000..3c42df6ffb5369b8bfead3ccbe34bf502a50438f GIT binary patch literal 7324 zcmZ`;1ymf%wjCh2OK^7*EI@D)BtUTY0Kpk%@WI_(6G(!)yThQ#0D}Z~4NihiaR21~ z|JQx*zW-~jTHU?7_UTn!b$XrMTU`m|2^QeL8w0?kj}M3K@#0U%c0NP(v1_0nP`$Gv5 z0PqA20Kj<+=4u6j03B>xxjpT{vD!nb-*^eynGpC%BE=3r!whkkgnMvbbvI_td`*Dw z39cQ@3)?%ZC;1LAh}9>|(>R)1H+$W)pmehs;bWfzTM5>@hE&Zz_jYD&fjDUXXuO9SfB|pxU4DGRJWR9 ze>yg8E<0erPBBy0LTYZ~hI};C+TMS+c{=kc8J*W{542_<5wq}RzM&Gox16@t3;Tw? zur+%6;x5mWt(ErE&`a5A_2ugVod>7!q2Hb@vikOdYNs?IKTq!6d&}WU{SA@dp|0{! zt=x|i=U50I?h(rm6C^fTR)V|1$n9S&6DBxC*yzyTj2YJ!v!2E}zC0`&)(o5rIAj58 zXY5qxI6Z56Dg6LM;sPDNcuvI<spjy}N$NTHQrG$X+z&9vrh{O|LuOOt0uw-ufjs9WUWSFf&`M37bL2QqFd?w&LSX%COPo9)T}q>2^9?5~}z)e}F-OVIIWXCEnK zKnP)qb-!|L2}uYJ>{uN7vWmiC@!*L4dx`jsP=^bE&`pOI|0w^)@AFzv{%TH~dY!aE zu*Q>Q4sJ`W+?$P?OPc7|!sJO^g_1F1a)?ovzfRet0x$i$+FTUi1|DbJJ3b&>S;uxP zncXgwA=&+Xq}7`5495w{`Vv9>IdkA_eG;3aBFBDM zz|+(N>Ue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NQ{kI~T%;*t!zg-)eTAD~7G- z(B=^dRoDaHcT~Ozybgo37Ya9_)#w?aEIQsEv;grRZf7UU3*6 zu6LDWUQ@HR+O)-XXRmwZBexv=&HBzrxKC(Z?lke%`Tark!fkiY0`+f~=50M@iDk_Xjlg=GG6Ez%>dgL!V6d2VHc^a_ z7*zpO!%3xReDTtA@kAv8z}k+Fa)EE#XPn~c_rmjR!EMiWsq5^QX?t646O^fxzh#j| zTrxC*T#<^4k9fr`@WRB27{&lz3ecz8oV5mhTX?lxprPb>klIND_Sx>!W4`qFe>X6p z(7%fP^Q|p~pzf|= z+#)mZ-cuT(+Q0{X^jD?QdH1+=RBx1V#V(J>U%OzGw1|n=GJ9S(Fm0Rp^LCRwJXYra zU9%%0bNyAHKbGi#|8&d#pntdj_0H6l{;>XkTkLO!%H!$3nq>cE{?mT>n@RU*QT(4~ z%s)f?)3x|J#B-EKyYGKIjDNEJ`5XIhmOARc{nY*^@t?ZpZ=xsuzp5N{CDccg5b$Un Pq5%va6%r@apR4}@pN^gk literal 0 HcmV?d00001 diff --git a/app.py b/app.py index 6f7d68cf..0d8f8d89 100644 --- a/app.py +++ b/app.py @@ -87,6 +87,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') + # Create a session to interact with the database @@ -101,7 +102,7 @@ def add_order(): product_code=product_code, product_quantity=product_quantity, order_date=order_date, - shipping_date=shipping_date + shipping_date=shipping_date, delivery_date=delivery_date ) @@ -113,4 +114,4 @@ def add_order(): # run the app if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000, debug=True) + app.run(host='0.0.0.0', port=5000, debug=True) \ No newline at end of file diff --git a/docker-image-documentation.txt b/docker-image-documentation.txt new file mode 100644 index 00000000..7a3fb1a0 --- /dev/null +++ b/docker-image-documentation.txt @@ -0,0 +1,18 @@ +Docker Image documentation + +Created a docker container image named dockerfile to include the following steps: +• Step 1 - Use an official Python runtime as a parent image. (used `python:3.8-slim`) +• Step 2 - Set the working directory in the container. Used WORKDIR /app. +• Step 3 - Copy the application files in the container. Used the command (COPY . .) +• Step 4 - Install system dependencies and ODBC driver. +• Step 5 - Install pip and setuptools. +• Step 6 - Install Python packages specified in requirements.txt. +• Step 7 - Expose port (EXPOSE 5000) +• Step 8 - Define Startup Command (CMD ["python", "app.py"]) +Next, build the docker container image with the command: + >docker build -t dockerfile . +Next, run the docker container using the command that includes the exposed port as in the docker image: + >docker run -p 5000:5000 dockerfile +Next, Open a web browser and go to http://127.0.0.1:5000 to interact with the application within the Docker container to confirm the application works. +Next, Tag and push the docker container image to docker hub. First login to docker using the command in the command line: docker tag dockerfile whule/dockerfile (note that dockerfile is the name of the docker container image). +Then push the container image to docker hub with this command: docker push whule/dockerfile (Note that whule is my docker hub userid and dockerfile is the docker container image name) diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..4334ebd3 --- /dev/null +++ b/dockerfile @@ -0,0 +1,32 @@ +# TODO: Step 1 - Use an official Python runtime as a parent image. You can use `python:3.8-slim`. +FROM python:3.8-slim-buster + +# TODO: Step 2 - Set the working directory in the container +WORKDIR /app + +# TODO: Step 3 Copy the application files in the container +COPY . . + +# 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 + +# TODO: Step 4 - Install Python packages specified in requirements.txt +RUN pip install -r requirements.txt + +# TODO: Step 5 - Expose port +EXPOSE 5000 + +# TODO: Step 6 - Define Startup Command +CMD ["python", "app.py"] diff --git a/templates/orders.html b/templates/orders.html index 204a33d1..ceb6bfab 100644 --- a/templates/orders.html +++ b/templates/orders.html @@ -41,7 +41,7 @@

Order List

{{ order.product_quantity }} {{ order.order_date }} {{ order.shipping_date }} - {{ order.delivery Date }} + {{ order.delivery_date }} {% endfor %} diff --git a/~$cker Image documentation.odt b/~$cker Image documentation.odt new file mode 100644 index 0000000000000000000000000000000000000000..69887b3eab3022a22db3e64ce40b8ac82ee38ba2 GIT binary patch literal 162 zcmWgeNG-}uELL#LO-wD%D9uS_AO;99crc_g6fxv7Br+5;C@?sJS*Z-=3>gfi3^_nK y1_pB`28KB@sHOphzyKz`%ib#9FYFehX;}@YjTHk!;%kkT?LfXdRNX!QR(=2&5Ey*` literal 0 HcmV?d00001 From e5610a182c9bf01fdeedf0efd2eca05020c27d81 Mon Sep 17 00:00:00 2001 From: Hermas Amaewhule Date: Tue, 5 Mar 2024 14:16:20 +0000 Subject: [PATCH 4/4] This is the azure kubernetes service project --- aks-terraform/aks-cluster-module/main.tf | 21 ++++++ aks-terraform/aks-cluster-module/outputs.tf | 14 ++++ aks-terraform/aks-cluster-module/variables.tf | 64 +++++++++++++++++++ aks-terraform/application-manifest.yaml | 40 ++++++++++++ aks-terraform/main.tf | 16 +++++ aks-terraform/network-module/main.tf | 57 +++++++++++++++++ aks-terraform/network-module/outputs.tf | 26 ++++++++ aks-terraform/network-module/variables.tf | 17 +++++ 8 files changed, 255 insertions(+) create mode 100644 aks-terraform/aks-cluster-module/main.tf create mode 100644 aks-terraform/aks-cluster-module/outputs.tf create mode 100644 aks-terraform/aks-cluster-module/variables.tf create mode 100644 aks-terraform/application-manifest.yaml create mode 100644 aks-terraform/main.tf create mode 100644 aks-terraform/network-module/main.tf create mode 100644 aks-terraform/network-module/outputs.tf create mode 100644 aks-terraform/network-module/variables.tf diff --git a/aks-terraform/aks-cluster-module/main.tf b/aks-terraform/aks-cluster-module/main.tf new file mode 100644 index 00000000..7acdf7d5 --- /dev/null +++ b/aks-terraform/aks-cluster-module/main.tf @@ -0,0 +1,21 @@ +resource "azurerm_kubernetes_cluster" "aks-cluster" { + name = var.aks_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_secret +} diff --git a/aks-terraform/aks-cluster-module/outputs.tf b/aks-terraform/aks-cluster-module/outputs.tf new file mode 100644 index 00000000..6bc89e78 --- /dev/null +++ b/aks-terraform/aks-cluster-module/outputs.tf @@ -0,0 +1,14 @@ +output "aks_cluster_name" { + description = "Name of the AKS cluster" + value = +} + +output "aks_cluster_id" { + description = "ID of the AKS cluster" + value = +} + +output "aks_kubeconfig" { + description = "Kubeconfig file for accessing the AKS cluster." + value = +} diff --git a/aks-terraform/aks-cluster-module/variables.tf b/aks-terraform/aks-cluster-module/variables.tf new file mode 100644 index 00000000..c7a7b896 --- /dev/null +++ b/aks-terraform/aks-cluster-module/variables.tf @@ -0,0 +1,64 @@ +# input variables + +variable "aks_cluster_name" { + description = "The name of the AKS cluster to be created." +  type        = string + default = "aks-cluster" + } + +variable "cluster_location" { + description = "Specfies the Azure region where the AKS cluster would be deployed to" + type = string + default = "UK South" + } + +variable "dns_prefix" { + description = "Defines the DNS prefix of cluster" + type = string + } + +variable "kubernetes_version" { + description = "Specifies which Kubernetes version the cluster would use" + type = string + default = "1.26.6" + } + +variable "service_principal_client_id" { + description = "Provides the Client ID for the service principal associated with cluster" + type = string + default = "549b492c-2de8-4e83-84fe-d55e63b066bf" + } + +varaible "service_principal_secret" { + description = "Supplies the Client secret for the service principal" + type = string + default = "KHL8Q~a954lzhfeG.Qqut942LABjem28J_cMwdgY" + } + +# Adding the following output variables from networking module as input +# varables. + +output "vnet_id" { + description = "For storing the id of the previously created vnet" + value = azure_resource_group.aks_vnet.name + } + + output "control_plane_subnet_id" { + description = "For storing the ID of the control plane subnet within the Vnet" + value = azure_resource_group.aks_vnet.control_plane_subnet.name + } + +output "worker_node_subnet_id" { + description = "For storing the ID of the worker node subnet within the Vnet" + value = azure_resource_group.aks_vnet.worker_node_subnet.name +} + +output "networking_resource_group_name" { + description = Azure Resource Group where the networking resources were provisioned in." + value = var.azure_resource_group.name + } + +output "aks_nsg_id" { + description = "store the ID of the Network Security Group (NSG)." + value = azure_resource_group.aks-nsg.name + } diff --git a/aks-terraform/application-manifest.yaml b/aks-terraform/application-manifest.yaml new file mode 100644 index 00000000..705dc862 --- /dev/null +++ b/aks-terraform/application-manifest.yaml @@ -0,0 +1,40 @@ +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: web-app-container +          image: /flask-app:v1 +          ports: +          - containerPort: 5000 +  strategy: +    type: RollingUpdate +    rollingUpdate: +      maxUnavailable: 1 +      maxSurge: 1 + +--- + +apiVersion: v1 +kind: service +metadata: +  name: flask-app-service +spec: +    selector: +    matchLabels: +      app: flask-app +  ports: + - protocol: TCP + port: 80 # port for iternal communication within the cluster location +  targetport: 5000 # port exposed by your computer + type: ClusterIP diff --git a/aks-terraform/main.tf b/aks-terraform/main.tf new file mode 100644 index 00000000..6c39dd30 --- /dev/null +++ b/aks-terraform/main.tf @@ -0,0 +1,16 @@ +terraform { +  required_providers { +    azurerm = { +      source  = "hashicorp/azure" +      version = "=3.0.0" +    } +  } +} + +provider "azurerm" { +  features {} +  client_id       = "549b492c-2de8-4e83-84fe-d55e63b066bf" +  client_secret   = "KHL8Q~a954lzhfeG.Qqut942LABjem28J_cMwdgY" +  subscription_id = "8ab233ac-c619-4888-bf7a-422ea867b8d8" +  tenant_id       = "47d4542c-f112-47f4-92c7-a838d8a5e8ef" +} diff --git a/aks-terraform/network-module/main.tf b/aks-terraform/network-module/main.tf new file mode 100644 index 00000000..8acf8c66 --- /dev/null +++ b/aks-terraform/network-module/main.tf @@ -0,0 +1,57 @@ +resource "azure_resource_group" "aks-resources" { + name = var.resource_group_name + location = "UK South" +} + +resource "virtual_network" "aks-vnet" { + name = "aks-vnet" + address_space = ["10.0.0.0/16"] +} + +resource "control_plane_subnet" "control-plane-subnet"{ + name = "control-plane-subnet" + virtual_network_name = virtual_network.aks_net.name + +} +resource "worker_node_subnet" "worker-node-subnet" { + name = "worker-node-subnet" + virtual_network_name = virtual_network.aks-vnet.name + address_prefixes = ["10.0.1.0/24"] + +} + +resource "network_security_group" "aks-nsg" { + name = "aks-nsg" + resource_group_name = var.resource_group_name + location = var.location +} + +resource "network_security_rule" "kube-apiserver-rule" { + name = "kube-apiserver-rule" + resource_group_name = "var.resource_group_name" + networking_security_group_name = network_security_group.aks_nsg.name + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "TCP" + source_port_range = "*" + destination_port_range = "80" + source_address_prefix = "*" + destination_address_prefix = "*" + +} + +resource "network_security_rule" "ssh-rule" { + name = "ssh-rule" + resource_group_name = "var.resource_group_name" + network_security_group_name = network_security_group.aks_nsg.name + priority = 1002 + direction = "Inbound" + access = Allow + protocol = "TCP" + source_port_range = "*" + destination_port_range = "80" + source_address_prefix = "*" + destination_address_prefix = "*" + +} \ No newline at end of file diff --git a/aks-terraform/network-module/outputs.tf b/aks-terraform/network-module/outputs.tf new file mode 100644 index 00000000..6ed62910 --- /dev/null +++ b/aks-terraform/network-module/outputs.tf @@ -0,0 +1,26 @@ +output "vnet_id" { + description = "For storing the ID of the previously created vnet" + value = azure_resource_group.aks-vnet.name +} + +output "control_plane_subnet_id" { + description = "For storing the Id of the control plane subnet within the vnet" + value = azure_resource_group.aks-vnet.control_plane_subnet_id.name + +} + +output "worker_node_subnet_id" { + description = "For storing the Id of the worker node subnet within the vnet" + value = azure_resource_group.aks-vnet.worker_node_subnet_id.name +} + +output "networking_resource_group_name" { + description = "Azure resource group for provisioning the network group" + value = var.resource_group_name.default +} + +output "aks_nsg_id" { + description = " To store the ID of the network security group (NSG)" + value = azure_resource_group.aks_nsg.name + +} \ No newline at end of file diff --git a/aks-terraform/network-module/variables.tf b/aks-terraform/network-module/variables.tf new file mode 100644 index 00000000..06543f6b --- /dev/null +++ b/aks-terraform/network-module/variables.tf @@ -0,0 +1,17 @@ +variable "resource_group_name" { + description = "The name of the Azure Resource group" + type = string + default = "aks-resource" +} + +variable "location" { + description = "Azure region where the networking resources will be deployed" + type = string + default = "UK South" +} + +variable "vnet_address_space" { + description = "Specifies the address space for the virtual network (Vnet)" + type = list(string) + default = ["10.0.0.0/16"] +} \ No newline at end of file