Chore: 워크플로우 수정 #15
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: 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: 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 # 새로운 컨테이너 시작 |