feat : initial commit

This commit is contained in:
2025-06-20 05:56:38 +00:00
commit 9a7e75865a
28 changed files with 1260 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# Build stage
FROM openjdk:21-jdk-slim AS builder
ARG BUILD_LIB_DIR
ARG ARTIFACTORY_FILE
COPY ${BUILD_LIB_DIR}/${ARTIFACTORY_FILE} app.jar
# Run stage
FROM openjdk:21-jdk-slim
ENV USERNAME k8s
ENV ARTIFACTORY_HOME /home/${USERNAME}
ENV JAVA_OPTS=""
# Add a non-root user
RUN adduser --system --group ${USERNAME} && \
mkdir -p ${ARTIFACTORY_HOME} && \
chown ${USERNAME}:${USERNAME} ${ARTIFACTORY_HOME}
WORKDIR ${ARTIFACTORY_HOME}
COPY --from=builder app.jar app.jar
RUN chown ${USERNAME}:${USERNAME} app.jar
USER ${USERNAME}
ENTRYPOINT [ "sh", "-c" ]
CMD ["java ${JAVA_OPTS} -jar app.jar"]
+120
View File
@@ -0,0 +1,120 @@
# HealthSync Backend 통합 Dockerfile
# 전체 멀티프로젝트를 한 번에 빌드하고 특정 서비스를 선택 실행
# =============================================================================
# Build Stage: 전체 멀티프로젝트 빌드
# =============================================================================
FROM openjdk:21-jdk-slim AS builder
# 빌드에 필요한 패키지 설치
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
# Gradle Wrapper 및 설정 파일 복사
COPY gradle/ gradle/
COPY gradlew .
COPY gradle.properties .
COPY settings.gradle .
COPY build.gradle .
# 각 서비스 소스코드 복사
COPY common/ common/
COPY api-gateway/ api-gateway/
COPY user-service/ user-service/
COPY health-service/ health-service/
COPY intelligence-service/ intelligence-service/
COPY goal-service/ goal-service/
COPY motivator-service/ motivator-service/
# Gradle 실행 권한 부여
RUN chmod +x gradlew
# 전체 프로젝트 빌드 (테스트 제외)
RUN ./gradlew clean build -x test
# 빌드된 JAR 파일들 확인
RUN find . -name "*.jar" -type f
# =============================================================================
# Runtime Stage: 실행 환경
# =============================================================================
FROM openjdk:21-jdk-slim
# 런타임 사용자 생성
RUN addgroup --system --gid 1001 healthsync && \
adduser --system --uid 1001 --gid 1001 healthsync
# 작업 디렉토리 설정
WORKDIR /app
# 빌드된 JAR 파일들 복사
COPY --from=builder /workspace/api-gateway/build/libs/*.jar ./jars/api-gateway.jar
COPY --from=builder /workspace/user-service/build/libs/*.jar ./jars/user-service.jar
COPY --from=builder /workspace/health-service/build/libs/*.jar ./jars/health-service.jar
COPY --from=builder /workspace/intelligence-service/build/libs/*.jar ./jars/intelligence-service.jar
COPY --from=builder /workspace/goal-service/build/libs/*.jar ./jars/goal-service.jar
COPY --from=builder /workspace/motivator-service/build/libs/*.jar ./jars/motivator-service.jar
# 실행 스크립트 생성
RUN cat > /app/start-service.sh << 'EOF'
#!/bin/bash
SERVICE_NAME=${SERVICE_NAME:-user-service}
JAVA_OPTS=${JAVA_OPTS:-"-Xms256m -Xmx1024m"}
echo "Starting HealthSync ${SERVICE_NAME}..."
echo "Java Options: ${JAVA_OPTS}"
case ${SERVICE_NAME} in
"api-gateway")
exec java ${JAVA_OPTS} -jar /app/jars/api-gateway.jar
;;
"user-service")
exec java ${JAVA_OPTS} -jar /app/jars/user-service.jar
;;
"health-service")
exec java ${JAVA_OPTS} -jar /app/jars/health-service.jar
;;
"intelligence-service")
exec java ${JAVA_OPTS} -jar /app/jars/intelligence-service.jar
;;
"goal-service")
exec java ${JAVA_OPTS} -jar /app/jars/goal-service.jar
;;
"motivator-service")
exec java ${JAVA_OPTS} -jar /app/jars/motivator-service.jar
;;
*)
echo "Error: Unknown service name '${SERVICE_NAME}'"
echo "Available services: api-gateway, user-service, health-service, intelligence-service, goal-service, motivator-service"
exit 1
;;
esac
EOF
# 스크립트 실행 권한 부여
RUN chmod +x /app/start-service.sh
# 디렉토리 소유자 변경
RUN chown -R healthsync:healthsync /app
# 사용자 변경
USER healthsync
# 헬스체크 스크립트 생성
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:${SERVER_PORT:-8080}/actuator/health || exit 1
# 기본 포트 노출 (환경변수로 오버라이드 가능)
EXPOSE 8080 8081 8082 8083 8084 8085
# 환경변수 기본값 설정
ENV SERVICE_NAME=user-service
ENV JAVA_OPTS="-Xms256m -Xmx1024m"
ENV SPRING_PROFILES_ACTIVE=docker
# 실행 명령
ENTRYPOINT ["/app/start-service.sh"]
+43
View File
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: health-service
namespace: team1tier-healthsync-ns
spec:
replicas: 2
selector:
matchLabels:
app: health-service
template:
metadata:
labels:
app: health-service
spec:
imagePullSecrets:
- name: acr-secret
containers:
- name: health-service
image: acrhealthsync01.azurecr.io/team1tier/health-service:1.0.0
imagePullPolicy: Always
ports:
- containerPort: 8082
envFrom:
- configMapRef:
name: common-config
- configMapRef:
name: health-config
- secretRef:
name: common-secret
- secretRef:
name: database-secret
- secretRef:
name: redis-secret
- secretRef:
name: health-db-secret
resources:
requests:
cpu: 256m
memory: 256Mi
limits:
cpu: 1024m
memory: 1024Mi
@@ -0,0 +1,60 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: common-config
namespace: team1tier-healthsync-ns
data:
ALLOWED_ORIGINS: "http://20.249.193.105"
DDL_AUTO: "update"
SHOW_SQL: "false"
LOG_LEVEL: "INFO"
WEB_LOG_LEVEL: "INFO"
GOOGLE_REDIRECT_ID : http://team1tier.20.214.196.128.nip.io/login/oauth2/code/google
GOOGLE_CLIENT_ID: 198383870460-s1s72vgu91nq9qvg5dai28vafj7mlag1.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET: 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
OAUTH2_REDIRECT_URL : http://team1tier.20.214.196.128.nip.io/login
---
apiVersion: v1
kind: ConfigMap
metadata:
name: user-config
namespace: team1tier-healthsync-ns
data:
SERVER_PORT: "8081"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: health-config
namespace: team1tier-healthsync-ns
data:
SERVER_PORT: "8082"
USER_SERVICE_URL: "http://user-service:80"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: goal-config
namespace: team1tier-healthsync-ns
data:
SERVER_PORT: "8084"
USER_SERVICE_URL: "http://user-service:80"
INTELLIGENCE_SERVICE_URL: "http://team1tier.20.214.196.128.nip.io"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
namespace: team1tier-healthsync-ns
data:
# Azure Cache for Redis 설정
REDIS_HOST: "redis-digitalgarage-01.redis.cache.windows.net"
REDIS_PORT: "6380" # SSL 포트
REDIS_SSL: "true" # SSL 활성화
REDIS_TIMEOUT: "2000"
REDIS_DATABASE: "0"
# Connection Pool 설정
REDIS_LETTUCE_POOL_MAX_ACTIVE: "8"
REDIS_LETTUCE_POOL_MAX_IDLE: "8"
REDIS_LETTUCE_POOL_MIN_IDLE: "0"
---
@@ -0,0 +1,64 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: goal-service
namespace: team1tier-healthsync-ns
spec:
revisionHistoryLimit: 3
replicas: 2
selector:
matchLabels:
app: goal-service
template:
metadata:
labels:
app: goal-service
spec:
imagePullSecrets:
- name: acr-secret
containers:
- name: goal-service
image: acrhealthsync01.azurecr.io/team1tier/goal-service:1.0.8
imagePullPolicy: Always
ports:
- containerPort: 8084
envFrom:
- configMapRef:
name: common-config
- configMapRef:
name: goal-config
- configMapRef:
name: redis-config
- secretRef:
name: common-secret
- secretRef:
name: database-secret
- secretRef:
name: redis-secret
- secretRef:
name: goal-db-secret
resources:
requests:
cpu: 256m
memory: 256Mi
limits:
cpu: 1024m
memory: 1024Mi
# startupProbe:
# httpGet:
# path: /actuator/health
# port: 8084
# failureThreshold: 30
# periodSeconds: 10
# livenessProbe:
# httpGet:
# path: /actuator/health
# port: 8084
# initialDelaySeconds: 60
# periodSeconds: 15
# readinessProbe:
# httpGet:
# path: /actuator/health
# port: 8084
# initialDelaySeconds: 10
# periodSeconds: 5
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: health-service
namespace: team1tier-healthsync-ns
spec:
revisionHistoryLimit: 3
replicas: 2
selector:
matchLabels:
app: health-service
template:
metadata:
labels:
app: health-service
spec:
imagePullSecrets:
- name: acr-secret
containers:
- name: health-service
image: acrhealthsync01.azurecr.io/team1tier/health-service:1.0.13
imagePullPolicy: Always
ports:
- containerPort: 8082
env:
- name: SPRING_DATA_REDIS_HOST
value: "redis-digitalgarage-01.redis.cache.windows.net"
- name: SPRING_DATA_REDIS_PORT
value: "6380"
- name: SPRING_DATA_REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
key: REDIS_PASSWORD
- name: SPRING_DATA_REDIS_SSL_ENABLED
value: "true"
- name: SPRING_DATA_REDIS_TIMEOUT
value: "2000ms"
- name: DB_URL
value: "jdbc:postgresql://psql-digitalgarage-01.postgres.database.azure.com:5432/healthsync_db"
- name: DB_USERNAME
value: "team1tier"
- name: DB_PASSWORD
value: "Hi5Jessica!"
- name: JWT_SECRET
valueFrom:
secretKeyRef:
name: common-secret
key: JWT_SECRET
resources:
requests:
cpu: 256m
memory: 256Mi
limits:
cpu: 1024m
memory: 1024Mi
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-service
namespace: team1tier-healthsync-ns
spec:
revisionHistoryLimit: 3
replicas: 1
selector:
matchLabels:
app: user-service
template:
metadata:
labels:
app: user-service
spec:
imagePullSecrets:
- name: acr-secret
containers:
- name: user-service
image: acrhealthsync01.azurecr.io/team1tier/user-service:1.0.11
imagePullPolicy: Always
ports:
- containerPort: 8081
envFrom:
- configMapRef:
name: common-config
- configMapRef:
name: user-config
- secretRef:
name: database-secret
- secretRef:
name: redis-secret
- secretRef:
name: user-db-secret
resources:
requests:
cpu: 256m
memory: 256Mi
limits:
cpu: 1024m
memory: 1024Mi
@@ -0,0 +1,55 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: healthsync-ingress
namespace: team1tier-healthsync-ns
annotations:
kubernetes.io/ingress.class: nginx
spec:
ingressClassName: nginx
rules:
- host: team1tier.20.214.196.128.nip.io
http:
paths:
- path: /login/oauth2
pathType: Prefix
backend:
service:
name: user-service
port:
number: 80
- path: /api/user
pathType: Prefix
backend:
service:
name: user-service
port:
number: 80
- path: /api/auth
pathType: Prefix
backend:
service:
name: user-service
port:
number: 80
- path: /oauth2
pathType: Prefix
backend:
service:
name: user-service
port:
number: 80
- path: /api/health
pathType: Prefix
backend:
service:
name: health-service
port:
number: 80
- path: /api/goals
pathType: Prefix
backend:
service:
name: goal-service
port:
number: 80
@@ -0,0 +1,46 @@
---
apiVersion: v1
kind: Secret
metadata:
name: database-secret
namespace: team1tier-healthsync-ns
type: Opaque
stringData:
DB_USERNAME: "team1tier"
DB_PASSWORD: "Hi5Jessica!"
---
apiVersion: v1
kind: Secret
metadata:
name: redis-secret
namespace: team1tier-healthsync-ns
type: Opaque
stringData:
REDIS_PASSWORD: "HUezXQsxbphIeBy8FV9JDA3WaZDwOozGEAzCaByUk40="
---
apiVersion: v1
kind: Secret
metadata:
name: user-db-secret
namespace: team1tier-healthsync-ns
type: Opaque
stringData:
DB_URL: "jdbc:postgresql://psql-digitalgarage-01.postgres.database.azure.com:5432/healthsync_db"
---
apiVersion: v1
kind: Secret
metadata:
name: health-db-secret
namespace: team1tier-healthsync-ns
type: Opaque
stringData:
DB_URL: "jdbc:postgresql://psql-digitalgarage-01.postgres.database.azure.com:5432/healthsync_db"
---
apiVersion: v1
kind: Secret
metadata:
name: goal-db-secret
namespace: team1tier-healthsync-ns
type: Opaque
stringData:
DB_URL: "jdbc:postgresql://psql-digitalgarage-01.postgres.database.azure.com:5432/healthsync_db"
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: user-service
namespace: team1tier-healthsync-ns
spec:
selector:
app: user-service
ports:
- port: 80
targetPort: 8081
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: health-service
namespace: team1tier-healthsync-ns
spec:
selector:
app: health-service
ports:
- port: 80
targetPort: 8082
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: goal-service
namespace: team1tier-healthsync-ns
spec:
selector:
app: goal-service
ports:
- port: 80
targetPort: 8084
type: ClusterIP