-
Notifications
You must be signed in to change notification settings - Fork 3
99 lines (86 loc) · 4.18 KB
/
deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Deploy Dev to Docker Hub and DigitalOcean
on:
push:
branches:
- main
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 cmpe451group7/frontend:$FRONTEND_IMAGE_TAG ./frontend
docker tag cmpe451group7/frontend:${{ github.sha }} cmpe451group7/frontend:latest
# Build the backend image
- name: Build backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker build -t cmpe451group7/backend:$BACKEND_IMAGE_TAG ./backend/demo-group7
docker tag cmpe451group7/backend:${{ github.sha }} cmpe451group7/backend:latest
# Push the frontend image to Docker Hub
- name: Push frontend Docker image
run: |
FRONTEND_IMAGE_TAG=${{ github.sha }}
docker push cmpe451group7/frontend:$FRONTEND_IMAGE_TAG
docker push cmpe451group7/frontend:latest
# Push the backend image to Docker Hub
- name: Push backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker push cmpe451group7/backend:$BACKEND_IMAGE_TAG
docker push cmpe451group7/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=cmpe451group7/frontend:${{ github.sha }} --namespace=default
kubectl set image deployment/backend backend=cmpe451group7/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