본문 바로가기

MSA (MicroServiceArchitecture)/MSA Application (온라인 쇼핑몰))

6. git에 config 정보 저장하기

# git에 config 정보를 저장하기

1. github에 퍼블릭으로 저장소를 생성한다.

spring-cloud-config라는 이름으로 저장소를 생성한다.

그리고 생성한 저장소의 주소를 복사한다.

https://github.com/Nanninggu/spring-cloud-config.git

 

Nanninggu/spring-cloud-config

Contribute to Nanninggu/spring-cloud-config development by creating an account on GitHub.

github.com

2. remote repository로 등록하기

- 현재 연결정보 확인

git remote -v

- 위에서 복사한 레포지토리 정보를 remote 정보로 등록하기

git remote add origin https://github.com/Nanninggu/spring-cloud-config.git

다시 git remote -v로 등록된 git 주소를 확인 할 수 있다.

- 이전에 config 정보를 git commit 까지 진행 했기때문에 push 작업을 진행한다.

3. git 저장소로 push 하기

git push --set-upstream origin master

위의 명령어를 실행하면 로그인 화면창이 나올 수 있다.

- github으로 이동하여 확인해보면 해당 레포지토리에 파일 1개가 업로드 되어 있는것을 확인 할 수 있다.

해당 파일을 config 정보로 불러와 사용을 해보자.

4. config-service로 이동하여 uri 값을 변경한다.

- config-service의 application.yaml 파일의 정보를 아래와 같이 변경한다.

  cloud:
    config:
      server:
        git:
#          uri: file:///git/git/git-local-repo
          uri: https://github.com/Nanninggu/spring-cloud-config.git

- 재기동 후 웹브라우저에서 확인한다.

git 레포지토리에서 정보를 가져와 화면에 표시한다.

5. dev, stg, prd의 config 정보를 나누어 적용하는 방법

- 아래의 url 주소를 참고하여 로컬 폴더에 아래와 같이 dev, stg, prd 각각의 config 파일을 생성한다.

2023.04.06 - [MSA (MicroServiceArchitecture)/MSA Application (온라인 쇼핑몰))] - 5. Config 서비스 생성

 

5. Config 서비스 생성

# Condig 서비스를 생성하여 환경설정 정보를 한곳에서 구현하도록 한다. Config 서비스가 필요한 이유는 여러가지 환경설정 정보를 공통으로 서비스 하도록 하는것이 첫번째 목적이고 두번째목적

may9noy.tistory.com

그리고 위에서 생성한 git repository에 git add, commit, push를 수행하여 업로드를 한다.

- 아래와 같이 url에 dev, stg, prd만 변경하여 적용하면 config 정보를 적용 시킬수 있다.

6. local 경로에 config 정보를 저장하고 불러오기

- local 디렉토리에 config 정보를 저장하고 불러오는 과정을 알아본다.

파일의 수정 경로는 config-service > application.yaml 파일을 아래와 같이 수정한다.

- 내용 수정

server:
  port: 8888

spring:
  application:
    name: config-service
  profile:
    active: native
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest
  cloud:
    config:
      server:
        native:
          search-locations: file:///${user.home}/git/git/git-local-repo
        git:
#          uri: file:///git/git/git-local-repo
          uri: https://github.com/Nanninggu/spring-cloud-config.git
#          [private_repository]
#          username: [your_username]
#          password: [your_password]
management:
  endpoints:
    web:
      exposure:
        include: health, busrefresh

- 웹 브라우저에서 config 정보를 정상적으로 가져 오는지 확인

- 끝 -