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

배포 스트립트 수정 #399

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions .github/workflows/server-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ jobs:
password: ${{ secrets.SERVER_SSH_PASSWORD }}
port: ${{ secrets.SERVER_SSH_PORT }}
script: |
NCP_REGISTRY=${{ secrets.NCP_REGISTRY }}
NCP_DOCKER_ACCESS_KEY_ID=${{ secrets.NCP_DOCKER_ACCESS_KEY_ID }}
NCP_DOCKER_SECRET_KEY=${{ secrets.NCP_DOCKER_SECRET_KEY }}
export NCP_REGISTRY=${{ secrets.NCP_REGISTRY }}
export NCP_DOCKER_ACCESS_KEY_ID=${{ secrets.NCP_DOCKER_ACCESS_KEY_ID }}
export NCP_DOCKER_SECRET_KEY=${{ secrets.NCP_DOCKER_SECRET_KEY }}
sh server/deploy.sh
curl -X POST -H 'Content-type: application/json' --data '{"text":"서버 배포 성공!"}' ${{ secrets.SLACK_WEBHOOK_URL }}
27 changes: 14 additions & 13 deletions server/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# blue 컨테이너가 띄워져 있는지 확인 (3000 포트 == blue)
EXIST_BLUE=$(sudo netstat -lntp | grep 3000)
EXIST_BLUE=$(netstat -lntp | grep 3000)

if [ -n "$EXIST_BLUE" ]; then
TARGET_COLOR="green"
Expand All @@ -20,15 +20,14 @@ else
NOW_SERVER_NAME="catchy-tape-green"
fi


# green의 경우 was 환경변수 PORT 변경
ENV_FILE="/server/prod.env"
PORT_CHANGE_FROM="PORT=3000"
PORT_CHANGE_TO="PORT=3001"
# ENV_FILE="/server/prod.env"
# PORT_CHANGE_FROM="PORT=3000"
# PORT_CHANGE_TO="PORT=3001"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 요 주석 부분은 지워서 커밋하고 머지해주실 수 있을까요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다!


if [ "$TARGET_COLOR" = "green" ]; then
sed -i "s/$PORT_CHANGE_FROM/$PORT_CHANGE_TO/" "$ENV_FILE"
fi
# if [ "$TARGET_COLOR" = "green" ]; then
# sed -i "s/$PORT_CHANGE_FROM/$PORT_CHANGE_TO/" "$ENV_FILE"
# fi

# 1 새로운 서버를 띄운다
docker login $NCP_REGISTRY -u $NCP_DOCKER_ACCESS_KEY_ID -p $NCP_DOCKER_SECRET_KEY
Expand All @@ -43,14 +42,16 @@ nginx -s reload
# 3 원래 서버 종료 & 삭제
FIRST_DEPLOYED_SERVER="catchy-tape-latest"
FIRST_DEPLOYED_SERVER_ID=$(docker ps --filter "name=$FIRST_DEPLOYED_SERVER" -q)
if ["$FIRST_DEPLYOED_SERVER_ID"]; then
docker stop $FIRST_DEPLOYED_SERVER_ID
docerk rm $FIRST_DEPLOYED_SERVER
if [ -n "$FIRST_DEPLOYED_SERVER_ID" ]; then
docker stop $FIRST_DEPLOYED_SERVER
docker rm $FIRST_DEPLOYED_SERVER
fi

STOP_SERVER_ID=$(docker ps --filter "name=$NOW_SERVER_NAME" -q)
docker stop $STOP_SERVER_ID
docker rm $NOW_SERVER_NAME
if [ -n "$STOP_SERVER_ID" ]; then
docker stop $STOP_SERVER_ID
docker rm $NOW_SERVER_NAME
fi

# 사용하지 않는 도커 이미지 정리
docker image prune -a -f
Loading