Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/azure deployment #21

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/car-demo-azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: car-demo-common-service

on:
push:
branches: [ feature/azure-deployment ]

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"
34 changes: 34 additions & 0 deletions admin-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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: 8080

---
apiVersion: v1
kind: Service
metadata:
name: adminservice
spec:
type: LoadBalancer
selector:
app: adminservice
ports:
- protocol: TCP
port: 80
targetPort: 8080
4 changes: 4 additions & 0 deletions admin-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -3,3 +3,7 @@ kind: Kustomization

resources:
- gcp-deploy-service.yaml


# need to change acc. to select gcp and azure deployment
- azure-manifest/azure-deploy-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
35 changes: 35 additions & 0 deletions cart-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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: 9096


---
apiVersion: v1
kind: Service
metadata:
name: cartservice
spec:
type: LoadBalancer
selector:
app: cartservice
ports:
- protocol: TCP
port: 9096
targetPort: 9096
4 changes: 4 additions & 0 deletions cart-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -3,3 +3,7 @@ kind: Kustomization

resources:
- gcp-deploy-service.yaml


# need to change acc to gcp and azure deployment
- azure-manifest/azure-deploy-service.yaml
35 changes: 35 additions & 0 deletions inventory-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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


---
apiVersion: v1
kind: Service
metadata:
name: inventoryservice
spec:
type: LoadBalancer
selector:
app: inventoryservice
ports:
- protocol: TCP
port: 9091
targetPort: 9091
4 changes: 4 additions & 0 deletions inventory-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -3,3 +3,7 @@ kind: Kustomization

resources:
- gcp-deploy-service.yaml


# need to change acc to gcp and azure deployment
- azure-manifest/azure-deploy-service.yaml
35 changes: 35 additions & 0 deletions order-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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


---
apiVersion: v1
kind: Service
metadata:
name: orderservice
spec:
type: LoadBalancer
selector:
app: orderservice
ports:
- protocol: TCP
port: 9090
targetPort: 9090
5 changes: 5 additions & 0 deletions order-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -3,3 +3,8 @@ kind: Kustomization

resources:
- gcp-deploy-services.yaml



# need to change acc to gcp and azure deployment
- azure-manifest/azure-deploy-service.yaml
35 changes: 35 additions & 0 deletions payment-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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


---
apiVersion: v1
kind: Service
metadata:
name: paymentservice
spec:
type: LoadBalancer
selector:
app: paymentservice
ports:
- protocol: TCP
port: 9092
targetPort: 9092
4 changes: 4 additions & 0 deletions payment-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -4,3 +4,7 @@ kind: Kustomization
resources:
- gcp-deploy-service.yaml



# need to change acc to gcp and azure deployment
- azure-manifest/azure-deploy-service.yaml
34 changes: 34 additions & 0 deletions shipment-service/azure-manifest/azure-deploy-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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

---
apiVersion: v1
kind: Service
metadata:
name: shipmentservice
spec:
type: LoadBalancer
selector:
app: shipmentservice
ports:
- protocol: TCP
port: 9093
targetPort: 9093
3 changes: 3 additions & 0 deletions shipment-service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -5,3 +5,6 @@ resources:
- gcp-deploy-service.yaml



# need to change acc to gcp and azure deployment
- azure-manifest/azure-deploy-service.yaml