Skip to content

Commit e7ed760

Browse files
hendisantikaclaude
andcommitted
feat: add GitHub Actions deployment pipeline to dev server
Build Docker image, push to Docker Hub (hendisantika/jvmid-bot), and deploy to dev server (103.31.204.189) via SSH on every push to main. Reuses existing lint & test checks as a prerequisite before deploying. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5981766 commit e7ed760

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy to Dev Server
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
checks:
10+
uses: ./.github/workflows/python-checks.yml
11+
12+
build-and-push:
13+
needs: checks
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to Docker Hub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_TOKEN }}
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v6
30+
with:
31+
context: .
32+
push: true
33+
tags: |
34+
hendisantika/jvmid-bot:latest
35+
hendisantika/jvmid-bot:${{ github.sha }}
36+
cache-from: type=gha
37+
cache-to: type=gha,mode=max
38+
39+
deploy:
40+
needs: build-and-push
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Set up SSH key
47+
run: |
48+
mkdir -p ~/.ssh
49+
echo "${{ secrets.DEV_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
50+
chmod 600 ~/.ssh/id_rsa
51+
echo "${{ secrets.DEV_SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
52+
chmod 644 ~/.ssh/known_hosts
53+
54+
- name: Copy docker-compose.prod.yml to server
55+
run: |
56+
scp docker-compose.prod.yml deployer@103.31.204.189:~/jvmid-bot/docker-compose.prod.yml
57+
58+
- name: Deploy on server
59+
run: |
60+
ssh deployer@103.31.204.189 << 'EOF'
61+
cd ~/jvmid-bot
62+
docker compose -f docker-compose.prod.yml pull
63+
docker compose -f docker-compose.prod.yml up -d
64+
docker image prune -f
65+
echo "Deployment complete. Running containers:"
66+
docker ps --filter "name=jvmid-bot"
67+
EOF

.github/workflows/python-checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ "main" ]
66
pull_request:
77
branches: [ "main" ]
8+
workflow_call:
89

910
jobs:
1011
lint:

docker-compose.prod.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3.8'
2+
3+
services:
4+
bot:
5+
image: hendisantika/jvmid-bot:latest
6+
container_name: jvmid-bot
7+
env_file: .env
8+
volumes:
9+
- ./data:/app/data
10+
restart: unless-stopped
11+
deploy:
12+
resources:
13+
limits:
14+
cpus: '1'
15+
memory: 512M
16+
reservations:
17+
cpus: '0.5'
18+
memory: 256M

0 commit comments

Comments
 (0)