-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (75 loc) · 2.77 KB
/
Copy pathdeploy.yml
File metadata and controls
77 lines (75 loc) · 2.77 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
68
69
70
71
72
73
74
75
76
77
name: Deploy to OCI
on:
push:
branches: [ dev ]
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Send to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "build/libs/AccountBookForMoms-0.0.1-SNAPSHOT.jar,docker-compose.yml,Dockerfile,nginx.conf"
target: "/home/ubuntu/app"
- name: Create secret file
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cat << 'EOF' > /home/ubuntu/app/application-secret.yml
${{ secrets.APPLICATION_SECRET }}
EOF
- name: Create FCM secret JSON file
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cat << 'EOF' > /home/ubuntu/app/firebase-service-account.json
${{ secrets.FCM_JSON_CONFIG }}
EOF
- name: Run on Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/ubuntu/app && \
cp build/libs/AccountBookForMoms-0.0.1-SNAPSHOT.jar . && \
sudo docker compose up -d --no-deps --build app --remove-orphans && \
sudo docker compose restart nginx
- name: Send Discord Notification
if: always()
run: |
if [ "${{ job.status }}" == "success" ]; then
STATUS="✅ 배포 성공!"
COLOR=5763719
else
STATUS="❌ 배포 실패!"
COLOR=15548997
fi
TITLE="백엔드 CI/CD 알림"
BRANCH="${{ github.ref_name }}"
COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | head -n 1 | sed 's/"/\\"/g')
LOG_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
curl -H "Content-Type: application/json" \
-d "{\"embeds\": [{\"title\": \"$TITLE\", \"color\": $COLOR, \"description\": \"**결과:** $STATUS\n**브랜치:** \`$BRANCH\`\n**커밋:** $COMMIT_MSG\n\n[빌드 결과 확인하기]($LOG_URL)\"}]}" \
${{ secrets.DISCORD_WEBHOOK }}