-
Notifications
You must be signed in to change notification settings - Fork 0
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
로컬에서 도커 환경 구성을 위한 셋업 진행 #5
Open
yoonseo-han
wants to merge
1
commit into
dev
Choose a base branch
from
env/local-cloud-sync
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/bin/bash | ||
|
||
# healthy 상태 대기 | ||
waiting() { | ||
while true; do | ||
health_status_server=$(docker inspect --format '{{.State.Health.Status}}' server-$1) | ||
|
||
if [ "$health_status_server" != "starting" ]; then | ||
echo "$health_status_server" | ||
return 0 | ||
fi | ||
|
||
sleep 5 | ||
done | ||
} | ||
|
||
# nginx 설정 업데이트 및 리로드 함수 | ||
update_and_reload_nginx() { | ||
local target=$1 | ||
NGINX_CONFIG="nginx/conf.d/default.conf" | ||
|
||
BACK_END_BLUE="server-blue:3000" | ||
BACK_END_GREEN="server-green:3000" | ||
echo "Updating nginx configuration for $target environment..." | ||
|
||
# 파일 업데이트 | ||
echo $target | ||
# 리눅스 방식 | ||
# if [ "$target" == "green" ]; then | ||
# docker exec nginx sh -c "sed -i 's|server server-.*;|server $BACK_END_GREEN;|g' /etc/nginx/conf.d/default.conf" | ||
# else | ||
# docker exec nginx sh -c "sed -i 's|server server-.*;|server $BACK_END_BLUE;|g' /etc/nginx/conf.d/default.conf" | ||
# fi | ||
|
||
if [ "$target" == "green" ]; then | ||
# MacOS 방식 | ||
sed -i '' "s|server server-.*;|server $BACK_END_GREEN;|g" "$NGINX_CONFIG" | ||
else | ||
sed -i '' "s|server server-.*;|server $BACK_END_BLUE;|g" "$NGINX_CONFIG" | ||
fi | ||
|
||
# nginx 컨테이너 재시작 | ||
echo "Restarting nginx to apply new configuration..." | ||
docker exec nginx nginx -s reload | ||
|
||
# 설정이 제대로 적용되었는지 확인 | ||
sleep 2 | ||
docker exec nginx nginx -t | ||
} | ||
|
||
# Blue에서 Green으로 전환 | ||
switch_to_green() { | ||
echo "Deploying Green environment..." | ||
|
||
cd ../../../ | ||
|
||
# Green 환경 시작 | ||
docker compose -f docker-compose-green.yml up -d | ||
|
||
health_status_server=$(waiting "green") | ||
echo $health_status_server | ||
if [ "$health_status_server" == "healthy" ]; then | ||
echo "Green server is healthy. Stopping and removing..." | ||
# nginx 설정 업데이트 및 리로드 | ||
update_and_reload_nginx "green" | ||
|
||
echo "Stopping Blue server..." | ||
if docker ps -q --filter name=server-blue > /dev/null; then | ||
docker stop server-blue | ||
docker rm server-blue | ||
fi | ||
else | ||
echo "Green server is not Healthy" | ||
docker stop server-green | ||
docker rm server-green | ||
fi | ||
} | ||
# Green에서 Blue로 전환 | ||
switch_to_blue() { | ||
echo "Deploying Blue environment..." | ||
|
||
cd ../../../ | ||
|
||
# Blue 환경 시작 | ||
docker compose -f docker-compose-blue.yml up -d | ||
|
||
health_status_server=$(waiting "blue") | ||
echo $health_status_server | ||
if [ "$health_status_server" == "healthy" ]; then | ||
echo "Blue server is healthy. Stopping and removing..." | ||
|
||
# nginx 설정 업데이트 및 리로드 | ||
update_and_reload_nginx "blue" | ||
|
||
echo "Stopping Green server..." | ||
if docker ps -q --filter name=server-green > /dev/null; then | ||
docker stop server-green | ||
docker rm server-green | ||
fi | ||
else | ||
echo "Blue server is not Healthy" | ||
docker stop server-blue | ||
docker rm server-blue | ||
fi | ||
} | ||
|
||
# 현재 실행 중인 환경 확인 및 전환 | ||
if [ -n "$(docker ps -q --filter name=blue)" ]; then | ||
switch_to_green | ||
echo "switch_to_green 실행" | ||
else | ||
switch_to_blue | ||
echo "switch_to_blue 실행" | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
NGINX_CONFIG="nginx/conf.d/default.conf" | ||
|
||
# nginx 설정 업데이트 및 리로드 함수 | ||
update_and_reload_nginx() { | ||
local target=$1 | ||
|
||
echo "Updating nginx configuration for $target environment..." | ||
|
||
# 파일 업데이트 | ||
echo $target | ||
if [ "$target" == "green" ]; then | ||
rm -rf nginx/html/dist-green | ||
cp -r nginx/html/dist nginx/html/dist-green | ||
sed -i "s|root /usr/share/nginx/html.*;|root /usr/share/nginx/html/dist-green;|g" $NGINX_CONFIG | ||
else | ||
rm -rf nginx/html/dist-blue | ||
cp -r nginx/html/dist nginx/html/dist-blue | ||
sed -i "s|root /usr/share/nginx/html.*;|root /usr/share/nginx/html/dist-blue;|g" $NGINX_CONFIG | ||
fi | ||
|
||
# nginx 컨테이너 재시작 | ||
echo "Restarting nginx to apply new configuration..." | ||
docker exec nginx nginx -s reload | ||
|
||
# 설정이 제대로 적용되었는지 확인 | ||
sleep 2 | ||
docker exec nginx nginx -t | ||
} | ||
|
||
# Blue에서 Green으로 전환 | ||
switch_to_green() { | ||
echo "Deploying Green environment..." | ||
|
||
cd ../../../ | ||
# nginx 설정 업데이트 및 리로드 | ||
update_and_reload_nginx "green" | ||
|
||
} | ||
# Green에서 Blue로 전환 | ||
switch_to_blue() { | ||
echo "Deploying Blue environment..." | ||
|
||
cd ../../../ | ||
|
||
# nginx 설정 업데이트 및 리로드 | ||
update_and_reload_nginx "blue" | ||
} | ||
|
||
# 현재 실행 중인 환경 확인 및 전환 | ||
if [ -n "$(cat $NGINX_CONFIG | grep html/dist-blue)" ]; then | ||
switch_to_green | ||
echo "switch_to_green 실행" | ||
else | ||
switch_to_blue | ||
echo "switch_to_blue 실행" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
networks: | ||
webapp: | ||
external: true | ||
|
||
services: | ||
server-blue: | ||
image: "inear-server:latest" | ||
container_name: server-blue | ||
env_file: | ||
- ./env/server.env | ||
environment: | ||
- NODE_ENV=development | ||
- TZ=Asia/Seoul | ||
networks: | ||
- webapp | ||
restart: unless-stopped | ||
healthcheck: | ||
test: ["CMD-SHELL", "wget -q --spider http://server-blue:3000/api/health || exit 1"] | ||
interval: 7s | ||
timeout: 10s | ||
retries: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
networks: | ||
webapp: | ||
external: true | ||
|
||
services: | ||
server-green: | ||
image: "inear-server:latest" | ||
container_name: server-green | ||
env_file: | ||
- ./env/server.env | ||
environment: | ||
- NODE_ENV=development | ||
- TZ=Asia/Seoul | ||
networks: | ||
- webapp | ||
restart: unless-stopped | ||
healthcheck: | ||
test: ["CMD-SHELL", "wget -q --spider http://server-green:3000/api/health || exit 1"] | ||
interval: 7s | ||
timeout: 10s | ||
retries: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
networks: | ||
webapp: | ||
name: webapp | ||
|
||
services: | ||
nginx: | ||
image: "inear-nginx:latest" | ||
container_name: nginx | ||
env_file: | ||
- ./env/client.env | ||
volumes: | ||
- ./nginx/conf.d:/etc/nginx/conf.d:ro | ||
ports: | ||
- '80:80' | ||
networks: | ||
- webapp | ||
restart: unless-stopped |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 env 디렉토리는 로컬에서도 사용되는 건가요~?