Skip to content

Merge branch 'main' of https://github.com/KUSITMS-30th-TEAM-C/frontend #4

Merge branch 'main' of https://github.com/KUSITMS-30th-TEAM-C/frontend

Merge branch 'main' of https://github.com/KUSITMS-30th-TEAM-C/frontend #4

Workflow file for this run

# 작업 모듈화
name: deploy next to ncloud
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
push_to_registry:
name: Push to mcp container registry
runs-on: ubuntu-latest
steps:
- name: Checkout # GitHub Action은 해당 프로젝트가 만들어진 환경에서 checkout하고 나서 실행
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: NCP 레지스트리 로그인
uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_ACCESS_KEY }}
- name: 도커 이미지 빌드 후 푸시
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/cnergy-frontend:${{ github.sha }} #깃허브 커밋 해시값으로 이미지 구분
pull_from_registry:
name: NCP 접속 후 이미지 다운로드 및 배포
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: ssh 연결
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NCP_HOST }}
username: ${{ secrets.NCP_USERNAME }}
password: ${{ secrets.NCP_PASSWORD }}
port: ${{ secrets.NCP_PORT }}
script: |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/cnergy-frontend:${{ github.sha }}
if [-z "$GITHUB_SHA" ]; then
echo "GITHUB_SHA 환경 변수가 설정되지 않았습니다. 최신 이미지를 사용합니다."
IMAGE_ID=$(docker images --format "{{.ID}}" | head -n 1)
else
echo "GITHUB_SHA: $GITHUB_SHA 이미지를 사용합니다."
IMAGE_ID=${{ secrets.NCP_CONTAINER_REGISTRY }}/cnergy-frontend:${{ github.sha }}
fi
docker stop cnergy-frontend || true
docker rm cnergy-frontend || true
docker run -d -p 80:3000 --name cnergy-frontend $IMAGE_ID
docker image prune -f