Skip to content

Commit

Permalink
refactor(ci/cd) Updated main.yml with backend monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Uj5Ghare authored Dec 11, 2024
1 parent 108e297 commit 291f544
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ jobs:
git commit -m "refactor(k8s) updated k8s deployment image tag"
git push
#NOTE: I understand that following job does not adhere to real-world practices, but it is simply an experiment to showcase that we can use k8s to deploy our apps to github servers to simulate how it will function on our actual server/vm.
# I could have utilized EKS cluster here, but it's a very expensive service, and my AWS credits are ov
Deploy-On-Minikube-Frontend:
if: contains(github.event.head_commit.message, 'frontend')
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -238,6 +240,8 @@ jobs:
git commit -m "refactor(k8s) updated k8s deployment image tag"
git push
#NOTE: I understand that following job does not adhere to real-world practices, but it is simply an experiment to showcase that we can use k8s to deploy our apps to github servers to simulate how it will function on our actual server/vm.
# I could have utilized EKS cluster here, but it's a very expensive service, and my AWS credits are over.
Deploy-On-Minikube-Backend:
if: contains(github.event.head_commit.message, 'backend')
runs-on: ubuntu-24.04
Expand All @@ -252,8 +256,16 @@ jobs:
refs: ${{ github.refs_name }}
- name: Start minikube
uses: medyagh/setup-minikube@latest
- name: Try the cluster!
run: kubectl get pods -A
- name: Enable Metrics Server
run: |
minikube addons enable metrics-server
kubectl wait --for=condition=available --timeout=300s deployment/metrics-server -n kube-system
- name: Install Prometheus and Grafana
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus --set alertmanager.enabled=true
helm install grafana prometheus-community/grafana
- name: Deploy to minikube
run: |
kubectl apply -f namespace.yml
Expand All @@ -262,8 +274,30 @@ jobs:
run: |
sleep 10
kubectl get all -n app
sleep 5
kubectl get all -n app
- name: Monitor Resource Usage
run: |
sleep 10
kubectl top pods -n app
kubectl get all -n app
- name: Health Check for Backend
run: |
set -e
for i in {1..5}; do
if curl -fsS http://localhost:8000/status; then
echo "Backend is healthy!"
exit 0
else
echo "Attempt $i: Backend is down!"
sleep 10
fi
done
echo "ALERT: Backend is down!" >&2
- name: Expose Grafana
run: |
kubectl port-forward service/grafana 3000:80 &
echo "Grafana dashboard is accessible at http://localhost:3000"
Slack-Notification-Backend:
if: contains(github.event.head_commit.message, 'backend')
Expand Down

0 comments on commit 291f544

Please sign in to comment.