Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore : 무중단 배포(blue-green) 스크립트 추가 및 서버 변경 #19

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
current_application_port=$(expr $application_port)

echo ${current_application_port}

green_application_port=0
green_application_name="green-application"
blue_application_name="blue-application"
temp_application_name="deprecated-application"

if [ "$current_application_port" -eq 8081 ]; then
green_application_port=8082
else
green_application_port=8081
fi

echo ${green_application_port}


echo $(docker pull wendyjihyo/github-actions-kobaco)

cmd=$(docker run -d -p ${green_application_port}:8080 --name ${green_application_name} --net application --env-file /home/ubuntu/.env wendyjihyo/github-actions-kobaco)

echo $(docker image prune -f)

echo ${cmd}

# 실행 되는지 확인 -> 확인이 health 채크가 완료되면 blue rename to deprecated-application -> green rename to blue -> nginx reload

application_status="FAIL"

for i in {1..10}; do
cmd=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${green_application_port}/health)

echo ${cmd}

if [ "$cmd" -eq 202 ]; then
application_status="SUCCESS"
break;
else
echo "fail"
sleep 10
fi
done

if [ "$application_staus" == "FAIL" ]; then
echo "application unhealty"
$(docker rm -f $green_application_name)
else
echo "reload processing"
echo "set "'$service_port'" ${green_application_port}" | sudo tee /home/ubuntu/nginx/conf/service-port.inc
export application_port=${green_application_port}
echo $(docker rename $blue_application_name $temp_application_name)
echo $(docker rename $green_application_name $blue_application_name)
echo $(docker exec -it nginx-nginx-1 service nginx reload)
echo $(docker rm -f $temp_application_name)
fi
12 changes: 4 additions & 8 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ jobs:
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-kobaco


- name: docker compose push
- name: deploy script push
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_SSH_HOST }}
username: ubuntu
key: ${{ secrets.REMOTE_SSH_KEY }}
source: "./.deploy/docker-compose.yml"
target: "/home/ubuntu"
source: "./.deploy/deploy.sh"
target: "/home/ubuntu/deploy"
strip_components: 2

- name: execute remote ssh
Expand All @@ -76,8 +76,4 @@ jobs:
echo "AWS_REGION=${{secrets.AWS_REGION}}" >> .env
echo "AWS_S3_BUCKET=${{secrets.AWS_S3_BUCKET}}" >> .env

sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-kobaco
sudo docker stop kobaco
sudo docker rm kobaco
sudo docker compose up -d
sudo docker image prune -f
cd /deploy && . deploy.sh
Loading