Skip to content

Commit

Permalink
Update server-cd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
zzawang authored May 20, 2024
1 parent 4fcd4e5 commit b8596c6
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/server-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b8596c6

Please sign in to comment.