Skip to content

Merge pull request #495 from bounswe/fix/BE-get-profile-by-username #110

Merge pull request #495 from bounswe/fix/BE-get-profile-by-username

Merge pull request #495 from bounswe/fix/BE-get-profile-by-username #110

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 }}
FRONTEND_API_URL="http://${{ secrets.DO_REMOTE }}:30002"
docker build --build-arg REACT_APP_API_BASE_URL=$FRONTEND_API_URL -t 24cmpe451group2/frontend:$FRONTEND_IMAGE_TAG ./frontend
docker tag 24cmpe451group2/frontend:${{ github.sha }} 24cmpe451group2/frontend:latest
# Build the backend image
- name: Build backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker build -t 24cmpe451group2/backend:$BACKEND_IMAGE_TAG ./backend
docker tag 24cmpe451group2/backend:${{ github.sha }} 24cmpe451group2/backend:latest
# 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
docker push 24cmpe451group2/frontend:latest
# 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
docker push 24cmpe451group2/backend:latest
# 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
EOF
# Sleep before checking pod status
- name: Sleep before checking pod status
run: sleep 30
# Check the status of the frontend pods
- name: Check frontend pod status
run: |
sshpass -p "${{ secrets.DO_SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no root@${{ secrets.DO_REMOTE }} << EOF
echo "Checking the status of the frontend pods:"
FRONTEND_WAITING_REASONS=\$(kubectl get pods -l app=frontend --namespace=default -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}')
if [ -z "\$FRONTEND_WAITING_REASONS" ]; then
echo "All frontend pods are running successfully. No containers are waiting."
else
echo "Error: Some frontend pods are not running successfully."
echo "Waiting reasons for frontend pods: \$FRONTEND_WAITING_REASONS"
exit 1
fi
EOF
# Check the status of the backend pods
- name: Check backend pod status
run: |
sshpass -p "${{ secrets.DO_SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no root@${{ secrets.DO_REMOTE }} << EOF
echo "Checking the status of the backend pods:"
BACKEND_WAITING_REASONS=\$(kubectl get pods -l app=backend --namespace=default -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}')
if [ -z "\$BACKEND_WAITING_REASONS" ]; then
echo "All backend pods are running successfully. No containers are waiting."
else
echo "Error: Some backend pods are not running successfully."
echo "Waiting reasons for backend pods: \$BACKEND_WAITING_REASONS"
exit 1
fi
EOF