요즘 회사에서 msa 기반으로 프로젝트를 진행하다 보니 msa 구조를 좀 더 잘 짤 수 있을거 같아졌다. 지금까지 기능을 구현하느라 설정 파일들을 제대로 정리하지 않았어서 오늘 정리하려고 한다.
이전에 파일로 늘어놨던 구조에서 모두 폴더에 파일을 넣었다.
공통 설정은 application.yml
파일로 정의해두면 모든 서비스에서 공통으로 설정값을 공유할 수 있다.
token key 값, actuator 설정을 공통으로 처리했다.
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} 네이밍으로도 파일을 찾아주기 때문에 다음과 같이 깔끔하게 정리할 수 있다.
실서버에 적용해도 정상적으로 나온다.
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
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
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
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에서 정보를 가져와서 실행되도록 수정되었다!