-
Notifications
You must be signed in to change notification settings - Fork 1
64 lines (56 loc) · 1.71 KB
/
main.yml
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
name: Capshnz CI/CD Pipeline
on:
push:
branches:
- master
- ss_1203
jobs:
test-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
run: |
git clone https://github.com/infinite-options/Caption-Backend.git
cd Caption-Backend
ls
- name: Set Up Python
run: |
sudo apt update
sudo apt install -y python3 python3-pip
python3 --version
- name: Install Dependencies
run: |
cd Caption-Backend
pip3 install -r requirements.txt
- name: Run app to test
id: test
run: |
cd Caption-Backend
python3 caption_api.py &
sleep 10
if ! pgrep -f "python3 caption_api.py"; then
echo "App failed to start"
exit 1
fi
- name: Deploy to EC2
if: success()
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER}}
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
run: |
echo "${SSH_PRIVATE_KEY}" > ssh_key.pem
chmod 600 ssh_key.pem
ssh -o StrictHostKeyChecking=no -i ssh_key.pem $EC2_USER@$EC2_HOST << EOF
echo "Connected to EC2 instance"
cd /home/ec2-user/capshnz
source .venv/bin/activate
cd Caption-Backend
echo "Pulling latest code..."
git pull origin master
echo "Restarting application..."
pkill -f "python3 caption_api.py" || echo "No existing app running"
nohup python3 caption_api.py >> caption.log 2>&1 &
echo "Application started"
exit 0
EOF