Skip to content

Commit 1baa44f

Browse files
committed
cd: Fix broken workflow
1 parent 250eb03 commit 1baa44f

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

.github/workflows/prod-deploy.yml

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ on:
1010
- "prod"
1111

1212
jobs:
13-
deploy:
13+
prod_deploy:
1414
runs-on: ubuntu-latest
15-
if: github.event.workflow_run.conclusion == 'success'
15+
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'push'
16+
1617
steps:
1718
- name: Checkout repository
1819
uses: actions/checkout@v4
@@ -23,19 +24,47 @@ jobs:
2324
username: ${{ secrets.DOCKERHUB_USERNAME }}
2425
password: ${{ secrets.DOCKERHUB_TOKEN }}
2526

26-
- name: Pull and Deploy
27-
run: |
28-
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
29-
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }} ktu-bot:latest
30-
docker stop ktu-bot || true
31-
docker rm ktu-bot || true
32-
docker run -d --restart always \
33-
-p 5000:5000 \
34-
-e TZ=Asia/Kolkata \
35-
-e ENV_TYPE=${{ secrets.ENV_TYPE }} \
36-
-e ADMIN_ID=${{ secrets.ADMIN_ID }} \
37-
-e BOT_TOKEN=${{ secrets.BOT_TOKEN }} \
38-
-e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" \
39-
-e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" \
40-
-e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET }}" \
41-
--name ktu-bot ktu-bot:latest
27+
- name: Build and push Docker image
28+
uses: docker/build-push-action@v4
29+
with:
30+
context: .
31+
push: true
32+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
33+
34+
- name: Deploy to VPS
35+
uses: appleboy/ssh-action@master
36+
with:
37+
host: ${{ secrets.HOST }}
38+
username: ${{ secrets.USERNAME }}
39+
key: ${{ secrets.SSH_PRIVATE_KEY }}
40+
port: 22
41+
script: |
42+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
43+
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }} ktu-bot:latest
44+
docker stop ktu-bot || true
45+
docker stop redis-queue-db || true
46+
docker rm ktu-bot || true
47+
docker rm redis-queue-db || true
48+
docker network rm ktu-bot-network || true
49+
docker network create ktu-bot-network || true
50+
docker run -d --restart always -p 6379:6379 --network ktu-bot-network --network-alias redis-queue-db --name redis-queue-db redis
51+
docker run -d \
52+
--restart always \
53+
-p 5000:5000 \
54+
-e TZ=Asia/Kolkata \
55+
--network ktu-bot-network \
56+
-e ENV_TYPE=${{ secrets.ENV_TYPE }} \
57+
-e ADMIN_ID=${{ secrets.ADMIN_ID }} \
58+
-e WEBHOOK_DOMAIN=${{ secrets.WEBHOOK_DOMAIN }} \
59+
-e WEBHOOK_PORT=${{ secrets.WEBHOOK_PORT }} \
60+
-e BOT_TOKEN=${{ secrets.BOT_TOKEN }} \
61+
-e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" \
62+
-e NODE_ENV=production \
63+
-e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" \
64+
-e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET }}" \
65+
-e LATEST_COMMIT=${{ github.sha }} \
66+
-e UPTIME_ROBOT_API_KEY=${{ secrets.UPTIME_ROBOT_API_KEY }} \
67+
-e ORIGIN_URL=${{ secrets.ORIGIN_URL }} \
68+
--name ktu-bot \
69+
-v /var/log/ktu-bot:/var/log/ktu-bot \
70+
ktu-bot:latest

.github/workflows/test-deploy.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ on:
88
push:
99
branches:
1010
- "prod"
11+
pull_request:
12+
branches:
13+
- "prod"
1114

1215
jobs:
1316
test_deploy:
1417
runs-on: ubuntu-latest
15-
if: github.event.workflow_run.conclusion == 'success'
18+
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'prod')
1619
steps:
1720
- name: Checkout repository
1821
uses: actions/checkout@v4
@@ -45,3 +48,4 @@ jobs:
4548
echo "Container has failed"
4649
exit 1
4750
fi
51+

0 commit comments

Comments
 (0)