Skip to content

Commit 250eb03

Browse files
committed
cd: Fix workflows
1 parent 478c31d commit 250eb03

File tree

3 files changed

+36
-87
lines changed

3 files changed

+36
-87
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ jobs:
1919
uses: actions/setup-node@v3
2020
with:
2121
node-version: "20.x"
22+
2223
- run: npm ci
2324
- run: npm run build --if-present

.github/workflows/prod-deploy.yml

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,85 +5,37 @@ on:
55
workflows: ["KTU Bot Test Deploy"]
66
types:
77
- completed
8+
push:
9+
branches:
10+
- "prod"
811

912
jobs:
10-
on-failure:
11-
runs-on: ubuntu-latest
12-
if: github.ref == 'refs/heads/prod' && github.event.workflow_run.conclusion == 'failure'
13-
steps:
14-
- run: echo "Test deployment failed.. Skipping prod deploy.." && exit 1
15-
16-
on-success:
17-
runs-on: ubuntu-latest
18-
if: github.ref == 'refs/heads/prod' && github.event.workflow_run.conclusion == 'success'
19-
steps:
20-
- run: echo "Test deployment successful.. Deploying prod..."
21-
22-
build-and-push:
23-
name: Build and push docker image
13+
deploy:
2414
runs-on: ubuntu-latest
25-
needs: on-success
26-
15+
if: github.event.workflow_run.conclusion == 'success'
2716
steps:
2817
- name: Checkout repository
2918
uses: actions/checkout@v4
3019

31-
- name: Login to docker hub
20+
- name: Login to Docker Hub
3221
uses: docker/login-action@v2
3322
with:
3423
username: ${{ secrets.DOCKERHUB_USERNAME }}
3524
password: ${{ secrets.DOCKERHUB_TOKEN }}
3625

37-
- name: Build and push docker image
38-
uses: docker/build-push-action@v4
39-
with:
40-
context: .
41-
push: true
42-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
43-
44-
deploy:
45-
name: Deploy docker container to VPS
46-
runs-on: ubuntu-latest
47-
needs: build-and-push
48-
49-
steps:
50-
- name: Checkout repository
51-
uses: actions/checkout@v4
52-
53-
- name: Deploy to VPS
54-
uses: appleboy/ssh-action@master
55-
with:
56-
host: ${{ secrets.HOST }}
57-
username: ${{ secrets.USERNAME }}
58-
key: ${{ secrets.SSH_PRIVATE_KEY }}
59-
port: 22
60-
script: |
61-
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }}
62-
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/ktu-bot:${{ github.sha }} ktu-bot:latest
63-
docker stop ktu-bot || true
64-
docker stop redis-queue-db || true
65-
docker rm ktu-bot || true
66-
docker rm redis-queue-db || true
67-
docker network rm ktu-bot-network || true
68-
docker network create ktu-bot-network || true
69-
docker run -d --restart always -p 6379:6379 --network ktu-bot-network --network-alias redis-queue-db --name redis-queue-db redis
70-
docker run -d \
71-
--restart always \
72-
-p 5000:5000 \
73-
-e TZ=Asia/Kolkata \
74-
--network ktu-bot-network \
75-
-e ENV_TYPE=${{ secrets.ENV_TYPE }} \
76-
-e ADMIN_ID=${{ secrets.ADMIN_ID }} \
77-
-e WEBHOOK_DOMAIN=${{ secrets.WEBHOOK_DOMAIN }} \
78-
-e WEBHOOK_PORT=${{ secrets.WEBHOOK_PORT }} \
79-
-e BOT_TOKEN=${{ secrets.BOT_TOKEN }} \
80-
-e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" \
81-
-e NODE_ENV=production \
82-
-e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" \
83-
-e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET }}" \
84-
-e LATEST_COMMIT=${{ github.sha }} \
85-
-e UPTIME_ROBOT_API_KEY=${{ secrets.UPTIME_ROBOT_API_KEY }} \
86-
-e ORIGIN_URL=${{ secrets.ORIGIN_URL }} \
87-
--name ktu-bot \
88-
-v /var/log/ktu-bot:/var/log/ktu-bot \
89-
ktu-bot:latest
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

.github/workflows/test-deploy.yml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,14 @@ on:
55
workflows: ["CI"]
66
types:
77
- completed
8+
push:
9+
branches:
10+
- "prod"
811

912
jobs:
10-
on-success:
11-
runs-on: ubuntu-latest
12-
if: github.ref == 'refs/heads/prod' && github.event.workflow_run.conclusion == 'success'
13-
steps:
14-
- run: echo 'CI successful. Proceeding with test deploy..'
15-
16-
on-failure:
17-
runs-on: ubuntu-latest
18-
if: github.ref == 'refs/heads/prod' && github.event.workflow_run.conclusion == 'failure'
19-
steps:
20-
- run: echo 'CI failed. Skipping test deploy..' && exit 1
21-
2213
test_deploy:
23-
name: Test deployment of bot
24-
if: github.ref == 'refs/heads/prod'
2514
runs-on: ubuntu-latest
26-
needs: on-success
27-
15+
if: github.event.workflow_run.conclusion == 'success'
2816
steps:
2917
- name: Checkout repository
3018
uses: actions/checkout@v4
@@ -36,7 +24,15 @@ jobs:
3624
run: |
3725
docker network create ktu-bot-network || true
3826
docker run -d -p 6379:6379 --network ktu-bot-network --network-alias redis-queue-db --name redis-queue-db redis
39-
docker run -d -p 5000:5000 -e TZ=Asia/Kolkata --network ktu-bot-network -e ENV_TYPE="DEVELOPMENT" -e BOT_TOKEN=${{ secrets.TESTING_BOT_TOKEN }} -e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT_TESTING }}" -e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" -e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET_TESTING }}" --name ktu-bot-testing ktu-bot-testing:latest
27+
docker run -d -p 5000:5000 \
28+
-e TZ=Asia/Kolkata \
29+
--network ktu-bot-network \
30+
-e ENV_TYPE="DEVELOPMENT" \
31+
-e BOT_TOKEN=${{ secrets.TESTING_BOT_TOKEN }} \
32+
-e FIREBASE_SERVICE_ACCOUNT="${{ secrets.FIREBASE_SERVICE_ACCOUNT_TESTING }}" \
33+
-e HUGGING_FACE_TOKEN="${{ secrets.HUGGING_FACE_TOKEN }}" \
34+
-e FIREBASE_STORAGE_BUCKET="${{ secrets.FIREBASE_STORAGE_BUCKET_TESTING }}" \
35+
--name ktu-bot-testing ktu-bot-testing:latest
4036
4137
- name: Wait for container to initialize
4238
run: sleep 5

0 commit comments

Comments
 (0)