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
53 changes: 53 additions & 0 deletions .github/workflows/github-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI/CD with Docker

on:
push:
branches: [ "deploy" ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
# 1. Checkout the code from GitHub repository
- name: Checkout code
uses: actions/checkout@v3

# 2. Set up Docker Buildx (for multi-platform support)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# 3. Log in to DockerHub (if using DockerHub for image storage)
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# 4. Create .env file from GitHub Secrets
- name: Create .env file
run: echo "${{ secrets.ENV }}" > ./src/.env

# 5. Build and push Docker image
- name: Build & push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKER_REPO }}:latest

# 6. SSH to EC2 and deploy Docker container
- name: SSH to EC2 & deploy Docker container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker ps -qa | xargs -r sudo docker rm -f
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker run -d -p 8000:8000 ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM python:3.11

COPY ./src /src
WORKDIR /src
WORKDIR /code

RUN pip install -r requirements.txt
COPY ./src /code/src/

EXPOSE 8080
RUN pip install --no-cache-dir -r /code/src/requirements.txt

CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
# Upgrade pip to the latest version
RUN pip install --upgrade pip

EXPOSE 8000

CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
2 changes: 1 addition & 1 deletion src/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Settings(BaseSettings):
openai_api_key: str

class Config:
env_file = ".env"
env_file = "src/.env"

# 환경 변수 값 가져오기
settings = Settings()
Expand Down
Loading