๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
BackEnd๐ŸŒฑ/Etc

[GitHub] submodule ์‚ฌ์šฉํ•ด์„œ yml๊ณผ ๊ฐ™์€ ๋ฏผ๊ฐํ•œ ์ •๋ณด ์ˆจ๊ธฐ๊ธฐ

by dkswnkk 2022. 7. 10.

์„œ๋ก 

๋ณดํ†ต ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด GitHub ์ƒ์—์„œ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ์ง€ ์•Š์€ ๋ฏผ๊ฐํ•œ ์ •๋ณด๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. Spring Boot๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ DB์˜ ๊ณ„์ • ๋“ฑ์„ ๋‹ด์„ .ymlํŒŒ์ผ๋“ค์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ”„๋กœ์ ํŠธ ์ž์ฒด๋ฅผ private๋กœ ์„ค์ •ํ•ด์„œ ๋…ธ์ถœ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๊ฒ ์ง€๋งŒ submodule์„ ์‚ฌ์šฉํ•˜๋ฉด ํŠน์ • ํด๋”๋งŒ private๋กœ ์„ค์ •ํ•ด์„œ ๋…ธ์ถœ์„ ๋ง‰์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ์ด๋ฒˆ ๊ฒŒ์‹œ๊ธ€์—์„œ๋Š” git submodule์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ณ , Spring Boot ํ™˜๊ฒฝ์—์„œ ymlํŒŒ์ผ๋“ค์„ ์ˆจ๊ฒจ๋ณด๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ตฌ์ฒด์ ์ธ ๊ณผ์ •

1. public repository ์ƒ์„ฑ

public respository

๋จผ์ € ์œ„์™€ ๊ฐ™์ด public repository๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ €๋Š” ๊ธฐ์ดˆ์ ์ธ spring boot ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ์กด์˜ yml ํŒŒ์ผ ๊ฒฝ๋กœ

๊ธฐ์กด์—๋Š” ์œ„์™€ ๊ฐ™์ด submodule-test/src/main/resources ๊ฒฝ๋กœ์— application.yml ํŒŒ์ผ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ์˜ ๋ชฉ์ ์€ ์ด ๋ฏผ๊ฐํ•œ ์ •๋ณด๊ฐ€ ๋‹ด๊ธด yml ํŒŒ์ผ๋“ค์„ public repository์—์„œ ์ˆจ๊ธฐ๋”๋ผ๋„ ํ”„๋กœ์ ํŠธ๋Š” ์ •์ƒ์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ public repository์˜ application.ymlํŒŒ์ผ์€ ์‚ญ์ œํ•ด ์ค๋‹ˆ๋‹ค.

public repository์˜ yml ์‚ญ์ œ


2. ๋ฏผ๊ฐํ•œ ์ •๋ณด๋ฅผ ๋‹ด์„ private repository ์ƒ์„ฑ

private repository

๋‹ค์Œ์œผ๋กœ yml ํŒŒ์ผ๋“ค์„ ๋‹ด์„ private repository๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

private repository์— yml ์ถ”๊ฐ€

๊ทธ ํ›„ ํ”„๋กœ์ ํŠธ์˜ ๋ฏผ๊ฐํ•œ ์ •๋ณด๊ฐ€ ๋‹ด๊ธธ application.yml ํŒŒ์ผ์„ priavate respotitory์— ์ƒ์„ฑํ•˜์—ฌ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
๊ฐ„๋‹จํ•˜๊ฒŒ ๊ทธ๋ƒฅ public repository์— ์กด์žฌํ•˜๋Š” ๋ฏผ๊ฐํ•œ ์ •๋ณด๋ฅผ private repository๋กœ ์˜ฎ๊ธฐ๊ณ , clone์‹œ์—๋งŒ ์—ฐ๋™ํ•ด์„œ ๊ฐ€์ ธ์˜จ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

3. public repository์— submodule ๋“ฑ๋ก

git submodule add ${์„œ๋ธŒ ๋ชจ๋“ˆ๋กœ ๋“ฑ๋กํ•  github repository์˜ ์ฃผ์†Œ}

main ํ”„๋กœ์ ํŠธ์— submodule ๋“ฑ๋ก

์œ„์™€ ๊ฐ™์ด ๋ฉ”์ธ ํ”„๋กœ์ ํŠธ์— submodule์„ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ์ตœ์ƒ์œ„ ๊ฒฝ๋กœ์— submodule์ด ์ƒ์„ฑ๋จ

๊ทธ๋Ÿฌ๋ฉด ์œ„์™€ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ์˜ ์ตœ์ƒ์œ„ ๊ฒฝ๋กœ์— submodule์˜ repository name์„ ๊ฐ€์ง„ ํด๋”๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

4. .gitmodules ํ™•์ธ

์œ„ ๊ณผ์ •๊นŒ์ง€ ๊ฑฐ์ณค๋‹ค๋ฉด ํ”„๋กœ์ ํŠธ์˜ ์ตœ์ƒ์œ„ ํด๋”์— .gitmodules ํŒŒ์ผ์ด ์ƒ์„ฑ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

.gitmodules ํŒŒ์ผ์ด ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค.

์ด์ œ ๋ฉ”์ธ ํ”„๋กœ์ ํŠธ๋ฅผ github๋กœ push ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด main ํ”„๋กœ์ ํŠธ(public repository)์— submodule(private repository)๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

main ํ”„๋กœ์ ํŠธ์— private repository์ธ submodule๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ๋‹ค.

public repository ์ด๋”๋ผ๋„ ์œ„ submodule ํด๋”๋Š” private respository ๊ถŒํ•œ์ด ์—†๋Š” ์œ ์ €๋Š” ์ ‘๊ทผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.


5. ๋งŒ์•ฝ submodule์˜ ํŒŒ์ผ์ด ์ˆ˜์ •๋˜์—ˆ๋‹ค๋ฉด?

๋งŒ์•ฝ submodule์˜ ํŒŒ์ผ์ด ์ˆ˜์ •๋˜์—ˆ๋‹ค๋ฉด git submodule update --remote ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ submodule์˜ ์ตœ์‹  ๋‚ด์šฉ์„ ๋ฉ”์ธ ํ”„๋กœ์ ํŠธ์— ๊ฐฑ์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ main project๋ฅผ ์ƒˆ๋กœ clone ํ•˜์˜€์„ ๊ฒฝ์šฐ์—๋„ ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ submodule์„ ๋ฐ›์•„ ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

6. gradle์„ submodules์˜ ๋‚ด์šฉ์„ ๋นŒ๋“œ ์‹œ ๊ฐ€์ ธ์˜ค๊ธฐ

์ด์ œ submoduleํด๋”์— ์žˆ๋Š” yml ํŒŒ์ผ๋“ค์„ ๋นŒ๋“œ ์‹œ์— submodule-test/src/main/resources ๊ฒฝ๋กœ๋กœ ๊ฐ€์ ธ์˜ค๊ฒŒ ํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
build.gradle์— ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

task copyPrivate(type: Copy) {
	copy {
		from './submodule-data'
		include "*.yml"
		into 'src/main/resources'
	}
}

from์€ submodule์˜ ํด๋”๋ฅผ ์ง€์นญํ•˜๊ณ , include๋Š” ํฌํ•จํ•  ํŒŒ์ผ, ๊ทธ๋ฆฌ๊ณ  into๋Š” ๋นŒ๋“œ ์‹œ์— ๋„ฃ์„ ๊ฒฝ๋กœ๋ฅผ ์ง€์นญํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ

๊ฐ„๋‹จํ•˜๊ฒŒ ์œ„์™€ ๊ฐ™์ด TestEntity๋ฅผ ๋งŒ๋“ค์—ˆ๊ณ , ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๋ฌด์‚ฌํžˆ ํ…Œ์ด๋ธ”์ด ์ƒ์„ฑ๋˜๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋Œ“๊ธ€