Skip to content

Commit 563884a

Browse files
authored
Merge pull request #369 from PromptPlace/feat/#368
Chore: Seperate production and development environments
2 parents d9f50b6 + a4ecff2 commit 563884a

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: deploy-dev
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Configure SSH
18+
env:
19+
EC2_USER: ubuntu
20+
EC2_HOST: ${{ secrets.EC2_HOST }}
21+
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
22+
run: |
23+
set -euo pipefail
24+
mkdir -p ~/.ssh
25+
printf "%s" "$EC2_SSH_KEY" > ~/.ssh/id_rsa
26+
chmod 600 ~/.ssh/id_rsa
27+
cat >>~/.ssh/config <<END
28+
Host prod
29+
HostName $EC2_HOST
30+
User $EC2_USER
31+
IdentityFile ~/.ssh/id_rsa
32+
StrictHostKeyChecking no
33+
END
34+
35+
# 운영 폴더(/opt/app-backup)와 섞이지 않게 'app-dev' 폴더를 따로 사용
36+
- name: Prepare target dir
37+
run: |
38+
ssh prod 'sudo mkdir -p /opt/app-dev && sudo chown ubuntu:ubuntu /opt/app-dev'
39+
40+
- name: Sync workspace
41+
run: |
42+
rsync -az --delete --exclude ".git" --exclude "node_modules" ./ prod:/opt/app-dev/
43+
44+
# .env가 아니라 .env.dev로 저장하되, 내용은 DEV용 시크릿을 사용
45+
- name: Write .env on EC2
46+
run: |
47+
ssh prod 'cat > /opt/app-dev/.env.dev <<EOF
48+
${{ secrets.ENV_DEV_CONTENT }}
49+
EOF'
50+
51+
- name: Install, Generate & Build on server
52+
run: |
53+
ssh prod 'cd /opt/app-dev && pnpm install --frozen-lockfile && pnpm exec prisma generate'
54+
55+
# 테스트 DB 마이그레이션
56+
- name: Run Prisma DB Push (Dev)
57+
run: |
58+
ssh prod << 'EOF'
59+
set -euo pipefail
60+
cd /opt/app-dev
61+
# .env.dev 파일을 로드하여 실행
62+
export $(cat .env.dev | xargs)
63+
pnpm exec prisma db push
64+
EOF
65+
66+
# app-dev 컨테이너만 재시작 (운영 컨테이너 app, caddy는 건드리지 않음)
67+
- name: Deploy Docker services (Dev)
68+
run: |
69+
ssh prod 'cd /opt/app-dev && sudo docker compose -f docker-compose.yml up -d --build app-dev'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
# Keep environment variables out of version control
33
.env
4+
.env.dev
45

56
/generated/prisma
67
dist/

Caddyfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,39 @@ http://promptplace.kro.kr {
4848
output stdout
4949
format console
5050
}
51+
}
52+
53+
# 테스트 서버 (Development)
54+
http://promptplace-dev.kro.kr {
55+
encode zstd gzip
56+
57+
header {
58+
X-Content-Type-Options "nosniff"
59+
Referrer-Policy "strict-origin-when-cross-origin"
60+
}
61+
62+
handle /api/* {
63+
# app-dev 컨테이너(테스트용)로 연결
64+
reverse_proxy app-dev:3000 {
65+
health_uri /health
66+
health_interval 30s
67+
health_timeout 3s
68+
fail_duration 10s
69+
70+
header_up X-Forwarded-Proto {scheme}
71+
header_up X-Forwarded-Host {host}
72+
header_up X-Real-IP {remote_host}
73+
}
74+
}
75+
76+
# 로드밸런서 헬스체크용
77+
@health path /health
78+
handle @health {
79+
respond "ok" 200
80+
}
81+
82+
log {
83+
output stdout
84+
format console
85+
}
5186
}

docker-compose.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ services:
2525
max-size: "10m"
2626
max-file: "3"
2727

28+
app-dev: # 서비스명
29+
build: .
30+
container_name: myapp-dev # 컨테이너명
31+
command: >
32+
sh -c "pnpm start"
33+
env_file: # .env 가져오기
34+
- .env.dev
35+
environment:
36+
- NODE_ENV=development
37+
expose:
38+
- "3000" # 내부 네트워크만 노출 (Caddy가 프록시)
39+
healthcheck:
40+
test: ["CMD", "curl", "-f", "http://127.0.0.1:3000/health"] # 컨테이너 내부 IP로 헬스체크 확인
41+
interval: 30s
42+
timeout: 3s
43+
start_period: 20s
44+
retries: 5
45+
restart: unless-stopped
46+
networks:
47+
- webnet
48+
logging:
49+
driver: json-file
50+
options:
51+
max-size: "10m"
52+
max-file: "3"
53+
2854
caddy: # caddy 컨테이너
2955
image: caddy:2.8.4
3056
container_name: caddy
@@ -47,4 +73,4 @@ networks:
4773

4874
volumes:
4975
caddy_data:
50-
caddy_config:
76+
caddy_config:

0 commit comments

Comments
 (0)