Skip to content

Commit 339df76

Browse files
committed
Added auto deployment for chatbot and made compliance checklist deployment only trigger on changes to relevant files
1 parent 6549839 commit 339df76

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Deploy Python Chatbot
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'Python RAG chatbot/**'
8+
- '.github/workflows/deploy-chatbot.yml'
9+
10+
jobs:
11+
deploy-chatbot:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Copy chatbot files to EC2
18+
uses: appleboy/scp-action@v0.1.7
19+
with:
20+
host: ${{ secrets.CHATBOT_EC2_HOST }}
21+
username: ec2-user
22+
key: ${{ secrets.EC2_SSH_KEY }}
23+
source: "Python RAG chatbot/*"
24+
target: "/home/ec2-user/"
25+
strip_components: 0
26+
27+
- name: Deploy and restart chatbot service
28+
uses: appleboy/ssh-action@v0.1.10
29+
with:
30+
host: ${{ secrets.CHATBOT_EC2_HOST }}
31+
username: ec2-user
32+
key: ${{ secrets.EC2_SSH_KEY }}
33+
script: |
34+
cd "/home/ec2-user/Python RAG chatbot"
35+
36+
# Install/update dependencies
37+
python3 -m pip install --upgrade pip
38+
python3 -m pip install -r requirements.txt
39+
40+
# Create/update .env file with secrets
41+
cat > .env <<EOF
42+
PINECONE_API_KEY=${{ secrets.PINECONE_API_KEY }}
43+
PINECONE_CLOUD=${{ secrets.PINECONE_CLOUD }}
44+
PINECONE_REGION=${{ secrets.PINECONE_REGION }}
45+
PINECONE_INDEX=${{ secrets.PINECONE_INDEX }}
46+
PINECONE_NAMESPACE=${{ secrets.PINECONE_NAMESPACE }}
47+
EMBED_MODEL=${{ secrets.EMBED_MODEL }}
48+
CHAT_MODEL=${{ secrets.CHAT_MODEL }}
49+
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
50+
EOF
51+
52+
# Create/update systemd service file
53+
sudo tee /etc/systemd/system/chatbot.service > /dev/null <<EOF
54+
[Unit]
55+
Description=Tariff RAG Chatbot API
56+
After=network.target
57+
58+
[Service]
59+
Type=simple
60+
User=ec2-user
61+
WorkingDirectory=/home/ec2-user/Python RAG chatbot
62+
ExecStart=/usr/bin/python3 -m uvicorn src.api_server:app --host 0.0.0.0 --port 8000
63+
Restart=on-failure
64+
RestartSec=10
65+
StandardOutput=journal
66+
StandardError=journal
67+
SyslogIdentifier=chatbot
68+
69+
[Install]
70+
WantedBy=multi-user.target
71+
EOF
72+
73+
# Reload and restart service
74+
sudo systemctl daemon-reload
75+
sudo systemctl enable chatbot
76+
sudo systemctl restart chatbot
77+
78+
# Check service status
79+
sudo systemctl status chatbot --no-pager

.github/workflows/deploy_compliance.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ name: Deploy to EC2
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [ "main" ]
6+
paths:
7+
- 'Compliance_checklist/**'
8+
- '.github/workflows/deploy_compliance.yml'
79

810
jobs:
911
deploy:

0 commit comments

Comments
 (0)