diff --git a/.github/workflows/server-cd.yml b/.github/workflows/server-cd.yml index 6173278be..e807f4728 100644 --- a/.github/workflows/server-cd.yml +++ b/.github/workflows/server-cd.yml @@ -42,16 +42,29 @@ jobs: cd ./be/issue-tracker ./gradlew clean build -x test - # - name: Build Docker image - #run: | - #cd ./be/issue-tracker - #docker build --platform amd64 --build-arg DEPENDENCY=build/dependency --tag ${{ secrets.DOCKER_USERNAME }}/issue-tracker:1.0.1 . - # dockerfile을 통해 이미지를 빌드하고, 이를 docker repo로 push 합니다. - # 이 때 사용되는 ${{ secrets.DOCKER_REPO }}/directors-dev 가 위에서 만든 도커 repository 입니다. - name: Docker build & push to docker repo run: | cd ./be/issue-tracker docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:issue-tracker-dev . docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:issue-tracker-dev + + # 서버에 접속 후 Docker 이미지 가져와서 배포 + - name: SSH into Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + password: ${{ secrets.EC2_PRIVATE_KEY }} + port: 22 + script: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:issue-tracker-dev + # 기존에 실행 중인 컨테이너 중지 및 삭제 + if [ $(docker ps -q -f name=spring-server) ]; then + docker stop spring-server + docker rm spring-server + fi + # 새로운 컨테이너 실행 + docker run -d --name spring-server ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:issue-tracker-dev