Update README.md #47
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: Hallyugo-backend dev CI/CD Pipeline | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 코드 체크아웃 | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
# JDK 설치 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 21 | |
# Gradle Build (backend 디렉토리에서 실행) | |
- name: Build with Gradle | |
working-directory: ./backend | |
run: ./gradlew build --exclude-task test | |
# DockerHub 로그인 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
# DockerHub Push (backend 디렉토리에서 Dockerfile 빌드) | |
- name: Build and Push Docker image | |
working-directory: ./backend | |
run: | | |
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_HUB_USERNAME }}/hallyugo-backend . | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/hallyugo-backend | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# AWS 배포 | |
- name: SSH to EC2 and deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
# 기존 컨테이너 중지 및 삭제 | |
cd /home/${{ secrets.EC2_USERNAME }}/hallyugo-server | |
sudo docker-compose stop | |
sudo docker-compose rm -f | |
sudo docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/hallyugo-backend:latest | |
# 최신 이미지를 받아서 Docker Compose로 재시작 | |
sudo docker-compose pull | |
sudo docker-compose up -d |