Skip to content

Commit

Permalink
reafactor: CD 배포 스크립트 구문 수정
Browse files Browse the repository at this point in the history
더 정확하게
  • Loading branch information
kanguk01 committed Nov 1, 2024
1 parent 3c4bdd8 commit 6943421
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- develop
- feat/96-feature-bluegreen

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Decode env.properties from GitHub Secrets
run: |
echo "${{ secrets.ENV_FILE }}" | base64 --decode > ./env.properties
- name: Decode Firebase config from GitHub Secrets
run: |
echo "${{ secrets.FIREBASE_CONFIG }}" | base64 --decode > ./splanet-firebase.json
Expand Down Expand Up @@ -67,11 +67,11 @@ jobs:
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if sudo docker ps --filter "name=splanet_blue" --format "{{.Names}}" | grep -q "splanet_blue"; then
echo "::set-output name=version::blue"
echo "CURRENT_VERSION=blue" >> $GITHUB_ENV
elif sudo docker ps --filter "name=splanet_green" --format "{{.Names}}" | grep -q "splanet_green"; then
echo "::set-output name=version::green"
echo "CURRENT_VERSION=green" >> $GITHUB_ENV
else
echo "::set-output name=version::none"
echo "CURRENT_VERSION=none" >> $GITHUB_ENV
fi
- name: Deploy New Version to EC2
Expand All @@ -81,7 +81,7 @@ jobs:
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if [ "${steps.current_version.outputs.version}" == "blue" ]; then
if [ "${{ env.CURRENT_VERSION }}" == "blue" ]; then
NEW_VERSION="green"
NEW_PORT=8081
else
Expand All @@ -102,12 +102,12 @@ jobs:
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if [ "${steps.current_version.outputs.version}" == "blue" ]; then
if [ "${{ env.CURRENT_VERSION }}" == "blue" ]; then
NEW_PORT=8081
else
NEW_PORT=8080
fi
echo "Waiting for the application to be healthy on http://api.splanet.co.kr:${NEW_PORT}/actuator/health..."
for i in {1..30}; do
if curl -s http://api.splanet.co.kr:${NEW_PORT}/actuator/health | grep '"status":"UP"' > /dev/null; then
Expand All @@ -117,8 +117,7 @@ jobs:
echo "Waiting for application to start... (Attempt $i)"
sleep 5
done
# If the application is not healthy after 40 attempts (200 seconds), fail the deployment
if [ "$i" -eq 30 ]; then
echo "Application did not start successfully within the expected time."
sudo docker logs splanet_${NEW_VERSION}
Expand All @@ -132,7 +131,7 @@ jobs:
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if [ "${{ steps.current_version.outputs.version }}" == "blue" ]; then
if [ "${{ env.CURRENT_VERSION }}" == "blue" ]; then
TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-8081/${{ secrets.ARN_ID_8081 }}"
else
TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet/${{ secrets.ARN_ID_8080 }}"
Expand All @@ -147,12 +146,11 @@ jobs:
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if [ "${{ steps.current_version.outputs.version }}" != "none" ]; then
sudo docker stop splanet_${{ steps.current_version.outputs.version }}
sudo docker rm splanet_${{ steps.current_version.outputs.version }}
if [ "${{ env.CURRENT_VERSION }}" != "none" ]; then
sudo docker stop splanet_${{ env.CURRENT_VERSION }}
sudo docker rm splanet_${{ env.CURRENT_VERSION }}
fi
- name: Clean up old Docker images
uses: appleboy/[email protected]
with:
Expand Down

0 comments on commit 6943421

Please sign in to comment.