Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

# Binary files should be left untouched
*.jar binary

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Zookeeper_Register.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions zookeeper-memcached-registrar/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

# Binary files should be left untouched
*.jar binary

5 changes: 5 additions & 0 deletions zookeeper-memcached-registrar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sun Jun 01 21:52:04 KST 2025
gradle.version=8.9
#Thu Jun 05 14:33:49 KST 2025
gradle.version=8.14.1
31 changes: 13 additions & 18 deletions zookeeper-memcached-registrar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
# 1단계: Java 17 환경에서 Gradle을 사용하여 JAR 빌드
# ───────────────────────────────────────────────────
# 1단계: Gradle 환경에서 ShadowJar를 만들어 내는 builder 이미지
# ───────────────────────────────────────────────────
FROM gradle:8.5-jdk17 AS builder

WORKDIR /app

# Gradle 설정 파일들 먼저 복사 (의존성 캐싱 활용)
COPY build.gradle settings.gradle ./
# gradlew와 wrapper도 필요하다면 복사합니다. 여기서는 gradle 이미지를 직접 사용합니다.
# COPY gradlew ./
# COPY gradle ./gradle
# 1) Gradle build 파일들 복사 (의존성 캐싱을 위해)
COPY build.gradle settings.gradle ./

# 의존성 먼저 다운로드 (소스 변경 없이 의존성만 변경되었을 때 이 레이어까지 캐시 활용)
# RUN ./gradlew build --no-daemon --build-cache || echo "No settings.gradle, skipping dependency download step"
# 위 명령어 대신, gradle 이미지에서는 바로 빌드해도 괜찮습니다.

# 소스 코드 복사
# 2) 소스 코드 전체 복사
COPY src ./src

# Gradle 빌드를 실행하여 shadow JAR 생성 (fat JAR)
# gradlew가 있다면 ./gradlew shadowJar --no-daemon
# 3) ShadowJar(=fat JAR) 생성
RUN gradle shadowJar --no-daemon --build-cache

# 2단계: 작은 JRE 이미지를 기반으로 최종 이미지 생성
FROM openjdk:17-jre-slim
# ───────────────────────────────────────────────────
# 2단계: 경량화된 JRE 이미지를 활용한 런타임 이미지
# ───────────────────────────────────────────────────
FROM openjdk:17-slim

WORKDIR /app

# 빌드 단계에서 생성된 shadow JAR 파일 복사
# shadowJar 설정에 따라 파일명 패턴이 projectname-version-all.jar 형태가 됩니다.
# 빌더 단계에서 생성된 모든-의존성 포함 Jar 파일 복사
COPY --from=builder /app/build/libs/*-all.jar app.jar

# 애플리케이션 실행 명령어
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
3 changes: 1 addition & 2 deletions zookeeper-memcached-registrar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dependencies {
}

application {
mainClass = 'com.example.MemcachedNodeRegistrar'
}
mainClass = 'com.example.zkmonitor.ZkMonitorApplication'}

// shadowJar 설정 (선택적, 기본 설정으로도 잘 동작함)
shadowJar {
Expand Down
96 changes: 27 additions & 69 deletions zookeeper-memcached-registrar/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version: '3.8'

services:
# ─────────────────────────────────────────────
# 1) ZooKeeper
# ─────────────────────────────────────────────
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
image: zookeeper:3.8.1
hostname: zookeeper
container_name: zookeeper
ports:
Expand All @@ -13,19 +16,9 @@ services:
networks:
- cache-network

hashring-server:
image: mr8356/hashringserver:latest
container_name: hashring-server
depends_on:
- zookeeper
ports:
- "8080:8080"
environment:
ZOOKEEPER_CONNECTION: zookeeper:2181
SPRING_APPLICATION_NAME: hashring-service
networks:
- cache-network

# ─────────────────────────────────────────────
# 2) Memcached 인스턴스 4개
# ─────────────────────────────────────────────
memcached1:
image: memcached:1.6-alpine
container_name: memcached1
Expand Down Expand Up @@ -58,74 +51,39 @@ services:
networks:
- cache-network

registrar1:
# ─────────────────────────────────────────────
# 3) zk-monitor (HealthChecker + ZkWatcher)
# ─────────────────────────────────────────────
zk-monitor:
build:
context: .
context: . # 이 디렉터리 안에 Dockerfile이 있어야 합니다.
dockerfile: Dockerfile
container_name: registrar1
container_name: zk-monitor
depends_on:
- zookeeper
- memcached1
environment:
ZOOKEEPER_CONNECTION: zookeeper:2181
NODE_ID: "node1"
MEMCACHED_HOST: memcached1
MEMCACHED_PORT_ACTUAL: "11211"
networks:
- cache-network
restart: on-failure

registrar2:
build:
context: .
dockerfile: Dockerfile
container_name: registrar2
depends_on:
- zookeeper
- memcached2
environment:
ZOOKEEPER_CONNECTION: zookeeper:2181
NODE_ID: "node2"
MEMCACHED_HOST: memcached2
MEMCACHED_PORT_ACTUAL: "11211"
networks:
- cache-network
restart: on-failure

registrar3:
build:
context: .
dockerfile: Dockerfile
container_name: registrar3
depends_on:
- zookeeper
- memcached3
environment:
ZOOKEEPER_CONNECTION: zookeeper:2181
NODE_ID: "node3"
MEMCACHED_HOST: memcached3
MEMCACHED_PORT_ACTUAL: "11211"
networks:
- cache-network
restart: on-failure

registrar4:
build:
context: .
dockerfile: Dockerfile
container_name: registrar4
depends_on:
- zookeeper
- memcached4
environment:
# 1) ZooKeeper 연결 정보
ZOOKEEPER_CONNECTION: zookeeper:2181
NODE_ID: "node4"
MEMCACHED_HOST: memcached4
MEMCACHED_PORT_ACTUAL: "11211"

# 2) Spring Boot 서버 알림 엔드포인트
# (실제 운영/테스트 환경에 맞춰 <SPRING_HOST>:<SPRING_PORT> 로 바꿔 주세요)
SPRING_NOTIFY_URL: http://<SPRING_HOST>:<SPRING_PORT>/zookeeper/nodeChange

# 3) Memcached 동기화 설정
MEMCACHED_BASE_NAME: memcached
MEMCACHED_COUNT: 4
MEMCACHED_PORT: 11211

# 4) HealthChecker 주기 (초 단위)
HEALTH_CHECK_INTERVAL: 10
networks:
- cache-network
restart: on-failure

networks:
cache-network:
driver: bridge
driver: bridge
5 changes: 5 additions & 0 deletions zookeeper-memcached-registrar/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

org.gradle.configuration-cache=true

2 changes: 2 additions & 0 deletions zookeeper-memcached-registrar/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading