Skip to content

Commit 5803a38

Browse files
committed
feat(cicd): Implement self-deploying continuous deployment pipeline
1 parent 124117e commit 5803a38

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

.github/workflows/build-image.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# It automatically builds your Docker image and pushes it to GHCR
2-
name: Build and Push Docker Image
31

4-
# We will run this workflow every time you push to the 'main' branch
2+
name: Build and Deploy Bot
3+
54
on:
65
push:
76
branches: [ "main" ]
87

98
jobs:
10-
build-and-push:
11-
runs-on: ubuntu-latest
9+
# ----------------------------------
10+
# JOB 1: BUILD THE DOCKER IMAGE
11+
# ----------------------------------
12+
build:
13+
runs-on: ubuntu-latest
1214
permissions:
1315
contents: read
14-
packages: write # Give the job permission to write to GHCR
16+
packages: write
1517

1618
steps:
1719
- name: Checkout repository
@@ -30,7 +32,6 @@ jobs:
3032
username: ${{ github.actor }}
3133
password: ${{ secrets.GITHUB_TOKEN }}
3234

33-
# Step to generate lowercase repository name
3435
- name: Set lowercase repository name
3536
run: echo "repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
3637

@@ -39,9 +40,53 @@ jobs:
3940
with:
4041
context: .
4142
file: ./Dockerfile
42-
platforms: linux/amd64,linux/arm64 # Build for multiple architectures
43+
platforms: linux/amd64,linux/arm64
4344
push: true
4445
tags: |
4546
ghcr.io/${{ env.repo }}:latest
4647
ghcr.io/${{ env.repo }}:${{ github.sha }}
4748
49+
# ----------------------------------
50+
# JOB 2: DEPLOY THE IMAGE TO THE VM
51+
# ----------------------------------
52+
deploy:
53+
needs: build
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- name: Deploy to VM
58+
uses: appleboy/ssh-action@v1.0.3
59+
with:
60+
host: ${{ secrets.VM_HOST }}
61+
username: ${{ secrets.VM_USER }}
62+
key: ${{ secrets.SSH_PRIVATE_KEY }}
63+
port: 22
64+
script: |
65+
echo "--- Starting deployment ---"
66+
67+
# Log in to GHCR (uses the GH_PAT secret)
68+
echo "${{ secrets.GH_PAT }}" | sudo docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
69+
70+
# Pull the new image (the one 'build' just created)
71+
sudo docker pull ghcr.io/rajat069/leetcode-reminder-bot:latest
72+
73+
# Stop and remove the old container
74+
# '|| true' means "don't fail if the container doesn't exist"
75+
sudo docker stop leetcode-bot || true
76+
sudo docker rm leetcode-bot || true
77+
78+
# Run the new container with all your flags
79+
sudo docker run \
80+
--detach \
81+
--restart=always \
82+
--name leetcode-bot \
83+
--dns=8.8.8.8 \
84+
--env-file /home/admin-rj/leetcode-env.env \
85+
-v /home/admin-rj/users.json:/app/users.json \
86+
ghcr.io/rajat069/leetcode-reminder-bot:latest
87+
88+
# Clean up old, unused images
89+
sudo docker image prune -f
90+
91+
echo "--- Deployment successful! ---"
92+

src/gemini_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def generate_optimal_hints(question, hint_count):
115115
else:
116116
print(" Gemini did not return a valid list of hints.")
117117
except json.JSONDecodeError:
118-
print(f" Failed to decode Gemini's JSON hint response: {response_text}")
118+
print(" Failed to decode Gemini's JSON hint response.")
119119

120120
# Fallback if anything fails
121121
return DEFAULT_HINTS[:hint_count]

0 commit comments

Comments
 (0)