Sign inSign up

datamario24/sc-gateway

By datamario24

•Updated 12 months ago

Image
0

396

datamario24/sc-gateway repository overview

⁠SCG

⁠도커빌드

# 명령어 형식: docker build -t <도커허브아이디>/<이미지 이름>:<태그> <빌드 컨텍스트 경로>

$ docker build -t datamario24/sc-gateway:0.2.0 .
$ docker push datamario24/sc-gateway:0.2.0

⁠도커 컴포즈 환경 변수 설정 예시

  • 설정 예시
  • atamario24/sc-gateway:0.3.0 버전 이후 부터 적용 가능
services:
  # 게이트웨이 서비스 (sc-gateway)
  gateway:
    image: my-spring-app:1.0 # 빌드된 Docker 이미지 이름
    ports:
      - "9000:9000"
    environment:
      # 💡 Compose 내부의 다른 서비스 이름을 사용하여 URI를 설정합니다.
      - HELLO_SERVICE_URI=http://hello-service:8080
    depends_on:
      - hello-service
    networks:
      - my-network

  # 타겟 서비스 (hello-service)
  hello-service:
    image: my-target-app:1.0
    ports:
      - "8765:8080" # 외부로 8765 포트 노출 (선택 사항)
    networks:
      - my-network
    # Compose 내부에서는 서비스 이름(hello-service)이 DNS 역할을 합니다.

networks:
  my-network:
    driver: bridge

⁠도커허브 경로 및 사용

$ docker pull datamario24/sc-gateway:0.2.0
server:
  port: 9000

spring:
  application:
    name: sc-gateway

  cloud:
    gateway:
      routes:
        - id: hello_route # 새로 추가할 라우트의 ID
          uri: http://localhost:8765 # 타겟 서비스의 URI
          predicates:
            - Path=/hello # 매칭할 경로 (정확히 /hello)

          # abc2hello_route
          # 1. http://localhost:9000/hello 로 들어오면
          # 2. http://localhost:8765/hello 로 연결

        - id: abc2hello_route # 새로 추가할 라우트의 ID
          uri: http://localhost:8765 # 타겟 서비스의 URI
          predicates:
            - Path=/abc

          # abc2hello_route
          # 1. http://localhost:9000/abc 로 들어오면
          # 2. http://localhost:8765/abc 로 연결

        - id: def2hello_ok_route # 새로 추가할 라우트의 ID
          uri: http://localhost:8765 # 타겟 서비스의 URI
          predicates:
            - Path=/def
          filters:
            - RewritePath=/def, /hello

          # abc2hello_ok_route
          # 1. http://localhost:9000/def 로 들어오면
          # 2. 필터에서 def 를 hello 로 바꾸어서 설정된 uri 로 보냄
          # 3. http://localhost:8765/hello 로 연결

logging:
  level:
    # Spring Cloud Gateway의 라우팅, 필터 체인 관련 로그
    org.springframework.cloud.gateway: DEBUG

    # 리액터(Netty) 네트워크 통신 로그 (요청/응답 상세)
    reactor.netty: DEBUG

    # Spring WebFlux (게이트웨이 기반 기술) 관련 로그
    org.springframework.web.reactive: DEBUG

Tag summary

Content type

Image

Digest

sha256:f011ddd13…

Size

251.5 MB

Last updated

12 months ago

docker pull datamario24/sc-gateway:0.5.1