Skip to content

Merge pull request #41 from BaeJunH0/feat/#37-cicd #4

Merge pull request #41 from BaeJunH0/feat/#37-cicd

Merge pull request #41 from BaeJunH0/feat/#37-cicd #4

Workflow file for this run

name: Deploy on Merge
on:
push:
branches:
- main # main 브랜치에 push될 때 실행
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. 저장소 클론
- name: Checkout repository
uses: actions/checkout@v3
# 2. Docker 로그인 (Docker Hub 또는 Private Registry)
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }} # GitHub Secrets에 설정
password: ${{ secrets.DOCKER_PASSWORD }} # GitHub Secrets에 설정
# 3. Docker 이미지 빌드 및 푸시
- name: Build and push Docker image
run: |
docker build -t baejunh0/myapp:latest .
docker push baejunh0/myapp:latest
# 4. 서버에 배포 스크립트 실행 (SSH 사용)
- name: Deploy to Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }} # 서버 IP
username: ${{ secrets.SERVER_USER }} # SSH 사용자
key: ${{ secrets.SERVER_SSH_KEY }} # SSH 개인 키 (GitHub Secrets에 설정)
port: 22
script: |
docker pull baejunh0/myapp:latest
docker stop myapp || true
docker rm myapp || true
docker run -d --name myapp -p 80:80 baejunh0/myapp:latest