Skip to content

Commit

Permalink
feat: 실패시 롤백
Browse files Browse the repository at this point in the history
  • Loading branch information
sjy2335 committed Nov 11, 2024
1 parent d5cee73 commit 1e2c513
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/deploy-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Verify SSH Key Presence
run: |
if [ -z "${{ secrets.key }}" ]; then
echo "SSH key is missing!"
exit 1
fi
echo "${{ secrets.key }}" | grep "BEGIN" || { echo "SSH key format is incorrect!"; exit 1; }
# 1. Sparse checkout으로 하위 디렉토리만 체크아웃
- name: Checkout repository with sparse checkout
uses: actions/checkout@v3
Expand All @@ -53,7 +46,10 @@ jobs:
# 3. 도커 이미지 빌드 & 푸시
- name: Build and push Docker image for ${{ inputs.service }}
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:latest ./${{inputs.service}}/${{inputs.path}}
TAG=$(date +%Y%m%d%H%M%S)
docker build -t ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:${TAG} ./${{inputs.service}}/${{inputs.path}}
docker push ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:${TAG}
docker tag ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:${TAG} ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:latest
docker push ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:latest
# 4. 각 서비스 서버에 배포
Expand All @@ -68,4 +64,12 @@ jobs:
cd /home/watchducks/app
echo "${{ secrets.env }}" > .env
docker pull ghcr.io/${{ github.repository_owner }}/${{ inputs.service }}/${{inputs.path}}:latest
docker-compose up -d
if docker-compose up -d; then
echo "Deployment successful"
else
echo "Deployment failed, rolling back"
docker-compose down
docker pull ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:previous-tag
docker-compose up -d
exit 1
fi

0 comments on commit 1e2c513

Please sign in to comment.