프로젝트 config 파일 정리

최준호·2022년 5월 16일
0

game

목록 보기
13/14
post-thumbnail

👏프로젝트 정리!

요즘 회사에서 msa 기반으로 프로젝트를 진행하다 보니 msa 구조를 좀 더 잘 짤 수 있을거 같아졌다. 지금까지 기능을 구현하느라 설정 파일들을 제대로 정리하지 않았어서 오늘 정리하려고 한다.

🔨config 파일과 yml 설정 변경

이전에 파일로 늘어놨던 구조에서 모두 폴더에 파일을 넣었다.
공통 설정은 application.yml 파일로 정의해두면 모든 서비스에서 공통으로 설정값을 공유할 수 있다.

token key 값, actuator 설정을 공통으로 처리했다.

config

bootstrap.yml

server:
  port: 8888

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: ${git.uri:file://C:/config}
          username: ${git.username:username}
          password: ${git.password:passowrd}
          searchPaths: '{application}' #/{application}/{application}-{profile}

config server에서 설정 파일들을 찾을 때 searchPaths를 설정해주면{application}/{application}-{profile} 네이밍으로도 파일을 찾아주기 때문에 다음과 같이 깔끔하게 정리할 수 있다.

실서버에 적용해도 정상적으로 나온다.

eureka

bootstrap.yml

spring:
  cloud:
    config:
      uri: ${spring.config.uri:http://127.0.0.1:8888}
      name: eureka
      profile: ${spring.config.profile:local}

docker-compose.yml

version: '3.7'
  
services:
    eureka:
        build : /msa/jenkins/data/workspace/Eureka/.
        container_name: eureka
        expose: 
            - "8761"
        environment:
            - spring.config.uri=http://config:8888
            - spring.config.profile=prod
networks:
    default:
        external:
            name: msa

gateway

bootstrap.yml

spring:
  cloud:
    config:
      uri: ${spring.config.uri:http://127.0.0.1:8888}
      name: gateway
      profile: ${spring.config.profile:local}

docker-compose.yml

version: '3.7'
  
services:
    gateway:
        build: /msa/jenkins/data/workspace/gateway/.
        container_name: gateway
        expose: 
            - "8000"
        environment:
            - spring.config.uri=http://config:8888
            - spring.config.profile=prod
networks:
    default:
        external:
            name: msa

login

bootstrap.yml

spring:
  cloud:
    config:
      uri: ${spring.config.uri:http://127.0.0.1:8888}
      name: login
      profile: ${spring.config.profile:local}

docker-compose.yml

version: '3.7'
  
services:
    login:
        build: /msa/jenkins/data/workspace/login/.
        container_name: login
        environment:
            - spring.config.uri=http://config:8888
            - spring.config.profile=prod
networks:
    default:
        external:
            name: msa

game

bootstrap.yml

spring:
  cloud:
    config:
      uri: ${spring.config.uri:http://127.0.0.1:8888}
      name: game
      profile: ${spring.config.profile:local}

docker-compose.yml

version: '3.7'
  
services:
    game:
        build: /msa/jenkins/data/workspace/game/.
        container_name: game
        environment:
            - spring.cloud.config.uri=http://config:8888
            - spring.cloud.config.profile=prod
networks:
    default:
        external:
            name: msa

이렇게 모든 서비스들을 정리했다. 파일만 수정하고 git에 올린 뒤 jenkins로 모두 처리했더니 생각보다 금방 끝났다. 역시 뭐든... 시작할 때 자동화 시켜놓으면 코딩이 너무 편해지는 것 같다.

모두 성공적으로 처리되었다.

이제 프로젝트 자체에 설정이 있는 프로젝트는 없어졌으며 모두 config server에서 정보를 가져와서 실행되도록 수정되었다!

profile
코딩을 깔끔하게 하고 싶어하는 초보 개발자 (편하게 글을 쓰기위해 반말체를 사용하고 있습니다! 양해 부탁드려요!) 현재 KakaoVX 근무중입니다!

0개의 댓글