Skip to content

fix: add pod fail error handlers #6

fix: add pod fail error handlers

fix: add pod fail error handlers #6

Workflow file for this run

name: Deploy Dev to Docker Hub and DigitalOcean
on:
push:
branches:
- dev
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DO_SSH_PASSWORD: ${{ secrets.DO_SSH_PASSWORD }}
DO_REMOTE: ${{ secrets.DO_REMOTE }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Log in to Docker Hub
- name: Docker Hub login
run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Build the frontend image
- name: Build frontend Docker image
run: |
FRONTEND_IMAGE_TAG=${{ github.sha }}
docker build -t 24cmpe451group2/frontend:$FRONTEND_IMAGE_TAG ./frontend
# Build the backend image
- name: Build backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker build -t 24cmpe451group2/backend:$BACKEND_IMAGE_TAG ./backend
# Push the frontend image to Docker Hub
- name: Push frontend Docker image
run: |
FRONTEND_IMAGE_TAG=${{ github.sha }}
docker push 24cmpe451group2/frontend:$FRONTEND_IMAGE_TAG
# Push the backend image to Docker Hub
- name: Push backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker push 24cmpe451group2/backend:$BACKEND_IMAGE_TAG
# Login to DigitalOcean Droplet and trigger deployment updates
- name: Deploy to DigitalOcean
run: |
sshpass -p "${{ secrets.DO_SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no root@${{ secrets.DO_REMOTE }} << EOF
echo "Updating backend and frontend deployments"
kubectl set image deployment/frontend frontend=24cmpe451group2/frontend:${{ github.sha }} --namespace=default
kubectl set image deployment/backend backend=24cmpe451group2/backend:${{ github.sha }} --namespace=default
kubectl rollout status deployment/frontend --timeout=5m --namespace=default
kubectl rollout status deployment/backend --timeout=5m --namespace=default
echo "Checking the status of the frontend pods:"
FRONTEND_PODS_STATUS=$(kubectl get pods -l app=frontend --namespace=default -o jsonpath='{.items[*].status.phase}')
echo "Frontend pods status: $FRONTEND_PODS_STATUS"
if [[ $FRONTEND_PODS_STATUS != *"Running"* ]]; then
echo "Error: Frontend pods are not running. Current status: $FRONTEND_PODS_STATUS"
exit 1
fi
echo "Checking the status of the backend pods:"
BACKEND_PODS_STATUS=$(kubectl get pods -l app=backend --namespace=default -o jsonpath='{.items[*].status.phase}')
echo "Backend pods status: $BACKEND_PODS_STATUS"
if [[ $BACKEND_PODS_STATUS != *"Running"* ]]; then
echo "Error: Backend pods are not running. Current status: $BACKEND_PODS_STATUS"
exit 1
fi
echo "Deployment successful: Both frontend and backend pods are running."
EOF