csct3434
[Spring Cloud Config Server] Github Private Repository 연동하기 본문
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",
}
}
]
}
'개발 일지' 카테고리의 다른 글
실시간 통신 방식 비교 : Polling, Long Polling, Server Sent Event, WebSocket (0) | 2025.01.17 |
---|---|
STOMP (Simple Text Oriented Messaging Protocol) (10) | 2024.07.23 |
AWS WAF를 활용한 봇 공격 차단 (feat. web ACL) (1) | 2024.06.04 |
CloudWatch Log Group으로 로그 전송하기 (feat. CloudWatch Agent) (0) | 2024.05.25 |
스프링부트 액세스 로그 설정 방법 (0) | 2024.05.25 |