Skip to content

Commit a768be6

Browse files
committed
chore: cd를 위한 runner 스크립트 작서
1 parent 5fc5253 commit a768be6

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/deploy-app.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: STACK-UP deploy ana-server
2+
3+
# dev 브랜치가 업데이트되면 AI서버와 실시간서버를 빌드하고 배포
4+
# 상우 원격컴에서만 작동하니 클라우드로 옮기면 삭제해야 함
5+
# 백엔드 코어랑 프론트는 아직 도커에 정의되지 않았으니.. 그때 이어서 해야 함
6+
7+
on:
8+
push:
9+
branches: [dev]
10+
paths:
11+
- "ai/**"
12+
- "realtime/**"
13+
- "docker-compose.yml"
14+
- "infra/**"
15+
- ".github/workflows/deploy-app.yml"
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: deploy-app-${{ github.ref }}
20+
cancel-in-progress: false
21+
22+
jobs:
23+
deploy:
24+
runs-on: self-hosted
25+
timeout-minutes: 20
26+
27+
env:
28+
DEPLOY_DIR: /home/stackup/stackup
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Sync repo to deploy dir (preserve .env and data)
35+
run: |
36+
mkdir -p "$DEPLOY_DIR"
37+
rsync -a --delete \
38+
--exclude='.git' \
39+
--exclude='.env' \
40+
--exclude='var/' \
41+
--exclude='**/__pycache__' \
42+
--exclude='**/.venv' \
43+
--exclude='**/node_modules' \
44+
"$GITHUB_WORKSPACE/" "$DEPLOY_DIR/"
45+
46+
- name: Ensure .env exists and contains current LLM_API_KEY
47+
env:
48+
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
49+
run: |
50+
cd "$DEPLOY_DIR"
51+
if [ ! -f .env ]; then
52+
cp .env.example .env
53+
fi
54+
# Write LLM_API_KEY via a temp file to keep the secret off the
55+
# process command line.
56+
tmp=$(mktemp)
57+
trap 'rm -f "$tmp"' EXIT
58+
awk -v key="$LLM_API_KEY" '
59+
BEGIN { written = 0 }
60+
/^LLM_API_KEY=/ { print "LLM_API_KEY=" key; written = 1; next }
61+
{ print }
62+
END { if (!written) print "LLM_API_KEY=" key }
63+
' .env > "$tmp"
64+
mv "$tmp" .env
65+
chmod 600 .env
66+
67+
- name: Build and restart app services
68+
run: |
69+
cd "$DEPLOY_DIR"
70+
docker compose up -d --build ai realtime
71+
72+
- name: Wait for healthy
73+
run: |
74+
cd "$DEPLOY_DIR"
75+
set +e
76+
rc=0
77+
for svc in ai realtime; do
78+
container="stackup-$svc"
79+
ok=0
80+
for i in $(seq 1 36); do
81+
h=$(docker inspect --format '{{ .State.Health.Status }}' "$container" 2>/dev/null || echo "missing")
82+
echo " [$i] $container: $h"
83+
if [ "$h" = "healthy" ]; then ok=1; break; fi
84+
sleep 5
85+
done
86+
if [ "$ok" -ne 1 ]; then
87+
echo "::error::$container did not become healthy"
88+
docker compose logs --tail=100 "$svc" || true
89+
rc=1
90+
fi
91+
done
92+
docker compose ps
93+
exit $rc
94+
95+
- name: Prune dangling images (best-effort)
96+
if: always()
97+
run: docker image prune -f >/dev/null 2>&1 || true

0 commit comments

Comments
 (0)