-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.71 KB
/
python-build-deploy.yml
File metadata and controls
84 lines (72 loc) · 2.71 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
78
79
80
81
82
83
84
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/air-core-dev-ae-images:latest
deploy:
name: Deploy to GCE
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to GCE via SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.GCE_HOST }}
username: ${{ secrets.GCE_USER }}
key: ${{ secrets.GCE_SSH_KEY }}
script: |
cd /home/ubuntu/rowing/fastapi
docker compose down || true
docker compose pull
docker compose up -d
docker compose ps
- name: Send Success Discord Notification
if: success()
run: |
repo_name=${{ github.event.repository.name }}
branch=${{ github.ref_name }}
curl -H "Content-Type: application/json" \
-d "{\"content\": \"**✅ 배포 성공!** :rocket:\\n저장소: \`${repo_name}\`\\n브랜치: \`${branch}\`\\n빌드 및 배포가 완료되었습니다.\"}" \
${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Failure Discord Notification
if: failure()
run: |
repo_name=${{ github.event.repository.name }}
branch=${{ github.ref_name }}
outcome_message=""
if [ \"${{ steps.build.outcome }}\" == \"failure\" ]; then
outcome_message+="빌드 단계에서 오류 발생.\\n"
fi
if [ \"${{ steps.docker_build.outcome }}\" == \"failure\" ]; then
outcome_message+="Docker 빌드 단계에서 오류 발생.\\n"
fi
if [ \"${{ steps.deploy.outcome }}\" == \"failure\" ]; then
outcome_message+="배포 단계에서 오류 발생.\\n"
fi
if [ -z \"$outcome_message\" ]; then
outcome_message="원인 불명 오류.\\n"
fi
curl -H "Content-Type: application/json" \
-d "{\"content\": \"**❌ 배포 실패!** :x:\\n저장소: \`${repo_name}\`\\n브랜치: \`${branch}\`\\n${outcome_message}자세한 내용은 GitHub Actions 로그를 확인하세요.\"}" \
${{ secrets.DISCORD_WEBHOOK_URL }}