Merge branch 'main' of https://github.com/YBIGTA/26th-project-BookPro… #17
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: Build and Deploy | |
on: | |
push: | |
branches: [ main ] # main 브랜치에 push 시 동작 | |
jobs: | |
build: | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Login to Docker Registry | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p echo ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker Image | |
run: | | |
docker build -f app/Dockerfile -t my-docker-image:${{ github.sha }} . | |
- name: Push Docker Image | |
run: | | |
docker push my-docker-image:${{ github.sha }} | |
deploy: | |
needs: build | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Deploy to EC2 via SSH | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} # 예: 3.34.178.2 | |
username: ${{ secrets.EC2_USER }} # 예: ubuntu | |
key: ${{ secrets.EC2_SSH_KEY }} # PEM 파일 내용 | |
script: | | |
docker pull my-docker-image:${{ github.sha }} | |
docker stop my-container || true | |
docker rm my-container || true | |
docker run -d --name my-container -p 80:80 my-docker-image:${{ github.sha }} |