Skip to content

Commit ac03bc1

Browse files
feat: dev 환경 설정 및 배포 스크립트 개선 (#179)
dev 환경에서 RAM 기반 env 파일 주입 기능 추가. docker-compose 파일 구조 단순화 및 배포 스크립트 보완.
1 parent 4726f45 commit ac03bc1

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

.github/workflows/deploy-to-dev-ec2-docker.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ jobs:
6565
host: ${{ secrets.EC2_HOST }}
6666
username: ubuntu
6767
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
68+
# ------------------------------
69+
# 원격에서 실행될 스크립트
70+
# ------------------------------
6871
script: |
6972
set -euo pipefail
7073
@@ -78,14 +81,17 @@ jobs:
7881
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
7982
8083
# 2) Create ephemeral env file in RAM (no disk residue)
81-
# - make /run/saerok owned by current user to avoid Permission denied
8284
sudo install -d -m 0700 -o "$(id -un)" -g "$(id -gn)" /run/saerok
8385
ENV_FILE="/run/saerok/env.dev"
8486
umask 177
8587
: > "$ENV_FILE"
88+
# 어떤 경우에도 마지막에 지우도록 보장
89+
cleanup() { shred -u "$ENV_FILE" || rm -f "$ENV_FILE"; }
90+
trap cleanup EXIT
8691
8792
# 2-1) Write secrets safely (single-line values assumed)
8893
add_kv() { printf '%s\n' "$1=$2" >> "$ENV_FILE"; }
94+
add_kv SPRING_PROFILES_ACTIVE "dev"
8995
add_kv DB_URL "${{ secrets.DB_URL }}"
9096
add_kv DB_USERNAME "${{ secrets.DB_USERNAME }}"
9197
add_kv DB_PASSWORD "${{ secrets.DB_PASSWORD }}"
@@ -122,14 +128,11 @@ jobs:
122128
-f docker-compose.dev.yml \
123129
up -d --force-recreate --quiet-pull
124130
125-
# 4) Clean up env (memory file)
126-
shred -u "$ENV_FILE" || rm -f "$ENV_FILE"
127-
128-
# 5) Show minimal status (no secrets)
131+
# 4) Status & recent logs (env 파일은 trap으로 종료 시 삭제)
129132
docker compose -p saerok -f docker-compose.yml -f docker-compose.dev.yml ps
130133
docker logs --tail=120 saerok-dev || true
131134
132-
# 6) Healthcheck
135+
# 5) Healthcheck
133136
echo "Waiting for health endpoint..."
134137
for i in {1..30}; do
135138
if curl -fsS http://localhost:8080/health > /dev/null; then
@@ -140,4 +143,5 @@ jobs:
140143
sleep 5
141144
done
142145
echo "❌ Healthcheck failed after retries"
146+
docker logs --tail=200 saerok-dev || true
143147
exit 1

deploy/docker-compose.dev.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ services:
1010
cpus: "0.75"
1111
mem_limit: "700m"
1212

13+
# 런타임에 생성한 RAM env 파일을 컨테이너로 그대로 주입
14+
env_file:
15+
- /run/saerok/env.dev
16+
1317
environment:
18+
# dev 오버레이에서 명시적으로 고정하고 싶은 값만 남김
1419
SPRING_PROFILES_ACTIVE: "dev"
1520
JAVA_OPTS: >-
1621
-Duser.timezone=Asia/Seoul

deploy/docker-compose.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
version: "3.9"
2-
31
services:
4-
app:
5-
environment:
6-
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE}
7-
DB_URL: ${DB_URL}
8-
depends_on: []
2+
app: {}

0 commit comments

Comments
 (0)