Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

csct3434

[Spring Cloud Config Server] Github Private Repository 연동하기 본문

개발 일지

[Spring Cloud Config Server] Github Private Repository 연동하기

csct3434 2025. 2. 8. 02:08

1. ECDSA 키 생성

ssh-keygen -t ecdsa -b 256 -f config-repo-key

 

  • config-repo-key : 개인키 파일 / Config 서버 application.yml에 등록
  • config-repo-key.pub : 공개키 파일 / GitHub에 등록

2. Github Repository Deploy key 추가

  • Repository Settings > Deploy keys로 이동
  • "Add deploy key" 클릭
  • 위에서 생성한 공개키(config-server-key.pub) 내용 입력
  • "Allow write access" 체크 해제 (읽기 전용)

3. Spring Cloud Config Server 설정

[build.gradle]

tasks.named("bootJar") {
    enabled = true
}

ext {
    set('springCloudVersion', '2024.0.0')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-config-server'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

 

[application.yml]

server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:example/config.git
          default-label: main
          ignore-local-ssh-settings: true
          private-key: |
            -----BEGIN OPENSSH PRIVATE KEY-----
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
            AAAAAAAAAAAAAAAA
            -----END OPENSSH PRIVATE KEY-----
          strict-host-key-checking: true
          hostKeyAlgorithm: ecdsa-sha2-nistp256
          host-key: AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=

 

  • uri : Github Repository > Code > SSH 주소 입력
  • default-label : Repository의 기본 브랜치명
  • private-key : 위에서 생성한 개인키(config-server-key) 내용 입력
  • strict-host-key-checking: true : GitHub 호스트 키 검증 활성화
  • host-key : GitHub의 호스트 키 / hostKeyAlgorithm : Github의 호스트 키 알고리즘
    • ssh-keyscan -t ecdsa github.com 명령어로 확인

 

[SpringApplication]

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
  • @EnableConfigServer 어노테이션 추가

4. 테스트

요청

# 예시 : application.yml
curl http://localhost:8888/gateway/default

# 예시 : application-prod.yml
curl http://localhost:8888/application/prod

# 예시 : application-local.yml
curl http://localhost:8888/application/local

# 예시 : gateway.yml
curl http://localhost:8888/gateway/default

 

결과 : gateway.yml 

{
  "name": "gateway",
  "profiles": [
    "default"
  ],
  "label": null,
  "version": "585372dd4775ade63ff15580e3b78a1cf187cc8d",
  "state": "",
  "propertySources": [
    {
      "name": "git@github.com:example/config.git/gateway.yml",
      "source": {
        "GATEWAY.USER_SERVICE_URL": "http://${USER_SERVICE_URL:localhost}:8090",
        "GATEWAY.STORE_SERVICE_URL": "http://${STORE_SERVICE_URL:localhost}:8095",
      }
    }
  ]
}