Skip to content

Commit

Permalink
azure deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1067 committed Sep 19, 2023
1 parent 311a7a0 commit b682b3d
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/car-demo-azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions admin-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions admin-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: adminservice
spec:
type: LoadBalancer
selector:
app: adminservice
ports:
- protocol: TCP
port: 9091
targetPort: 9091
5 changes: 5 additions & 0 deletions admin-service/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 91 additions & 0 deletions apps-deployment-azure-script.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions cart-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions cart-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: cartservice
spec:
type: LoadBalancer
selector:
app: cartservice
ports:
- protocol: TCP
port: 9091
targetPort: 9091
5 changes: 5 additions & 0 deletions cart-service/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions inventory-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions inventory-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: inventoryservice
spec:
type: LoadBalancer
selector:
app: inventoryservice
ports:
- protocol: TCP
port: 9091
targetPort: 9091
5 changes: 5 additions & 0 deletions inventory-service/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions order-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions order-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: orderservice
spec:
type: LoadBalancer
selector:
app: orderservice
ports:
- protocol: TCP
port: 9090
targetPort: 9090
6 changes: 6 additions & 0 deletions order-service/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions payment-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions payment-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: paymentservice
spec:
type: LoadBalancer
selector:
app: paymentservice
ports:
- protocol: TCP
port: 9092
targetPort: 9092
5 changes: 5 additions & 0 deletions payment-service/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions shipment-service/azure-manifest/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions shipment-service/azure-manifest/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: shipmentservice
spec:
type: LoadBalancer
selector:
app: shipmentservice
ports:
- protocol: TCP
port: 9093
targetPort: 9093
Loading

0 comments on commit b682b3d

Please sign in to comment.