Skip to content

Commit 4941457

Browse files
committed
crone: 배포 파이프라인 구성
1 parent bd2036f commit 4941457

File tree

13 files changed

+705
-14
lines changed

13 files changed

+705
-14
lines changed

.env.example

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ===========================================
2+
# ProjectVG API Server - Environment Variables Template
3+
# ===========================================
4+
# Copy this file to .env and fill in your actual values
5+
6+
# Database Configuration
7+
DB_CONNECTION_STRING=Server=host.docker.internal,1433;Database=ProjectVG;User Id=sa;Password=YOUR_DB_PASSWORD;TrustServerCertificate=true;MultipleActiveResultSets=true
8+
DB_PASSWORD=YOUR_DB_PASSWORD
9+
10+
# Redis Configuration
11+
REDIS_CONNECTION_STRING=host.docker.internal:6380
12+
13+
# External Services
14+
LLM_BASE_URL=http://host.docker.internal:7908
15+
MEMORY_BASE_URL=http://host.docker.internal:7912
16+
TTS_BASE_URL=https://supertoneapi.com
17+
TTS_API_KEY=YOUR_TTS_API_KEY
18+
19+
# JWT Configuration (IMPORTANT: Use a secure random key in production)
20+
JWT_SECRET_KEY=YOUR_JWT_SECRET_KEY_MINIMUM_32_CHARACTERS
21+
JWT_ACCESS_TOKEN_LIFETIME_MINUTES=15
22+
JWT_REFRESH_TOKEN_LIFETIME_DAYS=30
23+
24+
# OAuth2 Configuration
25+
OAUTH2_ENABLED=true
26+
GOOGLE_OAUTH_ENABLED=true
27+
GOOGLE_OAUTH_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID
28+
GOOGLE_OAUTH_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET
29+
GOOGLE_OAUTH_REDIRECT_URI=http://localhost:7900/auth/oauth2/callback
30+
GOOGLE_OAUTH_AUTO_CREATE_USER=true
31+
GOOGLE_OAUTH_DEFAULT_ROLE=User
32+
33+
# Application Configuration
34+
ASPNETCORE_ENVIRONMENT=Production
35+
36+
# Container Resource Limits
37+
API_CPU_LIMIT=1.0
38+
API_MEMORY_LIMIT=1g
39+
API_PORT=7910

.gitattributes

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto
3+
4+
# Set file types that should always have CRLF line endings on checkout.
5+
*.sln text eol=crlf
6+
*.csproj text eol=crlf
7+
*.config text eol=crlf
8+
9+
# Set file types that should always have LF line endings on checkout.
10+
*.sh text eol=lf
11+
*.bash text eol=lf
12+
*.yml text eol=lf
13+
*.yaml text eol=lf
14+
15+
# Ensure that shell scripts are executable
16+
*.sh text eol=lf
17+
deploy.sh text eol=lf
18+
deploy-dev.sh text eol=lf
19+
20+
# PowerShell scripts
21+
*.ps1 text eol=crlf
22+
23+
# Docker files
24+
Dockerfile text eol=lf
25+
*.dockerfile text eol=lf
26+
docker-compose*.yml text eol=lf
27+
28+
# Markdown files
29+
*.md text eol=lf
30+
31+
# JSON files
32+
*.json text eol=lf

.github/workflows/release-cicd.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ env:
1212
DOTNET_VERSION: '8.0.x'
1313
DOCKER_IMAGE_NAME: ghcr.io/projectvg/projectvgapi
1414
ACTOR: projectvg
15+
16+
permissions:
17+
contents: read
18+
packages: write
1519

1620
jobs:
1721
build:
@@ -69,16 +73,22 @@ jobs:
6973
runs-on: [self-hosted, deploy-runner]
7074

7175
steps:
76+
- name: Checkout Repository
77+
uses: actions/checkout@v4
78+
7279
- name: Login to GitHub Container Registry
7380
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ env.ACTOR }} --password-stdin
7481

7582
- name: Add Private Files
7683
run: |
7784
echo "${{ secrets.PROD_APPLICATION_ENV }}" | base64 --decode > .env
78-
echo "${{ secrets.PROD_DOCKER_COMPOSE }}" | base64 --decode > docker-compose.yml
85+
echo "${{ secrets.PROD_DOCKER_COMPOSE }}" | base64 --decode > deploy/docker-compose.yml
86+
87+
- name: Make Deploy Script Executable
88+
run: chmod +x deploy/deploy.sh
7989

8090
- name: Run Deployment Script
81-
run: ./deploy.sh
91+
run: ./deploy/deploy.sh
8292

8393
- name: Cleanup Docker and Cache
8494
run: |

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ _ReSharper*/
100100

101101
# Docker
102102
**/Dockerfile.*
103-
docker-compose*
103+
docker-compose.override.yml
104+
105+
# Keep template files but ignore runtime files
106+
!docker-compose.prod.yml
107+
!env.prod.example
104108

105109
# Logs
106110
*.log
@@ -175,5 +179,5 @@ secrets.json
175179
*.xlsx
176180

177181
# Demo files
178-
web_chat_demo.html
179-
time_travel_commit.exe
182+
*.exe
183+
*.ini

ProjectVG.Api/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ EXPOSE 7900
2929
# 빌드 결과 복사
3030
COPY --from=build /app/publish .
3131

32-
# 헬스체크 추가
33-
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
34-
CMD curl -f http://localhost:7900/health || exit 1
32+
# 헬스체크 추가 - wget 사용
33+
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
34+
CMD wget --no-verbose --tries=1 --spider http://localhost:7900/health || exit 1
3535

3636
ENTRYPOINT ["dotnet", "ProjectVG.Api.dll"]

ProjectVG.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectVG.Common", "Project
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectVG.Tests", "ProjectVG.Tests\ProjectVG.Tests.csproj", "{9A8B7C6D-5E4F-3210-9876-543210987654}"
1717
EndProject
18-
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{81DDED9D-158B-E303-5F62-77A2896D2A5A}"
19-
EndProject
2018
Global
2119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2220
Debug|Any CPU = Debug|Any CPU
@@ -47,10 +45,6 @@ Global
4745
{9A8B7C6D-5E4F-3210-9876-543210987654}.Debug|Any CPU.Build.0 = Debug|Any CPU
4846
{9A8B7C6D-5E4F-3210-9876-543210987654}.Release|Any CPU.ActiveCfg = Release|Any CPU
4947
{9A8B7C6D-5E4F-3210-9876-543210987654}.Release|Any CPU.Build.0 = Release|Any CPU
50-
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
53-
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Release|Any CPU.Build.0 = Release|Any CPU
5448
EndGlobalSection
5549
GlobalSection(SolutionProperties) = preSolution
5650
HideSolutionNode = FALSE

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ dotnet test ProjectVG.Tests/ProjectVG.Tests.csproj
115115
- `POST /api/auth/logout` - 로그아웃
116116
- `GET /api/test/me` - 사용자 정보 (인증 필요)
117117

118+
## 🚀 배포
119+
120+
### 자동 배포 (CI/CD)
121+
`release` 브랜치에 푸시하면 자동 배포됩니다.
122+
123+
### 수동 배포
124+
```bash
125+
# 프로덕션 배포
126+
./deploy.sh
127+
128+
# 개발 환경 배포
129+
./deploy-dev.sh
130+
131+
# Windows 환경
132+
.\scripts\deploy.ps1 -Environment dev
133+
.\scripts\deploy.ps1 -Environment prod
134+
```
135+
136+
상세한 배포 가이드는 [DEPLOYMENT.md](DEPLOYMENT.md)를 참조하세요.
137+
118138
## 🧪 테스트
119139

120140
### 테스트 실행

deploy/DEPLOYMENT.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# 배포 가이드
2+
3+
ProjectVG API 서버의 배포 방법에 대한 가이드입니다.
4+
5+
## 🚀 자동 배포 (CI/CD)
6+
7+
### GitHub Secrets 설정 (최초 1회)
8+
9+
배포하기 전에 GitHub Secrets에 환경변수를 설정해야 합니다.
10+
11+
```bash
12+
# Secrets 생성 헬퍼 스크립트 실행
13+
./scripts/generate-secrets.sh
14+
15+
# 또는 Windows에서
16+
.\scripts\Generate-Secrets.ps1
17+
```
18+
19+
**필요한 GitHub Secrets**:
20+
- `PROD_APPLICATION_ENV`: .env 파일의 base64 인코딩
21+
- `PROD_DOCKER_COMPOSE`: docker-compose.prod.yml의 base64 인코딩
22+
- `GHCR_TOKEN`: GitHub Container Registry 접근 토큰
23+
24+
### Release 브랜치 자동 배포
25+
`release` 브랜치에 푸시하면 자동으로 배포가 진행됩니다.
26+
27+
1. **빌드 & 테스트**: Ubuntu에서 빌드 및 테스트 실행
28+
2. **Docker 이미지**: GHCR에 이미지 푸시
29+
3. **환경변수 복원**: GitHub Secrets에서 base64 디코딩
30+
4. **배포**: self-hosted runner에서 자동 배포
31+
32+
```bash
33+
git checkout release
34+
git merge develop
35+
git push origin release
36+
```
37+
38+
### 배포 프로세스
39+
- **빌드**: `dotnet build` + `dotnet test`
40+
- **Docker 이미지**: `ghcr.io/projectvg/projectvgapi:latest`
41+
- **환경변수**: GitHub Secrets → base64 decode → `.env`
42+
- **Docker Compose**: GitHub Secrets → base64 decode → `docker-compose.yml`
43+
- **배포 실행**: CI/CD 파이프라인에서 직접 실행
44+
- **헬스체크**: API 서버 응답 확인 (30회 재시도)
45+
46+
## 🛠️ 수동 배포
47+
48+
### 프로덕션 환경 수동 배포
49+
50+
```bash
51+
# 1. 최신 코드 가져오기
52+
git pull origin release
53+
54+
# 2. 환경 설정 파일 준비
55+
cp env.prod.example .env
56+
cp docker-compose.prod.yml docker-compose.yml
57+
58+
# 실제 환경변수 값으로 수정
59+
vi .env
60+
61+
# 3. 배포 스크립트 실행
62+
chmod +x deploy.sh
63+
./deploy.sh
64+
```
65+
66+
### 개발 환경 배포
67+
68+
```bash
69+
# 개발용 배포 스크립트 사용
70+
chmod +x deploy-dev.sh
71+
./deploy-dev.sh
72+
```
73+
74+
## 📋 배포 스크립트 상세
75+
76+
### `deploy.sh` (프로덕션)
77+
- **용도**: 프로덕션 환경 배포
78+
- **이미지**: GHCR에서 최신 이미지 풀
79+
- **헬스체크**: 30회 재시도 (최대 2.5분)
80+
- **로그**: 배포 후 최근 로그 20줄 출력
81+
82+
### `deploy-dev.sh` (개발)
83+
- **용도**: 로컬 개발 환경 배포
84+
- **이미지**: 로컬에서 빌드
85+
- **환경 파일**: `env.example`에서 자동 생성
86+
- **포트**: 7910 (API), Swagger UI 포함
87+
88+
## 🔧 배포 스크립트 수정
89+
90+
배포 로직을 수정하려면 repository의 `deploy.sh` 파일을 편집하세요:
91+
92+
```bash
93+
# 배포 스크립트 편집
94+
vi deploy.sh
95+
96+
# 변경사항 커밋
97+
git add deploy.sh
98+
git commit -m "배포 스크립트 업데이트"
99+
git push origin develop
100+
```
101+
102+
## 📊 모니터링 & 확인
103+
104+
### 배포 상태 확인
105+
```bash
106+
# 컨테이너 상태
107+
docker-compose ps
108+
109+
# 로그 확인
110+
docker-compose logs -f projectvg-api
111+
112+
# 헬스체크
113+
curl http://localhost:7910/health
114+
```
115+
116+
### 주요 엔드포인트
117+
- **API**: http://localhost:7910
118+
- **헬스체크**: http://localhost:7910/health
119+
- **Swagger**: http://localhost:7910/swagger (개발 환경)
120+
121+
## 🚨 트러블슈팅
122+
123+
### 배포 실패 시
124+
1. **로그 확인**: `docker-compose logs --tail=50`
125+
2. **컨테이너 상태**: `docker-compose ps`
126+
3. **이미지 확인**: `docker images | grep projectvg`
127+
4. **포트 충돌**: `netstat -tlnp | grep 7910`
128+
129+
### 롤백 방법
130+
```bash
131+
# 이전 이미지로 롤백 (태그 사용 시)
132+
docker-compose down
133+
docker-compose pull # 또는 특정 태그 지정
134+
docker-compose up -d
135+
```
136+
137+
## 🔐 보안 고려사항
138+
139+
### 환경 변수
140+
- `.env` 파일은 GitHub Secrets로 관리
141+
- 민감한 정보는 평문으로 저장하지 않음
142+
- 프로덕션과 개발 환경 분리
143+
144+
### Docker 이미지
145+
- GHCR을 통한 이미지 배포
146+
- 정기적인 base 이미지 업데이트
147+
- 보안 스캔 고려
148+
149+
## 📝 배포 히스토리
150+
151+
배포 이력은 GitHub Actions에서 확인할 수 있습니다:
152+
- **Repository****Actions****Release CI/CD**

0 commit comments

Comments
 (0)