From b682b3d74708b2a1581b963f868869b783835b1b Mon Sep 17 00:00:00 2001 From: deepak1067 Date: Tue, 19 Sep 2023 12:09:47 +0530 Subject: [PATCH] azure deployment --- .github/workflows/car-demo-azure-pipeline.yml | 38 ++++++++ admin-service/azure-manifest/deployment.yaml | 21 +++++ admin-service/azure-manifest/service.yaml | 12 +++ admin-service/kustomization.yaml | 5 + apps-deployment-azure-script.sh | 91 +++++++++++++++++++ cart-service/azure-manifest/deployment.yaml | 21 +++++ cart-service/azure-manifest/service.yaml | 12 +++ cart-service/kustomization.yaml | 5 + .../azure-manifest/deployment.yaml | 21 +++++ inventory-service/azure-manifest/service.yaml | 12 +++ inventory-service/kustomization.yaml | 5 + order-service/azure-manifest/deployment.yaml | 21 +++++ order-service/azure-manifest/service.yaml | 12 +++ order-service/kustomization.yaml | 6 ++ .../azure-manifest/deployment.yaml | 20 ++++ payment-service/azure-manifest/service.yaml | 12 +++ payment-service/kustomization.yaml | 5 + .../azure-manifest/deployment.yaml | 21 +++++ shipment-service/azure-manifest/service.yaml | 12 +++ shipment-service/kustomization.yaml | 4 + 20 files changed, 356 insertions(+) create mode 100644 .github/workflows/car-demo-azure-pipeline.yml create mode 100644 admin-service/azure-manifest/deployment.yaml create mode 100644 admin-service/azure-manifest/service.yaml create mode 100644 apps-deployment-azure-script.sh create mode 100644 cart-service/azure-manifest/deployment.yaml create mode 100644 cart-service/azure-manifest/service.yaml create mode 100644 inventory-service/azure-manifest/deployment.yaml create mode 100644 inventory-service/azure-manifest/service.yaml create mode 100644 order-service/azure-manifest/deployment.yaml create mode 100644 order-service/azure-manifest/service.yaml create mode 100644 payment-service/azure-manifest/deployment.yaml create mode 100644 payment-service/azure-manifest/service.yaml create mode 100644 shipment-service/azure-manifest/deployment.yaml create mode 100644 shipment-service/azure-manifest/service.yaml diff --git a/.github/workflows/car-demo-azure-pipeline.yml b/.github/workflows/car-demo-azure-pipeline.yml new file mode 100644 index 00000000..c71dc370 --- /dev/null +++ b/.github/workflows/car-demo-azure-pipeline.yml @@ -0,0 +1,38 @@ +name: car-demo-common-service + +on: + push: + branches: [ feature/azure-deployment ] +env: + # add env variables + +jobs: + setup-build-publish-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: 'write' + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 19 + uses: actions/setup-java@v3 + with: + java-version: '19' + distribution: 'temurin' + cache: maven + - name: Configure Kubernetes environment + uses: azure/aks-set-context@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Install Docker + run: | + curl -fsSL https://get.docker.com -o get-docker.sh + sudo sh get-docker.sh + + - name: Build, Publish, and Deploy + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + . apps-deployment-azure-script.sh "us-east1" \ No newline at end of file diff --git a/admin-service/azure-manifest/deployment.yaml b/admin-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..2551f49d --- /dev/null +++ b/admin-service/azure-manifest/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: adminservice +spec: + replicas: 1 + selector: + matchLabels: + app: adminservice + template: + metadata: + labels: + app: adminservice + spec: + containers: + - name: adminservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9091 + diff --git a/admin-service/azure-manifest/service.yaml b/admin-service/azure-manifest/service.yaml new file mode 100644 index 00000000..f7cca68a --- /dev/null +++ b/admin-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: adminservice +spec: + type: LoadBalancer + selector: + app: adminservice + ports: + - protocol: TCP + port: 9091 + targetPort: 9091 \ No newline at end of file diff --git a/admin-service/kustomization.yaml b/admin-service/kustomization.yaml index 6db59089..4c554c9e 100644 --- a/admin-service/kustomization.yaml +++ b/admin-service/kustomization.yaml @@ -3,3 +3,8 @@ kind: Kustomization resources: - gcp-deploy-service.yaml + + + # need to change acc. to select gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file diff --git a/apps-deployment-azure-script.sh b/apps-deployment-azure-script.sh new file mode 100644 index 00000000..f1413181 --- /dev/null +++ b/apps-deployment-azure-script.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# AKS Cluster Configuration +AKS_CLUSTER="cluster" +AKS_RESOURCE_GROUP="group" +AKS_NAMESPACE="default" +ACR_NAME="youracrname" + +# Function to build and deploy service to AKS +build_and_deploy_service() { + SERVICE_NAME="$1" + DEPLOYMENT_NAME="$2" + + # Checkout code + git clone https://github.com/your/repository.git "$SERVICE_NAME" + cd "$SERVICE_NAME" || exit + + +# # Create Azure Container Registry +# az acr create --resource-group $AKS_RESOURCE_GROUP \ +# --name $ACR_NAME \ +# --sku Standard \ +# --location $AKS_REGION +# +# # Providing required permission for downloading Docker image from ACR into AKS Cluster +# az aks update -n $AKS_CLUSTER \ +# -g $AKS_RESOURCE_GROUP \ +# --attach-acr $ACR_NAME + + # Build and push Docker image to ACR + az acr login --name "$ACR_NAME" + docker build -t "$ACR_NAME.azurecr.io/${SERVICE_NAME}:${GITHUB_SHA}" . + docker push "$ACR_NAME.azurecr.io/${SERVICE_NAME}:${GITHUB_SHA}" + + # Configure Kubernetes environment + az aks get-credentials --resource-group "$AKS_RESOURCE_GROUP" --name "$AKS_CLUSTER_NAME" + + # Set the image for kustomize + kustomize edit set image "$ACR_NAME.azurecr.io/${SERVICE_NAME}:${GITHUB_SHA}" + + # Deploy through kubectl + kustomize build . | kubectl apply -f - + kubectl rollout status deployment/"$DEPLOYMENT_NAME" -n "$AKS_NAMESPACE" + kubectl get services -o wide -n "$AKS_NAMESPACE" + + echo "-------------$SERVICE_NAME deployed on $AKS_CLUSTER_NAME----------" +} + +for project in $(cat projects-changes-deploy.txt) +do + : + case $project in + # case 1 build and deploy package common + "common") + cd common || exit + mvn -B clean deploy --file pom.xml + cd ..;; + + # case 2 build and deploy order-service + "order-service") + build_and_deploy_service order-service $AKS_CLUSTER orderservice + cd ..;; + + # case 3 build and deploy inventory-service + "inventory-service") + build_and_deploy_service inventory-service $AKS_CLUSTER inventoryservice + cd ..;; + + # case 4 build and deploy payment-service + "payment-service") + build_and_deploy_service payment-service $AKS_CLUSTER paymentservice + cd ..;; + + # case 5 build and deploy order-service + "shipment-service") + build_and_deploy_service shipment-service $AKS_CLUSTER shipmentservice + cd ..;; + + + # case 6 build and deploy admin-service + "admin-service") + build_and_deploy_service admin-service $AKS_CLUSTER adminservice + cd ..;; + + # case 7 build and deploy cart-service + "cart-service") + build_and_deploy_service cart-service $AKS_CLUSTER cartservice + cd ..;; + esac + +done \ No newline at end of file diff --git a/cart-service/azure-manifest/deployment.yaml b/cart-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..6651b700 --- /dev/null +++ b/cart-service/azure-manifest/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cartservice +spec: + replicas: 1 + selector: + matchLabels: + app: cartservice + template: + metadata: + labels: + app: cartservice + spec: + containers: + - name: cartservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9091 + diff --git a/cart-service/azure-manifest/service.yaml b/cart-service/azure-manifest/service.yaml new file mode 100644 index 00000000..39866097 --- /dev/null +++ b/cart-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: cartservice +spec: + type: LoadBalancer + selector: + app: cartservice + ports: + - protocol: TCP + port: 9091 + targetPort: 9091 \ No newline at end of file diff --git a/cart-service/kustomization.yaml b/cart-service/kustomization.yaml index 6db59089..0d65476e 100644 --- a/cart-service/kustomization.yaml +++ b/cart-service/kustomization.yaml @@ -3,3 +3,8 @@ kind: Kustomization resources: - gcp-deploy-service.yaml + + + # need to change acc to gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file diff --git a/inventory-service/azure-manifest/deployment.yaml b/inventory-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..459ab7b8 --- /dev/null +++ b/inventory-service/azure-manifest/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: inventoryservice +spec: + replicas: 1 + selector: + matchLabels: + app: inventoryservice + template: + metadata: + labels: + app: inventoryservice + spec: + containers: + - name: inventoryservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9091 + diff --git a/inventory-service/azure-manifest/service.yaml b/inventory-service/azure-manifest/service.yaml new file mode 100644 index 00000000..f6d58e46 --- /dev/null +++ b/inventory-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: inventoryservice +spec: + type: LoadBalancer + selector: + app: inventoryservice + ports: + - protocol: TCP + port: 9091 + targetPort: 9091 \ No newline at end of file diff --git a/inventory-service/kustomization.yaml b/inventory-service/kustomization.yaml index 6db59089..c54a5e8d 100644 --- a/inventory-service/kustomization.yaml +++ b/inventory-service/kustomization.yaml @@ -3,3 +3,8 @@ kind: Kustomization resources: - gcp-deploy-service.yaml + + +# need to change acc to gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file diff --git a/order-service/azure-manifest/deployment.yaml b/order-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..b04ad5be --- /dev/null +++ b/order-service/azure-manifest/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: orderservice +spec: + replicas: 1 + selector: + matchLabels: + app: orderservice + template: + metadata: + labels: + app: orderservice + spec: + containers: + - name: orderservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9090 + diff --git a/order-service/azure-manifest/service.yaml b/order-service/azure-manifest/service.yaml new file mode 100644 index 00000000..a9abd67c --- /dev/null +++ b/order-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: orderservice +spec: + type: LoadBalancer + selector: + app: orderservice + ports: + - protocol: TCP + port: 9090 + targetPort: 9090 \ No newline at end of file diff --git a/order-service/kustomization.yaml b/order-service/kustomization.yaml index b41da777..8d2a6b59 100644 --- a/order-service/kustomization.yaml +++ b/order-service/kustomization.yaml @@ -3,3 +3,9 @@ kind: Kustomization resources: - gcp-deploy-services.yaml + + + + # need to change acc to gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file diff --git a/payment-service/azure-manifest/deployment.yaml b/payment-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..6962254d --- /dev/null +++ b/payment-service/azure-manifest/deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: paymentservice +spec: + replicas: 1 + selector: + matchLabels: + app: paymentservice + template: + metadata: + labels: + app: paymentservice + spec: + containers: + - name: paymentservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9092 diff --git a/payment-service/azure-manifest/service.yaml b/payment-service/azure-manifest/service.yaml new file mode 100644 index 00000000..4ebd2ebc --- /dev/null +++ b/payment-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: paymentservice +spec: + type: LoadBalancer + selector: + app: paymentservice + ports: + - protocol: TCP + port: 9092 + targetPort: 9092 \ No newline at end of file diff --git a/payment-service/kustomization.yaml b/payment-service/kustomization.yaml index 185cd585..c120b69e 100644 --- a/payment-service/kustomization.yaml +++ b/payment-service/kustomization.yaml @@ -4,3 +4,8 @@ kind: Kustomization resources: - gcp-deploy-service.yaml + + + # need to change acc to gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file diff --git a/shipment-service/azure-manifest/deployment.yaml b/shipment-service/azure-manifest/deployment.yaml new file mode 100644 index 00000000..e32517ee --- /dev/null +++ b/shipment-service/azure-manifest/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: shipmentservice +spec: + replicas: 1 + selector: + matchLabels: + app: shipmentservice + template: + metadata: + labels: + app: shipmentservice + spec: + containers: + - name: shipmentservice + image: your-acr-name.azurecr.io/your-image-name + + ports: + - containerPort: 9093 + diff --git a/shipment-service/azure-manifest/service.yaml b/shipment-service/azure-manifest/service.yaml new file mode 100644 index 00000000..f18015db --- /dev/null +++ b/shipment-service/azure-manifest/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: shipmentservice +spec: + type: LoadBalancer + selector: + app: shipmentservice + ports: + - protocol: TCP + port: 9093 + targetPort: 9093 \ No newline at end of file diff --git a/shipment-service/kustomization.yaml b/shipment-service/kustomization.yaml index f4fe4f0b..c120b69e 100644 --- a/shipment-service/kustomization.yaml +++ b/shipment-service/kustomization.yaml @@ -5,3 +5,7 @@ resources: - gcp-deploy-service.yaml + + # need to change acc to gcp and azure deployment +- azure-manifest/deployment.yaml +- azure-manifest/service.yaml \ No newline at end of file