service PUT api 수정 (suspend 필드 업데이트 추가), 테스트 코드 추가 #137
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check code quality, run test code and Deploy to Amazon ECR | |
on: | |
pull_request: | |
branches: | |
- upcy-14th-backend-dev | |
types: | |
- opened | |
- synchronize | |
- closed | |
jobs: | |
test: | |
if: github.event_name == 'pull_request' && github.event.action != 'closed' | |
name: Django API Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: 코드 Checkout | |
uses: actions/checkout@v4 | |
- uses: actions/setup-python@v3 | |
with: | |
python-version: "3.12" | |
- name: Poetry 설치 | |
run: | | |
curl -sSL https://install.python-poetry.org | python3 - | |
export PATH="$HOME/.local/bin:$PATH" | |
- name: 의존성 설치 | |
run: | | |
poetry install --no-root | |
shell: bash | |
- name: 코드 스타일 검사 (isort) # 여기서 오류뜨면 로컬 콘솔에서 isort . 입력해주세요 | |
run: | | |
poetry run isort . --check-only | |
- name: 코드 스타일 검사 (black) # 여기서 오류뜨면 로컬 콘솔에서 black . 입력해주세요 | |
run: | | |
poetry run black . --check | |
- name: Django 테스트 실행 | |
env: | |
DJANGO_SETTINGS_MODULE: "config.settings" | |
DJANGO_DEBUG_MODE: true | |
UPCY_SECRET_KEY: "test123123123123123123123" # 진짜 SECRET 키 아닙니다. | |
run: | | |
poetry run python manage.py migrate # 데이터베이스 마이그레이션 | |
poetry run python manage.py test # Django 전체 테스트 실행 | |
deploy: | |
name: Deploy Docker image to ECR and Run docker image in EC2 instance | |
# PR이 머지되었을 때만 실행 | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: 코드 Checkout | |
uses: actions/checkout@v4 | |
- name: AWS Credentials 가져오기 | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: AWS ECR 로그인 | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: 백엔드 도커 이미지 생성 및 배포 | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
# 도커 이미지 생성 | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest . | |
# ECR로 도커 이미지 PUSH | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
- name: EC2에 배포 및 백엔드 어플리케이션 실행 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: ./deploy.sh | |
- name: 배포 결과 확인 | |
if: always() | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
# 컨테이너 상태 확인 | |
if docker ps | grep -q "${{ secrets.ECR_REPOSITORY_NAME }}"; then | |
echo "Container is running successfully" | |
exit 0 | |
else | |
echo "Container is not running" | |
exit 1 | |
fi |