Skip to content

Commit 82cc2ec

Browse files
authored
Merge pull request #18 from lion4thon/feat/api-AiRecommendPass
Feat/api ai recommend pass
2 parents 0bab515 + 951f4ca commit 82cc2ec

39 files changed

+3401
-33
lines changed

.github/workflows/cd.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
runs-on: ubuntu-latest
1414
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1515
env:
16-
IMAGE_NAME: mov-api
16+
SPRING_IMAGE_NAME: mov-api
17+
FASTAPI_IMAGE_NAME: mov-fastapi
1718
steps:
1819
- name: Deploy to EC2
1920
uses: appleboy/ssh-action@master
@@ -24,27 +25,41 @@ jobs:
2425
script: |
2526
# 環境 변수 설정
2627
DOCKER_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
27-
IMAGE_NAME=${{ env.IMAGE_NAME }}
28-
CONTAINER_NAME=mov-api
28+
SPRING_IMAGE_NAME=${{ env.SPRING_IMAGE_NAME }}
29+
FASTAPI_IMAGE_NAME=${{ env.FASTAPI_IMAGE_NAME }}
30+
SPRING_CONTAINER_NAME=mov-api
31+
FASTAPI_CONTAINER_NAME=mov-fastapi
2932
ENV_FILE_PATH=/home/${{ secrets.EC2_USERNAME }}/.env
3033
31-
echo "CI/CD: [1/5] Creating .env file..."
34+
echo "CI/CD: [1/8] Creating .env file..."
3235
echo "${{ secrets.ENV_FILE }}" > $ENV_FILE_PATH
3336
34-
echo "CI/CD: [2/5] Pulling latest Docker image..."
35-
docker pull $DOCKER_USERNAME/$IMAGE_NAME:latest
37+
echo "CI/CD: [2/8] Pulling latest Spring Boot Docker image..."
38+
docker pull $DOCKER_USERNAME/$SPRING_IMAGE_NAME:latest
3639
37-
echo "CI/CD: [3/5] Stopping and removing existing container..."
38-
docker stop $CONTAINER_NAME || true
39-
docker rm $CONTAINER_NAME || true
40+
echo "CI/CD: [3/8] Stopping and removing existing Spring Boot container..."
41+
docker stop $SPRING_CONTAINER_NAME || true
42+
docker rm $SPRING_CONTAINER_NAME || true
4043
41-
echo "CI/CD: [4/5] Starting new container..."
42-
docker run -d --name $CONTAINER_NAME \
44+
echo "CI/CD: [4/8] Starting new Spring Boot container..."
45+
docker run -d --name $SPRING_CONTAINER_NAME \
4346
--env-file $ENV_FILE_PATH \
4447
-p 8080:8080 \
45-
$DOCKER_USERNAME/$IMAGE_NAME:latest
48+
$DOCKER_USERNAME/$SPRING_IMAGE_NAME:latest
4649
47-
echo "CI/CD: [5/5] Cleaning up unused images..."
50+
echo "CI/CD: [5/8] Pulling latest FastAPI Docker image..."
51+
docker pull $DOCKER_USERNAME/$FASTAPI_IMAGE_NAME:latest
52+
53+
echo "CI/CD: [6/8] Stopping and removing existing FastAPI container..."
54+
docker stop $FASTAPI_CONTAINER_NAME || true
55+
docker rm $FASTAPI_CONTAINER_NAME || true
56+
57+
echo "CI/CD: [7/8] Starting new FastAPI container..."
58+
docker run -d --name $FASTAPI_CONTAINER_NAME \
59+
-p 8000:8000 \
60+
$DOCKER_USERNAME/$FASTAPI_IMAGE_NAME:latest
61+
62+
echo "CI/CD: [8/8] Cleaning up unused images..."
4863
docker image prune -f
4964
5065
echo "CI/CD: Deployment complete."

.github/workflows/ci.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ on:
77
branches: [ "main" ]
88
workflow_dispatch: # Actions 탭에서 수동 실행 버튼 제공(필요할 때 수동으로 돌릴 수 있게)
99
env:
10-
IMAGE_NAME: mov-api
10+
SPRING_IMAGE_NAME: mov-api
11+
FASTAPI_IMAGE_NAME: mov-fastapi
1112

1213
jobs:
13-
build-and-push:
14+
build-spring-boot:
1415
runs-on: ubuntu-latest
1516
steps:
1617
- name: Checkout
@@ -22,10 +23,30 @@ jobs:
2223
username: ${{ secrets.DOCKERHUB_USERNAME }}
2324
password: ${{ secrets.DOCKERHUB_TOKEN }}
2425

25-
- name: Build and conditionally push Docker image
26+
- name: Build and conditionally push Spring Boot Docker image
2627
uses: docker/build-push-action@v4
2728
with:
2829
context: .
2930
# main 브랜치에 push될 때만 Docker Hub에 이미지를 푸시합니다.
3031
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
31-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
32+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.SPRING_IMAGE_NAME }}:latest
33+
34+
build-fastapi:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
40+
- name: Login to Docker Hub
41+
uses: docker/login-action@v2
42+
with:
43+
username: ${{ secrets.DOCKERHUB_USERNAME }}
44+
password: ${{ secrets.DOCKERHUB_TOKEN }}
45+
46+
- name: Build and conditionally push FastAPI Docker image
47+
uses: docker/build-push-action@v4
48+
with:
49+
context: ./ai_recommendation
50+
# main 브랜치에 push될 때만 Docker Hub에 이미지를 푸시합니다.
51+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
52+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.FASTAPI_IMAGE_NAME }}:latest

ai_recommendation/.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Python
2+
venv/
3+
__pycache__/
4+
*.pyc
5+
*.pyo
6+
*.pyd
7+
.Python
8+
*.so
9+
*.egg
10+
*.egg-info/
11+
dist/
12+
build/
13+
14+
# IDE
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
20+
# OS
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Git
25+
.git/
26+
.gitignore
27+
28+
# Testing
29+
.pytest_cache/
30+
.coverage
31+
htmlcov/
32+
33+
# Logs
34+
*.log

ai_recommendation/.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
*.egg
7+
*.egg-info/
8+
dist/
9+
build/
10+
*.whl
11+
12+
# Virtual Environment
13+
venv/
14+
env/
15+
ENV/
16+
.venv
17+
18+
# IDE
19+
.vscode/
20+
.idea/
21+
*.swp
22+
*.swo
23+
*~
24+
.DS_Store
25+
26+
# Jupyter Notebook
27+
.ipynb_checkpoints
28+
29+
# Testing
30+
.pytest_cache/
31+
.coverage
32+
htmlcov/
33+
*.cover
34+
.hypothesis/
35+
36+
# Logs
37+
*.log
38+
logs/
39+
40+
# Environment variables
41+
.env
42+
.env.local
43+
44+
# Model files (선택적 - 학습된 모델을 Git에서 제외하려면 주석 해제)
45+
# models/*.cbm
46+
# models/*.pkl
47+
48+
# Data files (선택적 - 대용량 데이터를 제외하려면 주석 해제)
49+
# data/*.csv
50+
# data/*.json
51+
52+
# Temporary files
53+
*.tmp
54+
*.bak
55+
*.cache

ai_recommendation/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# FastAPI 추천 시스템 Docker 이미지
2+
FROM python:3.9-slim
3+
4+
WORKDIR /app
5+
6+
# 시스템 패키지 업데이트 및 필수 도구 설치
7+
RUN apt-get update && apt-get install -y \
8+
gcc \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Python 의존성 설치
12+
COPY requirements.txt .
13+
RUN pip install --no-cache-dir -r requirements.txt
14+
15+
# 애플리케이션 코드 복사
16+
COPY . .
17+
18+
# 포트 노출
19+
EXPOSE 8000
20+
21+
# FastAPI 서버 실행
22+
CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)