Skip to content

Chore: 워크 플로우 수정 #16

Chore: 워크 플로우 수정

Chore: 워크 플로우 수정 #16

Workflow file for this run

name: Deploy to EC2 with Docker Compose
on:
push:
branches: ["main"] # main 브랜치에 푸시될 때 트리거
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew build # JAR 파일 생성
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/akoming-test:latest .
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/akoming-test:latest
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "docker-compose.yml" # 로컬에 있는 docker-compose.yml
target: "/home/ubuntu/docker-compose.yml" # EC2에 복사될 경로
- name: Deploy on EC2 with Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
cd /home/ubuntu
sudo docker-compose down # 기존 컨테이너 중지
sudo docker-compose pull # 최신 이미지 가져오기
sudo docker-compose up -d # 새로운 컨테이너 시작