-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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/gemini-telegram-bot" | ||
|
||
- 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/gemini-telegram-bot | ||
# 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 "TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}" >> .env | ||
echo "API_KEY=${{ secrets.API_KEY }}" >> .env | ||
echo "BASE_API_URL=${{ secrets.BASE_API_URL }}" >> .env | ||
# Remove the old systemd service file if it exists | ||
sudo rm -f /etc/systemd/system/gemini_telegram_bot.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/gemini-telegram-bot | ||
ExecStart=/home/ubuntu/gemini-telegram-bot/venv/bin/python main.py | ||
Restart=always | ||
[Install] | ||
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/gemini_telegram_bot.service | ||
# Reload systemd, enable and start the service | ||
sudo systemctl daemon-reload | ||
sudo systemctl enable gemini_telegram_bot.service | ||
sudo systemctl start gemini_telegram_bot.service | ||
sudo systemctl restart gemini_telegram_bot |