-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35460b2
commit 0a52500
Showing
8 changed files
with
57 additions
and
79 deletions.
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
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,8 @@ | ||
### Docker 이미지를 생성할 때 기반이 되는 베이스 이미지를 설정한다. | ||
FROM openjdk:17-alpine | ||
### Dockerfile 내에서 사용할 변수 JAR_FILE을 정의한다. | ||
ARG JAR_FILE=build/libs/*.jar | ||
### JAR_FILE 경로에 해당하는 파일을 Docker 이미지 내부로 복사한다. | ||
COPY ${JAR_FILE} dnd-9th-1-backend.jar | ||
### Docker 컨테이너가 시작될 때 실행할 명령을 지정한다. | ||
ENTRYPOINT ["java","-jar","-Dspring.profiles.active=prod", "dnd-9th-1-backend.jar"] |
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,11 @@ | ||
version: '3' | ||
services: | ||
blue: # service_name | ||
build: ./ # Dockerfile path | ||
image: ${DOCKER_REGISTRY}/${DOCKER_APP_NAME}:${IMAGE_TAG} | ||
container_name: ${DOCKER_APP_NAME}-blue # | ||
environment: | ||
- LANG=ko_KR.UTF-8 | ||
- | ||
ports: | ||
- '8081:80' |
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,10 @@ | ||
version: '3' | ||
services: | ||
green: | ||
build: ./ | ||
image: | ||
container_name: ${DOCKER_APP_NAME}-green | ||
environment: | ||
- LANG=ko_KR.UTF-8 | ||
ports: | ||
- '8082:80' |
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 |
---|---|---|
@@ -1,30 +1,36 @@ | ||
#!/bin/bash | ||
|
||
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1) | ||
TARGET_PORT=0 | ||
cd /home/ubuntu/app | ||
DOCKER_APP_NAME=milestone | ||
|
||
echo "> ${CURRENT_PORT} port currently proxying by nginx." | ||
EXIST_BLUE=$(sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml ps | grep Up) | ||
|
||
if[ ${CURRENT_PORT} -eq 8081]; then | ||
TARGET_PORT=8082; | ||
elif [ ${CURRENT_PORT} -eq 8082]; then | ||
TARGET_PORT=8081; | ||
else | ||
echo "> Currently Running WAS does not exist." | ||
#Switching | ||
if[ -z "$EXIST_BLUE"]; then # Blue isn't working | ||
echo "> blue up" | ||
docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml up -d --build | ||
BEFORE_COMPOSE_COLOR="green" | ||
AFTER_COMPOSE_COLOR="blue" | ||
else # Blue is working | ||
echo "> green up" | ||
docdker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml up -d --build | ||
BEFORE_COMPOSE_COLOR="blue" | ||
AFTER_COMPOSE_COLOR="green" | ||
fi | ||
|
||
TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') | ||
sleep 10 | ||
|
||
if[ ! -z ${TARGET_PID}]; then | ||
echo "> Exiting WAS for port ${TARGET_PORT}." | ||
sudo kill ${TARGET_PID} | ||
fi | ||
EXIST_AFTER=$(docker-compose -p ${DOCKER_APP_NAME}-${AFTER_COMPOSE_COLOR} -f docker-compose.${AFTER_COMPOSE_COLOR}.yml ps | grep UP) | ||
|
||
if[ -n "$EXIST_AFTER"]; then | ||
echo "> nginx reload .. " | ||
NGINX_CONT=$(docker ps -q --filter ancestor=nginx) | ||
docker exec -it "$NGINX_CONT" bash -c "cp /etc/nginx/nginx.${AFTER_COMPOSE_COLOR}.conf /etc/nginx/nginx.conf;nginx -s reload" | ||
|
||
source ~/.bash_profile | ||
docker-compose -f docker-compose.${BEFORE_COMPOSE_COLOR}.yml down | ||
docker rm $(docker ps -q -a -f "name=${BEFORE_COMPOSE_COLOR}") | ||
echo "$BEFORE_COMPOSE_COLOR down" | ||
fi | ||
|
||
nohop java -jar \ | ||
-Dspring.profiles.active=prod \ | ||
-Dserver.port=${TARGET_PORT} \ | ||
/home/ubuntu/app/build/libs/*.SNAPSHOT.jar > /home/ubuntu/nohup.out 2>&1 & | ||
echo "> A new WAS for ${TARGET_PORT} is running." | ||
exit 0 | ||
echo "Start removing existing image" | ||
docker rmi $(docker images -f "dangling=true" -q) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.