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/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI/CD pipeline test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]


env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
DOCKER_REPO: ${{ secrets.DOCKER_REPO }}
AWS_HOST: ${{ secrets.AWS_HOST }}
AWS_SSH_KEY: ${{ secrets.AWS_SSH_KEY }}
AWS_USER: ${{ secrets.AWS_USER }}


jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Login to Docker Hub
run: |
docker login -u ${{ env.DOCKER_HUB_USERNAME }} -p ${{ env.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push Docker image
run: |
docker build -t ${{ env.DOCKER_REPO }}:latest .
docker push ${{ env.DOCKER_REPO }}:latest

deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: EC2 Docker Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ env.AWS_HOST }}
username: ${{ env.AWS_USER }}
key: ${{ env.AWS_SSH_KEY }}
script: |
cd git-action-test/
sed -i 's|image:.*|image: '"${{ env.DOCKER_REPO }}:latest"'|' docker-compose.yaml
docker-compose down
docker-compose pull
docker-compose up -d
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 1. 베이스 이미지로 Python 3.9 선택
FROM python:3.9-slim

# 2. 작업 디렉토리 생성
WORKDIR /app

# 3. 요구 사항 파일 복사
COPY requirements.txt /app/

# 4. 의존성 설치
RUN pip install --no-cache-dir -r requirements.txt

# 5. 애플리케이션 코드 복사
COPY . /app/

# 6. FastAPI 서버 실행 (Uvicorn 사용)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Loading