-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (96 loc) · 3.56 KB
/
cd.yml
File metadata and controls
108 lines (96 loc) · 3.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: CD - Deploy to GCE Instances
on:
repository_dispatch:
types: [deploy-backend]
workflow_dispatch:
inputs:
image_tag:
description: "Docker image tag to deploy (default: latest)"
required: false
default: "latest"
target:
description: "Target instance (all/app/ocr/alert)"
required: false
default: "all"
concurrency:
group: cd-deploy
cancel-in-progress: false # 배포 중 취소 방지
jobs:
deploy:
name: Deploy ${{ matrix.instance.name }}
runs-on: ubuntu-latest
environment: production
strategy:
max-parallel: 1
fail-fast: false
matrix:
instance:
- { name: app, compose: docker-compose.app.yml }
- { name: ocr, compose: docker-compose.ocr.yml }
- { name: alert, compose: docker-compose.alert.yml }
steps:
- name: Check target filter
id: check
run: |
TARGET="${{ github.event.inputs.target || 'all' }}"
CURRENT="${{ matrix.instance.name }}"
if [ "$TARGET" != "all" ] && [ "$TARGET" != "$CURRENT" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "⏭️ Skipping $CURRENT (target: $TARGET)"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: steps.check.outputs.skip != 'true'
- name: Authenticate to Google Cloud
if: steps.check.outputs.skip != 'true'
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
if: steps.check.outputs.skip != 'true'
uses: google-github-actions/setup-gcloud@v2
- name: Get instance name
if: steps.check.outputs.skip != 'true'
id: instance
run: |
ROLE="${{ matrix.instance.name }}"
case "$ROLE" in
app) INSTANCE="${{ secrets.APP_INSTANCE }}" ;;
ocr) INSTANCE="${{ secrets.OCR_INSTANCE }}" ;;
alert) INSTANCE="${{ secrets.ALERT_INSTANCE }}" ;;
esac
echo "name=$INSTANCE" >> $GITHUB_OUTPUT
echo "🎯 Deploying to $INSTANCE"
- name: Sync deploy configs
if: steps.check.outputs.skip != 'true'
run: |
gcloud compute scp --recurse \
./compose ./config ./env ./scripts \
${{ steps.instance.outputs.name }}:~/depoly/ \
--zone=${{ secrets.GCE_ZONE }} \
--quiet
- name: Deploy via SSH
if: steps.check.outputs.skip != 'true'
run: |
gcloud compute ssh ${{ steps.instance.outputs.name }} \
--zone=${{ secrets.GCE_ZONE }} \
--quiet \
--command="
cd ~/depoly &&
gcloud auth configure-docker ${{ secrets.AR_REGION }}-docker.pkg.dev --quiet &&
source env/hosts.env &&
docker compose -f compose/${{ matrix.instance.compose }} pull &&
docker compose -f compose/${{ matrix.instance.compose }} up -d &&
echo '=== Container Status ===' &&
docker compose -f compose/${{ matrix.instance.compose }} ps
"
- name: Health check
if: steps.check.outputs.skip != 'true'
run: |
echo "⏳ Waiting 15s for services to start..."
sleep 15
gcloud compute ssh ${{ steps.instance.outputs.name }} \
--zone=${{ secrets.GCE_ZONE }} \
--quiet \
--command="docker compose -f ~/depoly/compose/${{ matrix.instance.compose }} ps --format 'table {{.Name}}\t{{.Status}}'"