Skip to content

Commit b855f78

Browse files
committed
[infra] deploy ์ˆ˜์ •
1 parent 42142f6 commit b855f78

2 files changed

Lines changed: 60 additions & 60 deletions

File tree

โ€Ž.idea/workspace.xmlโ€Ž

Lines changed: 13 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Ždeploy.shโ€Ž

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,58 @@
11
#!/bin/bash
2-
cd /home/ec2-user/app || exit 1
2+
set -e
33

4-
DOCKER_APP_NAME="moviezip-app"
5-
JAR_FILE="demo-0.0.1-SNAPSHOT.jar"
6-
LOG_DIR="./logs"
4+
APP_NAME="moviezip-app"
5+
IMAGE_NAME="moviezip-server:latest"
6+
LOG_DIR="/home/ec2-user/app/logs"
77

88
mkdir -p ${LOG_DIR}
99

10-
# blue ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์—ฌ๋ถ€ ํ™•์ธ
11-
EXIST_BLUE=$(docker ps --filter "name=${DOCKER_APP_NAME}-blue" --filter "status=running" -q)
12-
13-
if [ -z "$EXIST_BLUE" ]; then
14-
echo "Deploy Blue"
15-
docker rm -f ${DOCKER_APP_NAME}-blue || true
16-
docker run -d --name moviezip-app-blue -p 8081:8080 \
17-
-v $(pwd)/demo-0.0.1-SNAPSHOT.jar:/app/demo-0.0.1-SNAPSHOT.jar \
18-
-e SPRING_PROFILES_ACTIVE=prod \
19-
-e DB_URL=jdbc:oracle:thin:@dblab.dongduk.ac.kr:1521/orclpdb \
20-
-e DB_USERNAME=ss240205 \
21-
-e DB_PASSWORD=ss240205ss \
22-
-e MONGODB_URI=mongodb://localhost:27017/movieZip \
23-
-e REDIS_HOST=localhost \
24-
-e REDIS_PORT=6379 \
25-
eclipse-temurin:17-jdk \
26-
java -jar /app/demo-0.0.1-SNAPSHOT.jar
27-
sleep 15
28-
docker rm -f ${DOCKER_APP_NAME}-green || true
10+
# Docker build (JAR ํฌํ•จ)
11+
echo "Building Docker image..."
12+
docker build -t ${IMAGE_NAME} /home/ec2-user/app
13+
14+
# Blue/Green ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ๋ฐ ํฌํŠธ ์„ค์ •
15+
BLUE_NAME="${APP_NAME}-blue"
16+
GREEN_NAME="${APP_NAME}-green"
17+
BLUE_PORT=8081
18+
GREEN_PORT=8082
19+
20+
# ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ Blue/Green ํ™•์ธ
21+
RUNNING_BLUE=$(docker ps --filter "name=${BLUE_NAME}" -q)
22+
RUNNING_GREEN=$(docker ps --filter "name=${GREEN_NAME}" -q)
23+
24+
# ๋ฐฐํฌํ•  ์ปจํ…Œ์ด๋„ˆ ๊ฒฐ์ •
25+
if [ -z "$RUNNING_BLUE" ]; then
26+
DEPLOY_NAME=$BLUE_NAME
27+
DEPLOY_PORT=$BLUE_PORT
28+
STOP_NAME=$GREEN_NAME
29+
echo "Deploying Blue..."
2930
else
30-
echo "Deploy Green"
31-
docker rm -f ${DOCKER_APP_NAME}-green || true
32-
docker run -d --name moviezip-app-green -p 8082:8080 \
33-
-v $(pwd)/demo-0.0.1-SNAPSHOT.jar:/app/demo-0.0.1-SNAPSHOT.jar \
34-
-e SPRING_PROFILES_ACTIVE=prod \
35-
-e DB_URL=jdbc:oracle:thin:@dblab.dongduk.ac.kr:1521/orclpdb \
36-
-e DB_USERNAME=ss240205 \
37-
-e DB_PASSWORD=ss240205ss \
38-
-e MONGODB_URI=mongodb://localhost:27017/movieZip \
39-
-e REDIS_HOST=localhost \
40-
-e REDIS_PORT=6379 \
41-
eclipse-temurin:17-jdk \
42-
java -jar /app/demo-0.0.1-SNAPSHOT.jar
43-
sleep 15
44-
docker rm -f ${DOCKER_APP_NAME}-blue || true
31+
DEPLOY_NAME=$GREEN_NAME
32+
DEPLOY_PORT=$GREEN_PORT
33+
STOP_NAME=$BLUE_NAME
34+
echo "Deploying Green..."
4535
fi
4636

37+
# ์ด์ „ ์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ
38+
if [ ! -z "$STOP_NAME" ]; then
39+
docker rm -f ${STOP_NAME} || true
40+
fi
41+
42+
# ์ƒˆ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
43+
docker run -d --name ${DEPLOY_NAME} -p ${DEPLOY_PORT}:8080 \
44+
-e SPRING_PROFILES_ACTIVE=prod \
45+
-e DB_URL=jdbc:oracle:thin:@dblab.dongduk.ac.kr:1521/orclpdb \
46+
-e DB_USERNAME=ss240205 \
47+
-e DB_PASSWORD=ss240205ss \
48+
-e MONGODB_URI=mongodb://mongo:27017/movieZip \
49+
-e REDIS_HOST=redis \
50+
-e REDIS_PORT=6379 \
51+
${IMAGE_NAME}
52+
53+
sleep 10
54+
55+
# ๋ถˆํ•„์š”ํ•œ ์ด๋ฏธ์ง€ ์ •๋ฆฌ
4756
docker image prune -af
4857

4958
echo "Deployment completed!"

0 commit comments

Comments
ย (0)