diff --git a/.github/workflows/deploy_msa_k8s.yml b/.github/workflows/deploy_msa_k8s.yml index 532a07ed..99097108 100644 --- a/.github/workflows/deploy_msa_k8s.yml +++ b/.github/workflows/deploy_msa_k8s.yml @@ -5,6 +5,7 @@ on: branches: - develop + jobs: build-and-deploy: runs-on: ubuntu-latest @@ -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: @@ -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 @@ -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 \ No newline at end of file diff --git a/backend/apigateway/.gitignore b/backend/apigateway/.gitignore index 0b17f470..9b3342ff 100644 --- a/backend/apigateway/.gitignore +++ b/backend/apigateway/.gitignore @@ -38,3 +38,4 @@ out/ ## secret src/main/resources/application-secret.properties +src/main/resources/application.yml \ No newline at end of file diff --git a/backend/apigateway/Dockerfile b/backend/apigateway/Dockerfile new file mode 100644 index 00000000..6494c127 --- /dev/null +++ b/backend/apigateway/Dockerfile @@ -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"] \ No newline at end of file diff --git a/backend/apigateway/build.gradle b/backend/apigateway/build.gradle index 76b2d18b..e0d94d33 100644 --- a/backend/apigateway/build.gradle +++ b/backend/apigateway/build.gradle @@ -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' diff --git a/backend/apigateway/k8s/apigateway-depl.yml b/backend/apigateway/k8s/apigateway-depl.yml index edeb1cb5..b607cb4b 100644 --- a/backend/apigateway/k8s/apigateway-depl.yml +++ b/backend/apigateway/k8s/apigateway-depl.yml @@ -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: @@ -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 \ No newline at end of file + name: inong-app-secrets \ No newline at end of file diff --git a/backend/apigateway/k8s/apigateway-service.yml b/backend/apigateway/k8s/apigateway-service.yml index bcd9c9cc..862c61a0 100644 --- a/backend/apigateway/k8s/apigateway-service.yml +++ b/backend/apigateway/k8s/apigateway-service.yml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: - name: live-service + name: apigateway-service spec: # ingress를 적용하기 위해 ClusterIP로 변경 @@ -13,4 +13,4 @@ spec: targetPort: 8080 # pod 포트 # depl의 labels와 맞아야 함 ⭐ selector: - app: live \ No newline at end of file + app: apigateway \ No newline at end of file diff --git a/backend/apigateway/src/main/resources/application-prod.yml b/backend/apigateway/src/main/resources/application-prod.yml index 5bea45c4..35a53c5a 100644 --- a/backend/apigateway/src/main/resources/application-prod.yml +++ b/backend/apigateway/src/main/resources/application-prod.yml @@ -4,7 +4,7 @@ spring: config: activate: on-profile: prod - import: application-secret.properties +# import: application-secret.properties application: name: api-gateway cloud: diff --git a/backend/live/build.gradle b/backend/live/build.gradle index 97be38c9..0accb13f 100644 --- a/backend/live/build.gradle +++ b/backend/live/build.gradle @@ -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' diff --git a/backend/live/k8s/live-depl.yml b/backend/live/k8s/live-depl.yml index ab3c7fef..59a7888b 100644 --- a/backend/live/k8s/live-depl.yml +++ b/backend/live/k8s/live-depl.yml @@ -79,7 +79,7 @@ spec: #무중단 배포를 위한 컨테이너 헬스체크 readinessProbe: httpGet: - path: /live-service/live/healthcheck + path: /live/healthcheck port: 8080 # 컨테이너 시작 후 지연 시간 설정 initialDelaySeconds: 20 diff --git a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConstants.java b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConstants.java index 76f21e44..c3259e70 100644 --- a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConstants.java +++ b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConstants.java @@ -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"; } \ No newline at end of file diff --git a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConsumerConfig.java b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConsumerConfig.java index b5791ba9..2e869f9a 100644 --- a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConsumerConfig.java +++ b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaConsumerConfig.java @@ -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; @@ -15,6 +16,9 @@ public class KafkaConsumerConfig { + @Value("${spring.kafka.bootstrap-servers}") + private String KAFKA_HOST; + @Bean ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); @@ -38,7 +42,7 @@ public ConsumerFactory consumerFactory() { @Bean public Map consumerConfigurations() { Map 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); diff --git a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaProducerConfig.java b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaProducerConfig.java index b3056e2f..134bdfd2 100644 --- a/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaProducerConfig.java +++ b/backend/live/src/main/java/org/samtuap/inong/domain/chat/kafka/KafkaProducerConfig.java @@ -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; @@ -17,6 +18,9 @@ @Configuration public class KafkaProducerConfig { + @Value("${spring.kafka.bootstrap-servers}") + private String KAFKA_HOST; + @Bean public ProducerFactory producerFactory() { return new DefaultKafkaProducerFactory<>(producerConfigurations()); @@ -25,7 +29,7 @@ public ProducerFactory producerFactory() { @Bean public Map producerConfigurations() { Map 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; diff --git a/backend/live/src/main/resources/application-prod.yml b/backend/live/src/main/resources/application-prod.yml index 67a8d91c..4be82e5f 100644 --- a/backend/live/src/main/resources/application-prod.yml +++ b/backend/live/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 0 + port: 8080 spring: config: @@ -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: diff --git a/backend/member/Dockerfile b/backend/member/Dockerfile index 6494c127..df3e9d78 100644 --- a/backend/member/Dockerfile +++ b/backend/member/Dockerfile @@ -1,4 +1,3 @@ - FROM openjdk:17-jdk-alpine as stage1 WORKDIR /app diff --git a/backend/member/build.gradle b/backend/member/build.gradle index 5c43714a..50c721d6 100644 --- a/backend/member/build.gradle +++ b/backend/member/build.gradle @@ -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' @@ -47,6 +47,8 @@ dependencies { // fcm implementation 'com.google.firebase:firebase-admin:9.3.0' + implementation 'com.thoughtworks.xstream:xstream:1.4.20' + } dependencyManagement { diff --git a/backend/member/k8s/member-depl.yml b/backend/member/k8s/member-depl.yml index 8142a21a..54fbc98d 100644 --- a/backend/member/k8s/member-depl.yml +++ b/backend/member/k8s/member-depl.yml @@ -144,7 +144,7 @@ spec: #무중단 배포를 위한 컨테이너 헬스체크 readinessProbe: httpGet: - path: /member-service/member/healthcheck + path: /member/healthcheck port: 8080 # 컨테이너 시작 후 지연 시간 설정 initialDelaySeconds: 20 diff --git a/backend/member/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java b/backend/member/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java index 41ba0fb3..fbba829b 100644 --- a/backend/member/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java +++ b/backend/member/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java @@ -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; diff --git a/backend/member/src/main/resources/application-prod.yml b/backend/member/src/main/resources/application-prod.yml index 3b7f432f..01fc46e8 100644 --- a/backend/member/src/main/resources/application-prod.yml +++ b/backend/member/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 0 + port: 8080 spring: config: @@ -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: @@ -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} \ No newline at end of file diff --git a/backend/order/build.gradle b/backend/order/build.gradle index 309623b4..9d7e1be4 100644 --- a/backend/order/build.gradle +++ b/backend/order/build.gradle @@ -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' diff --git a/backend/order/k8s/order-depl.yml b/backend/order/k8s/order-depl.yml index d0516d0a..228f93d9 100644 --- a/backend/order/k8s/order-depl.yml +++ b/backend/order/k8s/order-depl.yml @@ -79,7 +79,7 @@ spec: #무중단 배포를 위한 컨테이너 헬스체크 readinessProbe: httpGet: - path: /order-service/order/healthcheck + path: /order/healthcheck port: 8080 # 컨테이너 시작 후 지연 시간 설정 initialDelaySeconds: 20 diff --git a/backend/order/src/main/resources/application-prod.yml b/backend/order/src/main/resources/application-prod.yml index cd655cb4..f0da158b 100644 --- a/backend/order/src/main/resources/application-prod.yml +++ b/backend/order/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 0 + port: 8080 spring: config: @@ -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: @@ -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} \ No newline at end of file + channel-key: ${PORTONE_CHANNELKEY} diff --git a/backend/product/build.gradle b/backend/product/build.gradle index 0a987abd..ec8cf3d7 100644 --- a/backend/product/build.gradle +++ b/backend/product/build.gradle @@ -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' @@ -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') { diff --git a/backend/product/k8s/product-depl.yml b/backend/product/k8s/product-depl.yml index b9fbd589..ce72a214 100644 --- a/backend/product/k8s/product-depl.yml +++ b/backend/product/k8s/product-depl.yml @@ -104,7 +104,7 @@ spec: #무중단 배포를 위한 컨테이너 헬스체크 readinessProbe: httpGet: - path: /product-service/product/healthcheck + path: /product/healthcheck port: 8080 # 컨테이너 시작 후 지연 시간 설정 initialDelaySeconds: 20 diff --git a/backend/product/src/main/resources/application-prod.yml b/backend/product/src/main/resources/application-prod.yml index 5db7e993..a92cd4a3 100644 --- a/backend/product/src/main/resources/application-prod.yml +++ b/backend/product/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 0 + port: 8080 spring: config: activate: @@ -31,6 +31,7 @@ spring: bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS} consumer: group-id: product-group + group-instance-id: ${HOSTNAME}-instance auto-offset-reset: earliest data: redis: @@ -79,4 +80,3 @@ cloud: auto: false stack: auto: false -