Skip to content

Commit

Permalink
refactor: 다시 CD 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kanguk01 committed Nov 1, 2024
1 parent fc8191b commit 6417d6e
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,61 @@ jobs:
key: ${{ secrets.EC2_SSH_KEY }}
script: |
if sudo docker ps --filter "name=splanet_blue" --format "{{.Names}}" | grep -q "splanet_blue"; then
echo "blue" > current_version.txt
echo "blue" > /home/ubuntu/current_version.txt
elif sudo docker ps --filter "name=splanet_green" --format "{{.Names}}" | grep -q "splanet_green"; then
echo "green" > current_version.txt
echo "green" > /home/ubuntu/current_version.txt
else
echo "none" > current_version.txt
echo "none" > /home/ubuntu/current_version.txt
fi
cat current_version.txt
- name: Load Current Version
id: load_version
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
CURRENT_VERSION=$(cat /home/ubuntu/current_version.txt)
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Determine New Version
run: |
CURRENT_VERSION=$(cat current_version.txt)
echo "현재 버전은 $CURRENT_VERSION 입니다"
if [ "$CURRENT_VERSION" == "blue" ]; then
echo "NEW_VERSION=green" > new_version.txt
echo "NEW_PORT=8081" >> new_version.txt
if [ "${{ env.CURRENT_VERSION }}" == "blue" ]; then
echo "NEW_VERSION=green" >> $GITHUB_ENV
echo "NEW_PORT=8081" >> $GITHUB_ENV
elif [ "${{ env.CURRENT_VERSION }}" == "green" ]; then
echo "NEW_VERSION=blue" >> $GITHUB_ENV
echo "NEW_PORT=8080" >> $GITHUB_ENV
else
echo "NEW_VERSION=blue" > new_version.txt
echo "NEW_PORT=8080" >> new_version.txt
echo "NEW_VERSION=blue" >> $GITHUB_ENV
echo "NEW_PORT=8080" >> $GITHUB_ENV
fi
cat new_version.txt
- name: Print Current and New Version
run: |
echo "Current Version: $CURRENT_VERSION"
echo "New Version: $NEW_VERSION"
echo "New Port: $NEW_PORT"
- name: Deploy New Version to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
envs: |
IMAGE_TAG=${{ env.IMAGE_TAG }}
NEW_VERSION=${{ env.NEW_VERSION }}
NEW_PORT=${{ env.NEW_PORT }}
script: |
source new_version.txt # NEW_VERSION과 NEW_PORT 값을 불러옵니다
echo "새 버전 $NEW_VERSION, 포트 $NEW_PORT 에 배포를 시작합니다"
sudo docker pull kimsongmok/splanet:${{ env.IMAGE_TAG }}
sudo docker network inspect splanet >/dev/null 2>&1 || sudo docker network create splanet
sudo docker run -d --name splanet_$NEW_VERSION \
sudo docker run -d --name splanet_${{ env.NEW_VERSION }} \
--network splanet \
--env-file /home/ubuntu/env.properties \
-p $NEW_PORT:8080 --restart unless-stopped kimsongmok/splanet:${{ env.IMAGE_TAG }}
-p ${{ env.NEW_PORT }}:8080 --restart unless-stopped kimsongmok/splanet:${{ env.IMAGE_TAG }}
- name: Wait for Spring Boot Application to Start
uses: appleboy/[email protected]
Expand Down

0 comments on commit 6417d6e

Please sign in to comment.