Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/build_release_and_notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,27 @@ jobs:
echo "EXE_NAME=qgenie-api.exe" >> $GITHUB_ENV
fi

# 6. PyInstaller를 사용해 파이썬 코드를 실행 파일로 만듭니다.
- name: Build executable with PyInstaller
# 6. 실행파일에 생성할 env파일 추가
- name: Create .env file
shell: bash
env:
ENV_AES256_KEY: ${{ secrets.ENV_AES256_KEY }}
ENV_AI_SERVER_URL: ${{ secrets.ENV_AI_SERVER_URL }}
run: |
# app/assets 폴더가 없으면 생성합니다.
mkdir -p app/assets
# GitHub Secrets의 값을 .env 파일에 씁니다.
echo "ENV_AES256_KEY=${ENV_AES256_KEY}" > app/assets/.env
echo "ENV_AI_SERVER_URL=${ENV_AI_SERVER_URL}" >> app/assets/.env
echo ".env file created successfully."
cat app/assets/.env # 생성된 내용을 확인하기 위해 로그 출력

# 7. PyInstaller를 사용해 파이썬 코드를 실행 파일로 만듭니다.
- name: Build executable with PyInstaller
shell: bash
run: poetry run pyinstaller --clean --additional-hooks-dir ./hooks --add-data "app/assets:assets" --paths . --onefile --name ${{ env.EXE_NAME }} app/main.py

# 7. 빌드된 실행 파일을 다음 단계(deploy)에서 사용할 수 있도록 아티팩트로 업로드합니다.
# 8. 빌드된 실행 파일을 다음 단계(deploy)에서 사용할 수 있도록 아티팩트로 업로드합니다.
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ build/
*.egg-info/

# 환경 변수 파일 (보안 이슈)
.env # 환경 변수 파일
app/assets/.env
.env.*

# Jupyter Notebook 체크포인트 (혹시 사용 시)
Expand Down
25 changes: 23 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# main.py
# [추가] .env 파일 로드를 위한 모듈 임포트
import os
import sys

import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from starlette.middleware.base import BaseHTTPMiddleware

from app.api import health_api
from app.api.api_router import api_router
from app.core.all_logging import log_requests_middleware
from app.core.exceptions import (
APIException,
api_exception_handler,
Expand All @@ -14,8 +20,23 @@
)
from app.db.init_db import initialize_database

from starlette.middleware.base import BaseHTTPMiddleware
from app.core.all_logging import log_requests_middleware

# 실행 파일 내부에서 assets 폴더 경로를 찾는 로직
def resource_path(relative_path: str) -> str:
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_path, relative_path)


# 애플리케이션 시작 전 .env 파일 로드
env_path = resource_path("assets/.env")
if os.path.exists(env_path):
load_dotenv(dotenv_path=env_path)
print(f".env 파일을 성공적으로 로드했습니다: {env_path}")
else:
print(f"경고: .env 파일을 찾을 수 없습니다. ({env_path})")

app = FastAPI()

Expand Down