클라우드 네이티브에서는 환경마다 다른 개발환경을 셋팅해주어야한다.
ex) 로컬에서는 컴퓨터의 메모리 저장소(h2, redis)나 mysql 과 같은 것을 사용하고, 운영이나 테스트 환경에서는 서버로 배포하여 각각의 환경이 분리되도록 설정해 주어야 한다.
yaml
파일)를 외부 시스템에서 관리하기 위한 기술Actions secrets and variables
을 통해 환경변수를 관리해 주었는데, 이 방법은 설정하고 나면 암호화되어 값의 확인이 불가능하다는 단점이 있다.dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Config Server
의존성을 추가해준다.spring:
application:
name: config-service
cloud:
config:
server:
git:
uri: https://github.com/ajou20658/spring-cloud-config
# username: [my username] # private 을 사용할 경우 명시 필요
# passphrase: [my password] # private 을 사용할 경우 명시 필요
# uri: file://C:\Users\kwy13\Desktop\git-local-repo
server:
port: 8888
로컬의 깃에 설정 파일을 커밋해둔다면 로컬 환경에서도 사용할 수 있다.
원격의 깃의 설정 파일 또한 사용 가능하다.
@SpringBootApplication
@EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
기존의 코드에 @EnableConfigServer
어노테이션을 추가해줘야 ConfigServer가 활성화된다.
의존성에서 Cloud Bootstrap
과 Config Client
를 추가한다.