Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rver into develop
  • Loading branch information
tteia committed Oct 30, 2024
2 parents 680827e + edc3dc8 commit 2514506
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 56 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/deploy_msa_k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- develop


jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -42,6 +43,11 @@ jobs:
-f ./backend/product/Dockerfile ./backend/product
docker push $REGISTRY/$REPOSITORY:latest
- name: eks kubectl apply
run: |
kubectl apply -f ./backend/product/k8s/product-depl.yml
kubectl rollout restart deployment product-deployment
# member
- name: build and push docker member images to ecr
env:
Expand All @@ -68,8 +74,8 @@ jobs:
docker push $REGISTRY/$REPOSITORY:latest
- name: eks kubectl apply
run: |
kubectl apply -f ./backend/product/k8s/product-depl.yml
kubectl rollout restart deployment product-deployment
kubectl apply -f ./backend/order/k8s/order-depl.yml
kubectl rollout restart deployment order-deployment
# live
- name: build and push docker live images to ecr
Expand All @@ -85,3 +91,18 @@ jobs:
run: |
kubectl apply -f ./backend/live/k8s/live-depl.yml
kubectl rollout restart deployment live-deployment
# apigateway
- name: build and push docker apigateway images to ecr
env:
REGISTRY: 676206947506.dkr.ecr.ap-northeast-2.amazonaws.com
REPOSITORY: inong/apigateway
run: |
docker build -t $REGISTRY/$REPOSITORY:latest \
-f ./backend/apigateway/Dockerfile ./backend/apigateway
docker push $REGISTRY/$REPOSITORY:latest
- name: eks kubectl apply
run: |
kubectl apply -f ./backend/apigateway/k8s/apigateway-depl.yml
kubectl rollout restart deployment apigateway-deployment
1 change: 1 addition & 0 deletions backend/apigateway/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ out/

## secret
src/main/resources/application-secret.properties
src/main/resources/application.yml
22 changes: 22 additions & 0 deletions backend/apigateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

FROM openjdk:17-jdk-alpine as stage1

WORKDIR /app

COPY gradlew .

COPY gradle gradle
COPY src src
COPY build.gradle .
COPY settings.gradle .

RUN chmod 777 gradlew
RUN ./gradlew bootJar

# 두 번째 스테이지
FROM openjdk:17-jdk-alpine
WORKDIR /app

COPY --from=stage1 /app/build/libs/*.jar app.jar

ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"]
2 changes: 1 addition & 1 deletion backend/apigateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ext {
dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
Expand Down
24 changes: 5 additions & 19 deletions backend/apigateway/k8s/apigateway-depl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ apiVersion: apps/v1

kind: Deployment
metadata:
name: live-deployment
name: apigateway-deployment

spec:
replicas: 1
selector:
matchLabels:
app: live
app: apigateway

template:
metadata:
labels:
app: live
app: apigateway
spec:
containers:
- name: live
- name: apigateway
# aws의 ecr 주소 사용
image: 676206947506.dkr.ecr.ap-northeast-2.amazonaws.com/inong/apigateway:latest
ports:
Expand Down Expand Up @@ -45,18 +45,4 @@ spec:
valueFrom:
secretKeyRef:
key: JWT_TOKEN_REFRESH_EXPIRATION_TIME
name: inong-app-secrets
readinessProbe:
httpGet:
path: /live/healthcheck
port: 8080
# 컨테이너 시작 후 지연 시간 설정
initialDelaySeconds: 10
# 확인 반복 주기
periodSeconds: 10
# 요청 타임아웃 설정
timeoutSeconds: 1 # 1초 이내에 안오면 실패로 간주
# 성공 인식 횟수 설정. 몇번을 성공해야 성공으로 간주할거냐
successThreshold: 1
# 연속 실패 횟수: 연속적으로 5번을 실패하면 건강하지 않은 상태로 판단하여 기존 서버 종료시키지 않음
failureThreshold: 5
name: inong-app-secrets
4 changes: 2 additions & 2 deletions backend/apigateway/k8s/apigateway-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1

kind: Service
metadata:
name: live-service
name: apigateway-service

spec:
# ingress를 적용하기 위해 ClusterIP로 변경
Expand All @@ -13,4 +13,4 @@ spec:
targetPort: 8080 # pod 포트
# depl의 labels와 맞아야 함 ⭐
selector:
app: live
app: apigateway
2 changes: 1 addition & 1 deletion backend/apigateway/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
config:
activate:
on-profile: prod
import: application-secret.properties
# import: application-secret.properties
application:
name: api-gateway
cloud:
Expand Down
2 changes: 1 addition & 1 deletion backend/live/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.kafka:spring-kafka'
Expand Down
2 changes: 1 addition & 1 deletion backend/live/k8s/live-depl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ spec:
#무중단 배포를 위한 컨테이너 헬스체크
readinessProbe:
httpGet:
path: /live-service/live/healthcheck
path: /live/healthcheck
port: 8080
# 컨테이너 시작 후 지연 시간 설정
initialDelaySeconds: 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public class KafkaConstants {
public static final String KAFKA_TOPIC = "kafka-chat";
public static final String GROUP_ID = "dongsanginong";
public static final String KAFKA_BROKER = "localhost:9092";
// public static final String KAFKA_BROKER = "localhost:9092";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.samtuap.inong.domain.chat.dto.ChatMessageRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
Expand All @@ -15,6 +16,9 @@

public class KafkaConsumerConfig {

@Value("${spring.kafka.bootstrap-servers}")
private String KAFKA_HOST;

@Bean
ConcurrentKafkaListenerContainerFactory<String, ChatMessageRequest> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, ChatMessageRequest> factory = new ConcurrentKafkaListenerContainerFactory<>();
Expand All @@ -38,7 +42,7 @@ public ConsumerFactory<String, ChatMessageRequest> consumerFactory() {
@Bean
public Map<String, Object> consumerConfigurations() {
Map<String, Object> configurations = new HashMap<>();
configurations.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, KafkaConstants.KAFKA_BROKER);
configurations.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_HOST);
configurations.put(ConsumerConfig.GROUP_ID_CONFIG, KafkaConstants.GROUP_ID);
configurations.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ErrorHandlingDeserializer.class);
configurations.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.kafka.common.serialization.StringSerializer;
import org.samtuap.inong.domain.chat.dto.ChatMessageRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
Expand All @@ -17,6 +18,9 @@
@Configuration
public class KafkaProducerConfig {

@Value("${spring.kafka.bootstrap-servers}")
private String KAFKA_HOST;

@Bean
public ProducerFactory<String, ChatMessageRequest> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigurations());
Expand All @@ -25,7 +29,7 @@ public ProducerFactory<String, ChatMessageRequest> producerFactory() {
@Bean
public Map<String, Object> producerConfigurations() {
Map<String, Object> configurations = new HashMap<>();
configurations.put(org.apache.kafka.clients.producer.ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KafkaConstants.KAFKA_BROKER);
configurations.put(org.apache.kafka.clients.producer.ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_HOST);
configurations.put(org.apache.kafka.clients.producer.ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configurations.put(org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return configurations;
Expand Down
5 changes: 4 additions & 1 deletion backend/live/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 0
port: 8080

spring:
config:
Expand Down Expand Up @@ -31,10 +31,13 @@ spring:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
consumer:
group-id: live-group
group-instance-id: ${HOSTNAME}-instance
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
properties:
socket.connection.setup.timeout.ms: 60000
socket.connection.setup.timeout.max.ms: 60000
spring:
json:
trusted:
Expand Down
1 change: 0 additions & 1 deletion backend/member/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

FROM openjdk:17-jdk-alpine as stage1

WORKDIR /app
Expand Down
4 changes: 3 additions & 1 deletion backend/member/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.kafka:spring-kafka'
Expand All @@ -47,6 +47,8 @@ dependencies {
// fcm
implementation 'com.google.firebase:firebase-admin:9.3.0'

implementation 'com.thoughtworks.xstream:xstream:1.4.20'

}

dependencyManagement {
Expand Down
2 changes: 1 addition & 1 deletion backend/member/k8s/member-depl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ spec:
#무중단 배포를 위한 컨테이너 헬스체크
readinessProbe:
httpGet:
path: /member-service/member/healthcheck
path: /member/healthcheck
port: 8080
# 컨테이너 시작 후 지연 시간 설정
initialDelaySeconds: 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.WebpushConfig;
import com.google.firebase.messaging.WebpushNotification;
import com.thoughtworks.xstream.core.BaseException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.samtuap.inong.common.exception.BaseCustomException;
Expand Down
15 changes: 2 additions & 13 deletions backend/member/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 0
port: 8080

spring:
config:
Expand Down Expand Up @@ -35,6 +35,7 @@ spring:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
consumer:
group-id: member-group
group-instance-id: ${HOSTNAME}-instance
auto-offset-reset: earliest

logging:
Expand Down Expand Up @@ -71,17 +72,5 @@ jwt:
access_expiration_time: ${JWT_TOKEN_ACCESS_EXPIRATION_TIME}
refresh_expiration_time: ${JWT_TOKEN_REFRESH_EXPIRATION_TIME}

### swagger
#springdoc:
# api-docs:
# path: /member-service/v3/api-docs
# swagger-ui:
# path: /member-service/swagger-ui.html
#
#openapi:
# service:
# # API Gateway port
# url: http://localhost:8080

fcm:
secret-file: ${FCM_SECRET_FILE}
2 changes: 1 addition & 1 deletion backend/order/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.kafka:spring-kafka'
Expand Down
2 changes: 1 addition & 1 deletion backend/order/k8s/order-depl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ spec:
#무중단 배포를 위한 컨테이너 헬스체크
readinessProbe:
httpGet:
path: /order-service/order/healthcheck
path: /order/healthcheck
port: 8080
# 컨테이너 시작 후 지연 시간 설정
initialDelaySeconds: 20
Expand Down
5 changes: 3 additions & 2 deletions backend/order/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 0
port: 8080

spring:
config:
Expand Down Expand Up @@ -35,6 +35,7 @@ spring:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
consumer:
group-id: order-group
group-instance-id: ${HOSTNAME}-instance
auto-offset-reset: earliest

logging:
Expand All @@ -47,4 +48,4 @@ portone:
api-secret: ${PORTONE_KAKAO_API_SECRET}
payment-prefix: ${PORTONE_PAYMENT_PREFIX}
store-id: ${PORTONE_STORE_ID}
channel-key: ${PORTONE_CHANNELKEY}
channel-key: ${PORTONE_CHANNELKEY}
4 changes: 3 additions & 1 deletion backend/product/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.mindrot:jbcrypt:0.4'
Expand Down Expand Up @@ -65,6 +65,8 @@ dependencies {
// redis shedlock
implementation 'net.javacrumbs.shedlock:shedlock-spring:4.44.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-redis-spring:4.44.0'

implementation 'com.thoughtworks.xstream:xstream:1.4.20'
}

tasks.named('test') {
Expand Down
Loading

0 comments on commit 2514506

Please sign in to comment.