Skip to content

Commit fcca5d9

Browse files
chore: 새록 어드민 배포를 위한 GitHub Actions 및 docker-compose dev 설정 추가
1 parent 39a0dde commit fcca5d9

4 files changed

Lines changed: 158 additions & 11 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Deploy Admin to Dev (EC2 + Docker Compose)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
packages: write
12+
environment: dev
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
# (옵션) BE와 동일 스타일 - 리포지토리명 소문자/메타 태그
18+
- name: Normalize image repo (lowercase)
19+
id: normalize
20+
run: echo "image_repo=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
21+
22+
- name: Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: GHCR login
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ secrets.GHCR_USERNAME }}
30+
password: ${{ secrets.GHCR_TOKEN }}
31+
32+
- name: Meta (tags/labels)
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ${{ steps.normalize.outputs.image_repo }}
37+
tags: |
38+
type=raw,value=dev-latest
39+
type=sha,format=long,prefix=dev-
40+
41+
- name: Build & Push
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
file: ./Dockerfile
46+
push: true
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}
49+
cache-from: type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache
50+
cache-to: type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache,mode=max
51+
52+
- name: Copy compose files to EC2
53+
uses: appleboy/scp-action@v0.1.7
54+
with:
55+
host: ${{ secrets.EC2_HOST }}
56+
username: ubuntu
57+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
58+
source: "deploy/docker-compose.yml,deploy/docker-compose.dev.yml"
59+
target: "~/saerok-admin"
60+
strip_components: 1
61+
62+
- name: Deploy on EC2
63+
uses: appleboy/ssh-action@v1
64+
with:
65+
host: ${{ secrets.EC2_HOST }}
66+
username: ubuntu
67+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
68+
script: |
69+
set -euo pipefail
70+
cd ~/saerok-admin
71+
72+
# 0) Docker & Compose must exist
73+
docker --version
74+
docker compose version
75+
76+
# 1) GHCR login for pull
77+
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
78+
79+
# 2) Create ephemeral env file in RAM and ensure cleanup
80+
sudo install -d -m 0700 /run/saerok-admin
81+
ENV_FILE="/run/saerok-admin/env.dev"
82+
umask 177
83+
: > "$ENV_FILE"
84+
cleanup() { shred -u "$ENV_FILE" || rm -f "$ENV_FILE"; }
85+
trap cleanup EXIT
86+
87+
add_kv() { printf '%s=%s\n' "$1" "$2" >> "$ENV_FILE"; }
88+
89+
# 2-1) Runtime envs (dev)
90+
# 프록시 뒤 HTTPS 인식/자바 힙 튜닝은 compose에 이미 있다면 생략 가능
91+
# add_kv SERVER_FORWARD_HEADERS_STRATEGY "native"
92+
# add_kv JAVA_OPTS "-Duser.timezone=Asia/Seoul -XX:MaxRAMPercentage=50 -XX:+ExitOnOutOfMemoryError"
93+
94+
# API endpoints
95+
add_kv SAEROK_API_BASE_URL "${{ secrets.SAEROK_API_BASE_URL }}"
96+
add_kv SAEROK_API_PREFIX "${{ secrets.SAEROK_API_PREFIX }}"
97+
98+
# Social login (admin 전용 redirect)
99+
add_kv KAKAO_CLIENT_ID "${{ secrets.ADMIN_KAKAO_CLIENT_ID }}"
100+
add_kv KAKAO_REDIRECT_URI "${{ secrets.KAKAO_REDIRECT_URI }}"
101+
add_kv APPLE_CLIENT_ID "${{ secrets.ADMIN_APPLE_CLIENT_ID }}"
102+
add_kv APPLE_REDIRECT_URI "${{ secrets.APPLE_REDIRECT_URI }}"
103+
104+
# 3) Pull & Up with dev overlay (mem/cpu limits inside dev.yml)
105+
docker compose -p saerok-admin -f docker-compose.yml -f docker-compose.dev.yml pull --quiet
106+
docker compose -p saerok-admin -f docker-compose.yml -f docker-compose.dev.yml up -d --force-recreate --quiet-pull
107+
108+
# 4) Healthcheck: /login (HEAD OK)
109+
for i in {1..30}; do
110+
if curl -fsS -I http://localhost:8081/login > /dev/null; then
111+
echo "✅ admin up"
112+
docker image prune -af --filter "until=24h" || true
113+
docker builder prune -af --filter "until=24h" || true
114+
exit 0
115+
fi
116+
echo "⏳ ($i/30)"; sleep 3
117+
done
118+
119+
echo "❌ admin health check failed"
120+
docker logs saerok-admin-dev --tail=200 || true
121+
exit 1

deploy/docker-compose.dev.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
services:
2+
app:
3+
image: ghcr.io/devkor-github/saerok-admin:dev-latest
4+
container_name: saerok-admin-dev
5+
restart: unless-stopped
6+
stop_grace_period: 15s
7+
ports: ["8081:8081"]
8+
9+
# t2.micro 안전 제한 (BE와 합쳐도 1GiB 넘지 않게)
10+
cpus: "0.25"
11+
mem_limit: "250m"
12+
13+
# 런타임에 만드는 RAM env 파일
14+
env_file:
15+
- /run/saerok-admin/env.dev
16+
17+
environment:
18+
# dev 오버레이에서 명시적으로 고정
19+
SPRING_PROFILES_ACTIVE: "dev"
20+
# 프록시 뒤 HTTPS 인식 (X-Forwarded-Proto 처리)
21+
SERVER_FORWARD_HEADERS_STRATEGY: "native"
22+
# 자바 메모리/타임존 튜닝
23+
JAVA_OPTS: >-
24+
-Duser.timezone=Asia/Seoul
25+
-XX:MaxRAMPercentage=50
26+
-XX:+ExitOnOutOfMemoryError

src/main/resources/application-codex.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ server:
33

44
oauth:
55
kakao:
6-
client-id: ${KAKAO_CLIENT_ID:}
7-
redirect-uri: ${KAKAO_REDIRECT_URI:http://localhost:8081/auth/callback/kakao}
6+
client-id: ${KAKAO_CLIENT_ID}
7+
redirect-uri: ${KAKAO_REDIRECT_URI}
88
apple:
9-
client-id: ${APPLE_CLIENT_ID:}
10-
redirect-uri: ${APPLE_REDIRECT_URI:http://localhost:8081/auth/callback/apple}
9+
client-id: ${APPLE_CLIENT_ID}
10+
redirect-uri: ${APPLE_REDIRECT_URI}
1111

1212
saerok:
1313
api:
14-
base-url: http://localhost:8080/api/v1
14+
base-url: ${SAEROK_API_BASE_URL}
1515
prefix: /api/v1

src/main/resources/application.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ server:
77

88
oauth:
99
kakao:
10-
client-id: ${KAKAO_CLIENT_ID:}
11-
redirect-uri: ${KAKAO_REDIRECT_URI:http://localhost:8081/auth/callback/kakao}
10+
client-id: ${KAKAO_CLIENT_ID}
11+
redirect-uri: ${KAKAO_REDIRECT_URI}
1212
apple:
13-
client-id: ${APPLE_CLIENT_ID:}
14-
redirect-uri: ${APPLE_REDIRECT_URI:http://localhost:8081/auth/callback/apple}
13+
client-id: ${APPLE_CLIENT_ID}
14+
redirect-uri: ${APPLE_REDIRECT_URI}
1515

1616
saerok:
1717
api:
18-
base-url: ${SAEROK_API_BASE_URL:http://localhost:8080/api/v1}
19-
prefix: ${SAEROK_API_PREFIX:/api/v1}
18+
base-url: ${SAEROK_API_BASE_URL}
19+
prefix: ${SAEROK_API_PREFIX}

0 commit comments

Comments
 (0)