-
Notifications
You must be signed in to change notification settings - Fork 1
67 lines (53 loc) · 1.65 KB
/
Copy pathcd-prod.yml
File metadata and controls
67 lines (53 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: CD - PROD
on:
push:
# branches: [ main ]
branches: [ dev ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"
- uses: gradle/actions/setup-gradle@v3
- name: Grant execute permission
run: chmod +x gradlew
- name: Build JAR
run: ./gradlew build -x test
- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push
uses: docker/build-push-action@v5
with:
context: .
file: Docker/Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/realmatch-backend:prod
${{ secrets.DOCKERHUB_USERNAME }}/realmatch-backend:${{ github.sha }}
- name: Deploy
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PROD_SERVER_IP }}
username: ubuntu
key: ${{ secrets.PROD_SERVER_SSH_KEY }}
script: |
cd /home/ubuntu/realmatch
docker compose pull
docker compose up -d
echo "Waiting for app to start..."
sleep 10
if ! docker compose ps | grep "Up"; then
echo "❌ Container is not running"
docker compose logs
exit 1
fi
echo "🧹 Pruning old docker images..."
docker image prune -a --filter "until=24h" -f