diff --git a/.github/workflows/nodejs-ci.yml b/.github/workflows/nodejs-ci.yml index d81b8ad..058e6d8 100644 --- a/.github/workflows/nodejs-ci.yml +++ b/.github/workflows/nodejs-ci.yml @@ -26,8 +26,8 @@ jobs: - name: Install dependencies run: npm install - # - name: Build project - # run: npm run build + - name: Build project + run: npm run build # 프로젝트 빌드 명령 추가 docker-build: runs-on: ubuntu-latest @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest needs: docker-build steps: - - name: deploy + - name: Deploy to server uses: appleboy/ssh-action@master with: username: ubuntu @@ -62,14 +62,19 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} port: ${{ secrets.WAS_PORT }} script: | + # 기존 컨테이너가 실행 중이면 종료하고 삭제 CONTAINER_ID=$(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) if [ ! -z "$CONTAINER_ID" ]; then sudo docker stop $CONTAINER_ID sudo docker rm $CONTAINER_ID fi - sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} - sudo docker run -d -p 9000:9000 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} + # 최신 이미지를 가져와서 실행 + sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}:latest + sudo docker run -d -p 9000:9000 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}:latest + + # 로그 확인 sudo docker logs $(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) + # 사용하지 않는 도커 이미지 제거 sudo docker image prune -f