-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (68 loc) · 2.57 KB
/
deploy_chatbot.yml
File metadata and controls
79 lines (68 loc) · 2.57 KB
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
name: Deploy Python Chatbot
on:
push:
branches: [ "main" ]
paths:
- 'Python RAG chatbot/**'
- '.github/workflows/deploy_chatbot.yml'
jobs:
deploy-chatbot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Copy chatbot files to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.CHATBOT_EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
source: "Python RAG chatbot/*"
target: "/home/ec2-user/"
strip_components: 0
- name: Deploy and restart chatbot service
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.CHATBOT_EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd "/home/ec2-user/Python RAG chatbot"
# Install/update dependencies
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
# Create/update .env file with secrets
cat > .env <<EOF
PINECONE_API_KEY=${{ secrets.CHATBOT_PINECONE_API_KEY }}
PINECONE_CLOUD=${{ secrets.PINECONE_CLOUD }}
PINECONE_REGION=${{ secrets.PINECONE_REGION }}
PINECONE_INDEX=${{ secrets.CHATBOT_PINECONE_INDEX }}
PINECONE_NAMESPACE=${{ secrets.PINECONE_NAMESPACE }}
EMBED_MODEL=${{ secrets.EMBED_MODEL }}
CHAT_MODEL=${{ secrets.CHAT_MODEL }}
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
EOF
# Create/update systemd service file
sudo tee /etc/systemd/system/chatbot.service > /dev/null <<EOF
[Unit]
Description=Tariff RAG Chatbot API
After=network.target
[Service]
Type=simple
User=ec2-user
WorkingDirectory=/home/ec2-user/Python RAG chatbot
ExecStart=/usr/bin/python3 -m uvicorn src.api_server:app --host 0.0.0.0 --port 8000
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=chatbot
[Install]
WantedBy=multi-user.target
EOF
# Reload and restart service
sudo systemctl daemon-reload
sudo systemctl enable chatbot
sudo systemctl restart chatbot
# Check service status
sudo systemctl status chatbot --no-pager