[FIX] CD 플로우 수정 (#23) #6
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: CD | |
# 주석 처리된 원본 내용 | |
# on: | |
# workflow_dispatch: | |
# pull_request: | |
# types: [closed] | |
# branches: [develop] | |
on: | |
pull_request: | |
branches: ["develop"] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
# 주석 처리된 원본 조건 | |
# if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
# 저장소 체크아웃 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Docker Buildx 설정 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
# DockerHub 로그인 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker 이미지 빌드 및 푸시 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/dev:latest | |
# SSH 키 추가 | |
- name: Add SSH key | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# 서버에 배포 | |
- name: Deploy to server | |
run: | | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' | |
docker pull ${{ secrets.DOCKER_USERNAME }}/dev:latest | |
docker stop app || true | |
docker rm app || true | |
docker run -d --name app -p 80:80 ${{ secrets.DOCKER_USERNAME }}/dev:latest | |
docker image prune -f | |
EOF | |