Skip to content

Commit 48585a0

Browse files
authored
[chore] 레디스 로컬 서버 문제 (#223)
* #222 [chore] 로컬 docker compose 파일 수정 * #222 [chore] 로컬 redis-init 파일 수정 * #222 [chore] env_file 경로 수정 및 db 환경변수 지정 * #222 [chore] application local - redis host 추가 * #222 [chore] redis init 파일 수정 * #222 [chore] docker compose 파일 수정 * #222 [chore] redis host 환경변수 추출
1 parent ae5bafb commit 48585a0

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

docker-compose.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,56 @@
11
services:
2-
alloon:
2+
backend:
3+
container_name: backend
34
restart: always
45
env_file:
56
- docker/.env
67
build:
7-
context: docker
8-
dockerfile: Dockerfile
8+
context: .
9+
dockerfile: docker/Dockerfile
910
ports:
1011
- "8080:8080"
1112
depends_on:
1213
- db
13-
- mem-db
14+
- redis
15+
- redis-init
16+
environment:
17+
- TZ=Asia/Seoul
18+
networks:
19+
- app-network
1420
db:
1521
image: postgres:latest
22+
container_name: postgres-db
1623
restart: always
1724
ports:
1825
- "5432:5432"
1926
volumes:
20-
- ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql
27+
- ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
2128
environment:
2229
POSTGRES_USER: postgres
2330
POSTGRES_PASSWORD: postgres!2#
24-
POSTGRES_DB: allon_server
25-
mem-db:
31+
POSTGRES_DB: photi_local_db
32+
networks:
33+
- app-network
34+
redis:
2635
image: redis:latest
36+
container_name: redis-db
2737
restart: always
2838
ports:
2939
- "6379:6379"
40+
networks:
41+
- app-network
42+
redis-init:
43+
image: redis:latest
44+
container_name: redis-init
45+
restart: "no"
46+
depends_on:
47+
- redis
48+
entrypoint: [ "bash", "-c", "/init/redis-init.sh" ]
3049
volumes:
31-
- ./docker/redis-init.sh:/redis-init.sh
32-
command: [ "sh", "-c", "redis-server --daemonize yes && sleep 3 && bash /redis-init.sh && tail -f /dev/null" ]
50+
- ./docker/redis-init.sh:/init/redis-init.sh:ro
51+
networks:
52+
- app-network
53+
54+
networks:
55+
app-network:
56+
driver: bridge

docker/redis-init.sh

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#!/bin/bash
2-
echo "Waiting for Redis to start..."
3-
until redis-cli ping | grep -q "PONG"; do
4-
echo "Redis is not ready yet. Waiting..."
5-
sleep 1
2+
set -e
3+
4+
echo "[INFO] Initializing Redis data..."
5+
6+
declare -A hashtags=(
7+
["러닝"]=10
8+
["게임"]=20
9+
["건강식"]=15
10+
["챌린지"]=5
11+
["개발"]=7
12+
["코틀린"]=9
13+
["iOS"]=25
14+
["안드로이드"]=15
15+
["스프링"]=50
16+
["디자인"]=36
17+
)
18+
19+
for tag in "${!hashtags[@]}"; do
20+
score="${hashtags[$tag]}"
21+
redis-cli -h redis ZADD popular:hashtags "$score" "$tag"
622
done
723

8-
echo "Redis initialization..."
9-
redis-cli <<EOF
10-
ZADD popular:hashtags 10 "러닝"
11-
ZADD popular:hashtags 20 "게임"
12-
ZADD popular:hashtags 15 "건강식"
13-
ZADD popular:hashtags 5 "챌린지"
14-
ZADD popular:hashtags 7 "개발"
15-
ZADD popular:hashtags 9 "코틀린"
16-
ZADD popular:hashtags 25 "iOS"
17-
ZADD popular:hashtags 15 "안드로이드"
18-
ZADD popular:hashtags 50 "스프링"
19-
ZADD popular:hashtags 36 "디자인"
20-
ZRANGE popular:hashtags 0 -1 WITHSCORES
21-
EOF
22-
echo "Redis initialization completed."
24+
echo "[INFO] Initialized hashtags:"
25+
redis-cli -h redis ZRANGE popular:hashtags 0 -1 WITHSCORES
26+
27+
echo "[INFO] Redis initialization completed successfully"

src/main/resources/application-local.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ spring:
1010
ddl-auto: none
1111
flyway:
1212
enabled: false
13+
data:
14+
redis:
15+
host: ${SPRING_REDIS_HOST}
1316

1417
cloud:
1518
aws:

0 commit comments

Comments
 (0)