Skip to content

KTU Bot Production Deploy #91

KTU Bot Production Deploy

KTU Bot Production Deploy #91

Workflow file for this run

name: KTU Bot Production Deploy
on:
workflow_run:
workflows: ["KTU Bot Test Deploy"]
types:
- completed
push:
branches:
- "prod"
jobs:
prod_deploy:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
- name: Deploy to VPS
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }} ktu-bot:latest
docker stop ktu-bot || true
docker stop redis-queue-db || true
docker rm ktu-bot || true
docker rm redis-queue-db || true
docker network rm ktu-bot-network || true
docker network create ktu-bot-network || true
docker run -d --restart always -p 6379:6379 --network ktu-bot-network --network-alias redis-queue-db --name redis-queue-db redis
docker run -d \
--restart always \
-p 5000:5000 \
-e TZ=Asia/Kolkata \
--network ktu-bot-network \
-e ENV_TYPE=${{ secrets.ENV_TYPE }} \
-e ADMIN_ID=${{ secrets.ADMIN_ID }} \
-e WEBHOOK_DOMAIN=${{ secrets.WEBHOOK_DOMAIN }} \
-e WEBHOOK_PORT=${{ secrets.WEBHOOK_PORT }} \
-e BOT_TOKEN=${{ secrets.BOT_TOKEN }} \
-e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" \
-e NODE_ENV=production \
-e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" \
-e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET }}" \
-e LATEST_COMMIT=${{ github.sha }} \
-e UPTIME_ROBOT_API_KEY=${{ secrets.UPTIME_ROBOT_API_KEY }} \
-e ORIGIN_URL=${{ secrets.ORIGIN_URL }} \
--name ktu-bot \
-v /var/log/ktu-bot:/var/log/ktu-bot \
ktu-bot:latest