-
Notifications
You must be signed in to change notification settings - Fork 7
108 lines (88 loc) · 3.86 KB
/
deploy.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
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
100
101
102
103
104
105
106
107
108
name: Gemini API Service Deploy CI/CD Workflow
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Copy Files to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: "."
target: "/home/ubuntu/langchain-gemini-api-service"
- name: SSH Remote Commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo "Running commands on remote server"
# go to the project directory
cd /home/ubuntu/langchain-gemini-api-service
# remove the old venv
sudo rm -r venv
# install python3-venv
python3.11 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
# Add environment variables to the .env file
# remove the old .env file
sudo rm -f .env
echo "GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" >> .env
echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> .env
echo "MY_API_KEY=${{ secrets.MY_API_KEY }}" >> .env
echo "SYSTEM_INSTRUCTION=${{ secrets.SYSTEM_INSTRUCTION }}" >> .env
# Ensure the NGINX config directories are clean
sudo rm -f /etc/nginx/sites-enabled/gemini_api_service
sudo rm -f /etc/nginx/sites-available/gemini_api_service
# Create and configure the NGINX configuration file for the manual proxy
echo "server {
listen 80;
server_name ${{ secrets.DOMAIN_NAME }};
location / {
proxy_pass http://localhost:8090;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}" | sudo tee /etc/nginx/sites-available/gemini_api_service
# Debug: Check if the file was created
sudo ls -l /etc/nginx/sites-available/
# Link the file and reload NGINX
if [ -f /etc/nginx/sites-available/gemini_api_service ]; then
sudo ln -s /etc/nginx/sites-available/gemini_api_service /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
else
echo "NGINX configuration file not created."
fi
# Remove the old systemd service file if it exists
sudo rm -f /etc/systemd/system/gemini_api_service.service
# Create systemd service file for the Docker container
echo "[Unit]
Description=Scraper Uvicorn Service
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/langchain-gemini-api-service
ExecStart=/home/ubuntu/langchain-gemini-api-service/venv/bin/uvicorn \
--host 0.0.0.0 \
--port 8090 \
--workers 3 \
app.main:app
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/gemini_api_service.service
# Reload systemd, enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable gemini_api_service.service
sudo systemctl start gemini_api_service.service
sudo systemctl restart gemini_api_service