[DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ

2022. 9. 3. 00:45ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

์ด ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ - Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ ์ž…๋‹ˆ๋‹ค.


ํ•ด๋‹น ๋‚ด์šฉ์˜ Code ๋‚ด์šฉ์€ ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.






๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Infrastructure as Code ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ก - SonarQube
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ข - Multi Nodes
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ƒ์šฉ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ๋ถ€๋ก


 






 

๐Ÿš€ ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ

    ๐Ÿ”ฝ  Jenkins๋ฅผ ์ด์šฉํ•œ CI / CD ์‚ฌ์šฉ

        ๐Ÿ“ฆ CI / CD๋ฅผ ์œ„ํ•œ Git, Maven ์„ค์ •

Manage Jenkins -> Jenkins Plugins -> available -> github


์ตœ์ดˆ github Plugin์ด ์„ค์น˜ ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ์„ ํ•ด์•ผ ํ•ด์š”.
์„ค์น˜๊ฐ€ ๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด ์„ค์น˜๋ฅผ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด ์„ค์น˜๊ฐ€ ๋˜์–ด ์žˆ์–ด์š”.



Manage Jenkins -> Global Tool Configuration -> git



Jenkins ๊ด€๋ฆฌ์—์„œ Global Tool Configuration์— ๋“ค์–ด๊ฐ€๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด Git์— ๋Œ€ํ•œ ์„ค์ • ๋ถ€๋ถ„์ด ์žˆ์–ด์š”.




์œ„์— ๊ทธ๋ฆผ์—์„œ ์ด๋ฆ„์€ Git ๊ด€๋ จํ•˜์—ฌ ์ด๋ฆ„์„ ์ž์œ ๋กญ๊ฒŒ ์ง€์ •ํ•ด ์ฃผ๋ฉด ๋˜๊ณ , Path to Git executable์—๋Š” git ๊ด€๋ จ ๋ช…๋ น์–ด๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ๋˜์š”.

์ด ๊ณณ์— git์„ ๋„ฃ์—ˆ๋‹ค๋Š” ๊ฒƒ์€ git ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ๋ช…๋ น์–ด ์ ‘๋‘์‚ฌ๊ฐ€ git์œผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๊ณ , ์ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ์—์š”.



์ฃผ๋‹ˆํ•˜๋ž‘์€ Synology NAS์— docker๋ฅผ ์ด์šฉํ•˜์—ฌ Ubuntu๋ฅผ ์„ค์น˜ํ–ˆ๊ณ , ๊ทธ ์•ˆ์— Jenkins๋ฅผ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.
ํ˜„์žฌ Docker๋กœ ๊ธฐ๋™๋˜๊ณ  ์žˆ๋Š” Container๋Š” ์œ„์™€ ๊ฐ™์ด 3๊ฐœ๊ฐ€ ์กด์žฌํ•˜๊ณ  ์žˆ์–ด์š”.



Jenkins๊ฐ€ ๊ตฌ๋™์ค‘์ธ Container์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด Container ID ๊ฐ’์„ ์œ„์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๊ณ , bash shell์„ ์ด์šฉํ•˜๊ฒ ๋‹ค๊ณ  ์ •์˜ํ•œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ๋”๋‹ˆ ํ•ด๋‹น Container์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ์—ˆ์–ด์š”.



Jenkins Container์— git์ด ์„ค์น˜ ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด ํ™•์ธ์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ 2.34.1 Version์— git์ด ์„ค์น˜ ๋˜์–ด ์žˆ์–ด์š”.



์ด๋ฒˆ์—๋Š” maven plugin์„ ์„ค์น˜ํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.


Manage Jenkins -> Jenkins Plugins -> available(์„ค์น˜ ๊ฐ€๋Šฅ) -> maven

 

์œ„์™€ ๊ฐ™์ด maven Plugin์„ ์ฐพ์•„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.





Manage Jenkins -> Global Tool Configuration

 


ํ•ด๋‹น Plugin์ด ์„ค์น˜๊ฐ€ ์™„๋ฃŒ ๋˜์—ˆ๋‹ค๋ฉด Global Tool Configuration์— Maven ์ชฝ์œผ๋กœ ์ด๋™์„ ํ•ด ์ฃผ์„ธ์š”.



728x90


Add Maven์„ ๋ˆ„๋ฅด๋ฉด ์œ„์™€ ๊ฐ™์ด Maven์„ ์„ค์น˜ํ•˜๊ณ , ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด ๋‚˜์™€์š”.

Install automatically๋ฅผ ๋ˆ„๋ฅด๋ฉด Jenkins Server์— maven์„ ์ž๋™์œผ๋กœ ์„ค์น˜ํ•ด ์ค„ ๊ฑฐ์—์š”.


mvn --version


Jenkins Container์—์„œ ์„ค์น˜ ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ณด๊ธฐ ์œ„ํ•ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ๋”๋‹ˆ ์—ญ์‹œ ์„ค์น˜๊ฐ€ ๋˜์ง€ ์•Š์€ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.



์ฃผ๋‹ˆํ•˜๋ž‘์€ ์ตœ์‹  ๋ฒ„์ „๋ณด๋‹ค ํ•œ๋‹จ๊ณ„ ์•„๋ž˜ Version์ธ 3.8.5 Version์„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.

๋งจ ๋ฐ‘์— Apply๋ฅผ ๋ˆ„๋ฅด๊ณ , save๋ฅผ ๋ˆ„๋ฅธ ๋’ค ํ•ด๋‹น ํ™”๋ฉด์„ ๋‚˜์™€์ค๋‹ˆ๋‹ค.






์ด๋ฒˆ์—๋Š” Meven Project๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋„๋ก ํ•ด๋ณผ๊ฒŒ์š”.


Item name

 

Jenkins Main ํ™”๋ฉด์—์„œ new Item์„ ๋ˆ„๋ฅด๋ฉด ์œ„์™€ ๊ฐ™์€ ํ™”๋ฉด์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ์–ด์š”.




์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด Item ์ด๋ฆ„์„ ์ •์˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด์ œ Maven project๋ฅผ ๋ˆ„๋ฅธ ๋’ค OK๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.




General ๋ถ€๋ถ„์— ๊ฐ„๋‹จํ•œ maven ๊ด€๋ จ Command๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.




Github๊ณผ Jenkins ์—ฐ๋™์„ ์œ„ํ•ด ํ•ด๋‹น Project๋ฅผ ์œ„ํ•œ Repository๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



์ด์ œ ์œ„์™€ ๊ฐ™์ด ์ค€๋น„๋œ Repository๋ฅผ ์—ฐ๊ฒฐํ•ด ๋ณด๋„๋ก ํ• ๊ฑฐ์—์š”.






Jenkins์—์„œ๋Š” ์†Œ์Šค ์ฝ”๋“œ ๊ด€๋ฆฌ์— ์œ„์™€ ๊ฐ™์ด Github Repository ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

Credentials๋Š” ํ•ด๋‹น Git hub Repository๊ฐ€ Private์ด๋ผ๋ฉด ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•œ ๊ณ„์ •๊ฐ’์„ ๋„ฃ์–ด์•ผ ํ•ด์š”.

ํ•˜์ง€๋งŒ, ์ง€๊ธˆ์€ Pubilc์ด๊ธฐ ๋•Œ๋ฌธ์— ๋„ฃ์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.






Pre Steps๋ฅผ ๋ˆ„๋ฅด๊ฒŒ ๋˜๋ฉด ์œ„์™€ ๊ฐ™์€ ์ฐฝ์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ์–ด์š”.

ํ•ด๋‹น Project๋Š” Meven์„ ์ด์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— Source Code๋ฅผ Meven Build Tool๋กœ Compile์„ ํ•˜๋„๋ก ์ž‘์—…ํ•  ๊ฒƒ์ด์—์š”.


Meven ์„ค์ • ๊ด€๋ จ ๋‚ด์šฉ์€ pom.xml์— ๋“ค์–ด๊ฐ€ ์žˆ์–ด์š”.

Root Pom์€ ์ด ์„ค์ •๊ฐ’์ด ๋“ค์–ด๊ฐ„ File์ธ pom.xml์„ ๋ฐ”๋ผ๋ณด๊ฒŒ ํ•ด์ฃผ๊ณ ,

Goals and options์—๋Š” Build๋ฅผ ํ•  ๋•Œ, ์–ด๋–ค ํ•ญ๋ชฉ๋“ค์„ ๊ฐ€์ง€๊ณ  Buildํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์„ ํƒํ•ด ์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ, ์ด ๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด ๋˜์š”.



๋ช…๋ น์–ด ๋‚ด   ์šฉ
clean ๊ธฐ์กด์— Buildํ•œ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ์ง€์šฐ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.
(target Directory ์‚ญ์ œ)
compile Code๋ฅผ Compileํ•˜์—ฌ Buildํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.
package compile๋œ ๋‚ด์šฉ์— ๋”ฐ๋ผ pom.xml์— ์ง€์ •๋œ Option์— ๋”ฐ๋ผ
Package File ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.


๊ธฐ๋ณธ์ ์œผ๋กœ Maven๊ณผ Gradle์„ jar, war ํ˜•ํƒœ์— Package File์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์–ด์š”.

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ

Spring Boot Project๋Š” ๋‘๊ฐ€์ง€ ํ˜•ํƒœ๋กœ Program์„ ๊ธฐ๋™ํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ฒซ๋ฒˆ์งธ๋Š” Web Application์ธ ๊ฒฝ์šฐ ์ž„๋ฒ ๋””๋“œ ํ†ฐ์ผ“์„ ๋‚ด์žฅํ•˜๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ์—์š”. ์ด ๋•Œ, jar ํ˜•ํƒœ๋กœ Packaging์„ ํ–ˆ์„ ๋•Œ, ํ•ด๋‹น jar๋ฅผ ์‹คํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด ํ†ฐ์ผ“์ด ๊ตฌ๋™๋˜๋Š” ๋ฐฉ์‹์ด์—์š”.

๋‘๋ฒˆ์งธ๋Š” ๋‚ด์žฅ๋œ ํ†ฐ์ผ“์ด ์•„๋‹Œ ๋‹ค๋ฅธ Web Application Server์— Packaging๋œ File์„ ๋ณต์‚ฌํ•˜์—ฌ ํ•ด๋‹น Server ์•ˆ์—์„œ ๊ธฐ๋™๋  ์ˆ˜ ์žˆ๊ฒŒ ๊ตฌ๋™๋˜๋Š” ๋ฐฉ์‹์ด๊ณ , ์ด ๋•Œ๋Š” war ํ˜•ํƒœ๋กœ ์ด์šฉ์„ ํ•ด์ฃผ๋ฉด ๋˜๋Š” ๊ฒƒ์ด์—์š”.



pom.xml


pom.xml์„ ํ™•์ธํ•ด๋ณด๋ฉด Packaging์„ war๋กœ ํ•˜๊ฒ ๋‹ค๊ณ  ์„ค์ •๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Build๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ๋๋‚˜๋ฉด war File๋กœ Packaging์ด ๋  ๊ฒƒ์ด์—์š”.

 

 


์ด๋ ‡๊ฒŒ ์„ค์ •์ด ์™„๋ฃŒ ๋˜์—ˆ์œผ๋ฉด ์ €์žฅ์„ ํ•ด ์ค๋‹ˆ๋‹ค.



๊ทธ๋Ÿฐ ๋’ค ์ง€๊ธˆ ๋นŒ๋“œ(Build now)๋ฅผ ์„ ํƒํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.



๊ทธ๋Ÿผ ์œ„์™€ ๊ฐ™์ด Build๊ฐ€ ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.

์œ„์˜ ์ž‘์—… ๋ฒˆํ˜ธ๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋ณด๋‹ค ์ž์„ธํ•œ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




Console Output์„ ๋ˆ„๋ฅด๋ฉด ์ž‘์—… ๋‚ด์šฉ์„ ๋ณด๋‹ค ์ƒ์„ธํžˆ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.





์œ„์™€ ๊ฐ™์ด Build ์ž‘์—…์ด ์„ฑ๊ณตํ•˜์˜€์–ด์š”.




ํ•ด๋‹น Project์— Workapce๋ฅผ ํ†ตํ•ด ๋‚ด์šฉ์„ ํ™•์ธ ํ•ด ๋ณผ๊ฒŒ์š”.




์ด ๊ณณ์—์„œ target์— ๋“ค์–ด๊ฐ€ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด war File์ด ๋งŒ๋“ค์–ด์ง„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



 


์ฐธ๊ณ ๋กœ Jenkins Container ๋‚ด์—์„œ ์œ„์˜ ์œ„์น˜์— war File์ด ์ €์žฅ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.











 

 

 

 

        ๐Ÿ“ฆ CI / CD๋ฅผ ์œ„ํ•œ Tomcat Server ์—ฐ๋™

์ด๋ฒˆ์—๋Š” Jenkins Plugin ์ค‘ Deploy to container(Tomcat Plugin)๋ฅผ ์„ค์น˜ํ•ด ๋ณผ๊ฒŒ์š”.

Manage Jenkins -> Jenkins Plugins -> available(์„ค์น˜ ๊ฐ€๋Šฅ) -> deploy to container plugin

๋ฐ˜์‘ํ˜•

์œ„์˜ Plugin์„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.






๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ

Deploy to container ๋ž€?

Jenkins๋ฅผ ํ†ตํ•ด Packaging ํ•œ war ํ˜น์€ jar File์„ Tomcat Web Application์ด ์„ค์น˜๋œ Server์— ๋ณต์‚ฌํ•˜์—ฌ ๊ตฌ๋™.

 


์„ค์น˜๊ฐ€ ์™„๋ฃŒ ๋˜์—ˆ๋‹ค๋ฉด ๋‘๋ฒˆ์งธ Project๋ฅผ ๋งŒ๋“ค์–ด๋ณผ๊ฒŒ์š”.




General์— ๊ฐ„๋‹จํ•œ ์„ค๋ช…๋ฌธ์„ ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.



์†Œ์Šค ์ฝ”๋“œ ๊ด€๋ฆฌ์—์„œ Git์„ ์„ ํƒํ•ด ์ฃผ์—ˆ๊ณ , Repository URL์— ํ•ด๋‹น Git Repository์— ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

Public Repository ์ด๊ธฐ ๋•Œ๋ฌธ์— Credentials๋Š” none์œผ๋กœ ๋‘๊ณ , ํ•ด๋‹น Respository์—์„œ ์ž‘์—…ํ•  Branch๋ฅผ ๊ผญ ๋งž์ถฐ์ฃผ์–ด์•ผ ํ•ด์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ master Branch์— push๊ฐ€ ๋˜๋ฉด ์ž‘์—…ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— master๋กœ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.





Build๋ฅผ ํ•  ๋•Œ, Maven Build๋ฅผ ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— Root POM์— pom.xml์„ ์ž…๋ ฅํ•ด์ฃผ์–ด ์‹คํ–‰๋  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.




๊ทธ ๋‹ค์Œ ๋นŒ๋“œ ํ›„ ์กฐ์น˜์— ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ๋ณผ๊ฒŒ์š”.



๋นŒ๋“œ ํ›„ ์กฐ์น˜ ์ถ”๊ฐ€๋ฅผ ๋ˆŒ์–ด Deploy war/ear ...๋ฅผ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค.


 


Build ๋‹จ๊ณ„์—์„œ war ํ˜น์€ jar File๋กœ Packaging (์••์ถ•)์ด ๋œ ๊ฒƒ์„ ์–ด๋–ค ์ž‘์—…์„ ํ•  ๊ฒƒ์ธ๊ฐ€๋ฅผ ์ •์˜ํ•ด ์ฃผ๋Š” ๋ถ€๋ถ„์ด์—์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ ํ•ด๋‹น Packaging์„ Container์— ๋ฐฐํฌ๋ฅผ ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์˜ ๋‚ด์šฉ์„ ์„ ํƒํ•œ ๊ฒƒ์ด์—์š”.

WAR/EAR files์—๋Š” ์ƒ์œ„ Directory ๋ชจ๋‘๋ฅผ ํฌํ•จํ•ด์„œ .war๋ผ๊ณ  ์ด๋ฆ„์ง€์–ด์ง„ Packaging๋œ File์„ ์„ ํƒํ•˜๊ฒ ๋‹ค๋Š” ๊ฒƒ์ด์—์š”. 

Context path์—๋Š” ์œ„์—์„œ ํ™•์ธํ•œ war File ์œ„์น˜๋ฅผ ์•Œ๋ ค์ฃผ๋ฉด ๋˜์š”.









๊ทธ๋Ÿฐ ๋’ค Tomcat 9 Version์„ ์„ ํƒํ•ด์„œ Container์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด ์ค„๊ฒŒ์š”.


์•„๋ž˜ ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— Tomcat Web Application Server๋ฅผ ์„ค์น˜ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.


ํ•ด๋‹น ๋‚ด์šฉ์€ ์ด ๊ณณ์— ์ •๋ฆฌ ํ•ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค.





์ตœ์ดˆ Credentials์— Add๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.


tomcat ๊ณ„์ • ๋ฐ ๊ถŒํ•œ ์ •๋ณด

 

์ฃผ๋‹ˆํ•˜๋ž‘์€ Tomcat์„ ์„ค์น˜ํ•  ๋•Œ, ์œ„์™€ ๊ฐ™์ด ๊ณ„์ •๊ณผ ๊ถŒํ•œ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด kind์— Username with password๋ฅผ ์„ ํƒํ•ด์ฃผ๊ณ , Username๊ณผ password์— deployer๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.


 




Tomcat URL์€ Tomcat Server๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๊ณ , ํ•ด๋‹น Tomcat Port ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์‹œ๋ฉด ๋˜์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์˜ Tomcat Server IP ์ฃผ์†Œ๋Š” ์œ„์™€ ๊ฐ™์ด ๋˜์–ด ์žˆ์–ด์š”.





๋ฐฐํฌํ•˜๊ธฐ ์ „ Tomcat Server์—๋Š” war File์ด Tomcat Home์— ์—†๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์ง€๊ธˆ ๋นŒ๋“œ (Build Now)

 

 

 


์ง€๊ธˆ ๋นŒ๋“œ๋ฅผ ๋ˆŒ๋Ÿฌ ๋นŒ๋“œ๋ฅผ ์‹คํ–‰ ํ•ด ๋ณผ๊ฒŒ์š”.





์ •์ƒ์ ์œผ๋กœ Build / ๋ฐฐํฌ๊ฐ€ ์„ฑ๊ณตํ•œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



Tomcat Server์— war File๋„ ์ „๋‹ฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



https://{tomcat IP or Domain}:Port ๋ฒˆํ˜ธ/manager/html

 

Tomcat Manager Page์— ๋ณด๋ฉด /hello-wold ๋ผ๋Š” ๊ฒฝ๋กœ์˜ Application์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์‹คํ–‰ ์ค‘์—๋Š” true๋กœ ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ๋ณด์•„ ์ •์ƒ ๊ตฌ๋™ ์ค‘์ธ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



ํ•ด๋‹น Application URL์„ ์ž…๋ ฅํ•ด์„œ ๋“ค์–ด๊ฐ€๋‹ˆ ์•„์ฃผ ์ž˜ ๋™์ž‘์ค‘์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.











        ๐Ÿ“ฆ PollSCM ์„ค์ •์„ ํ†ตํ•œ ์ง€์†์ ์ธ ํŒŒ์ผ ์—…๋ฐ์ดํŠธ

์ด๋ฒˆ์—๋Š” Update๋œ ๋‚ด์šฉ์„ ํ™•์ธ์„ ํ•ด์„œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด Build๋ฅผ ์ž๋™์œผ๋กœ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด ๋ณผ๊ฒŒ์š”.
PollSCM์€ Polling ์ž‘์—…์„ ์ฃผ๊ธฐ์ ์œผ๋กœ ํ•˜๋Š” ๊ฒƒ์ด์—์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ Build Triggers(๋นŒ๋“œ ์œ ๋ฐœ)์— Build periodically(Code์— ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์—†์–ด๋„ ์ผ๋‹จ Build ์ˆ˜ํ–‰)์— cron job์„ ๋งŒ๋“ค์–ด์„œ ํŠน์ • ์‹œ๊ฐ„์— Build๊ฐ€ ์ง€์ •๋˜๋„๋ก ์„ค์ •ํ•  ๊ฒƒ์ด์—์š”.

์—ฌ๊ธฐ์„œ๋Š” ์ผ์ • ์‹œ๊ฐ„์ด ๋˜๋ฉด ์ž๋™์œผ๋กœ ๊ฐ€์ ธ์˜ค๊ฒŒ ํ•˜๊ฑฐ๋‚˜, ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ์ด ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์˜ค๋Š” ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ์–ด์š”.

๋งŒ์•ฝ Poll SCM ๋ฐฉ์‹์„ ์ด์šฉํ•œ๋‹ค๋ฉด Code์— ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ์„ ๋•Œ, Github์—์„œ ์ˆ˜์ •๋œ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋˜๋Š”๋ฐ, ์ฆ‰, Commit์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ์žˆ์„๋•Œ๋งŒ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ์‹์ด์—์š”.


์ฃผ๋‹ˆํ•˜๋ž‘์€ ์ด๋ฒˆ์— Poll SCM ๋ฐฉ์‹์„ ๊ณต๋ถ€ํ•ด ๋ณผ๊ฒŒ์š”.


์œ„์—์„œ ์ง„ํ–‰ํ•œ Project์—์„œ ๊ตฌ์„ฑ Tab์„ ํด๋ฆญํ•˜์—ฌ ์ค๋‹ˆ๋‹ค.




์ด ๊ณณ์—์„œ ๋นŒ๋“œ ์œ ๋ฐœ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•ด ์ค„ ๊ฒƒ์ด์—์š”.



๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด *์„ ํ•˜๋‚˜ ์ž…๋ ฅํ•˜๊ณ , ํ•œ ์นธ ๋„๊ณ  ํ•ด์„œ 5๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.

์œ„์˜ ๋‚ด์šฉ์€ Linux / Unix์˜ Crontab๊ณผ ๋™์ผํ•œ๋ฐ, ํ•ด๋‹น ๋‚ด์šฉ์„ ํ•œ๋ฒˆ ์ฐพ์•„๋ณด์‹œ๊ธธ ๊ถŒ๊ณ  ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์œ„์˜ ๋‚ด์šฉ์€ ๋งค์ดˆ๋งˆ๋‹ค ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ํ™•์ธํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.


์œ„์— ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜๊ณ , Apply -> Save๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.


์‹ค์ œ Web์„ ๊ตฌ๋™ํ•˜๋Š” ํ™˜๊ฒฝ์—์„œ๋Š” ๋งค ์ดˆ๋งˆ๋‹ค ํ™•์ธํ•˜๊ฒŒ ์„ค์ •ํ•˜์ง„ ์•Š์„๊ฑฐ์—์š”.


src/main/webapp/WEB-INF/view/index.jsp

 

์œ„์™€ ๊ฐ™์ด Code๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.




๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด Push๋ฅผ ํ•ด์ฃผ์—ˆ์–ด์š”.



์ด๋ ‡๊ฒŒ ์ž๋™์œผ๋กœ Jenkins์—์„œ Build ์ž‘์—…์ด ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์‹ค์ œ ๋ฐฐํฌ๊ฐ€ ์ œ๋Œ€๋กœ ๋˜์–ด์„œ ์œ„์™€ ๊ฐ™์ด ํ™•์ธ์ด ๋˜์—ˆ์–ด์š”.











    ๐Ÿ”ฝ  Docker๋ฅผ ์ด์šฉํ•œ ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์„ฑ

        ๐Ÿ“ฆ SSH + Docker๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š” Container ์‚ฌ์šฉํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” ์™ธ๋ถ€์— ์žˆ๋Š” Server์— ๋ฐฐํฌ๋ฅผ ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

๋จผ์ € Jenkins์—์„œ publish Over SSH๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.

Manage Jenkins -> Jenkins Plugins -> available(์„ค์น˜ ๊ฐ€๋Šฅ) -> publish Over ssh


์ฃผ๋‹ˆํ•˜๋ž‘์€ ์ด์ œ ์•„๋ž˜์™€ ๊ฐ™์€ ์ž‘์—…์„ ํ•  ๊ฑฐ์—์š”.

1. Jenkins์—์„œ war File์„ SSH๋ฅผ ์ด์šฉํ•ด์„œ Server๋กœ ๋ณต์‚ฌ
2. Server์—์„œ Dockerfile์„ ๋งŒ๋“œ๋Š”๋ฐ, war File๊ณผ Docker Image๋ฅผ ๋นŒ๋“œํ•˜์—ฌ ๋งŒ๋“ฆ.
3. Docker Image๋ฅผ Container๋กœ ์ƒ์„ฑ.




์ตœ์ดˆ Jenkins์˜ Jenkins ๊ด€๋ฆฌ์—์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ด€๋ฆฌ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.



์„ค์น˜ ๊ฐ€๋Šฅ์—์„œ publish Over ssh Plugin์„ ์„ค์น˜ํ•ด ์ฃผ์„ธ์š”.







์ฃผ๋‹ˆํ•˜๋ž‘์€ Test๋ฅผ ์œ„ํ•ด test_ubunut ๋ผ๋Š” Container๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.


sudo docker exec -it {CONTAINER ID} bash

 

์œ„์™€ ๊ฐ™์ด Test์šฉ Ubuntu์— ์ ‘์†ํ•ด ์ค„๊ฒŒ์š”.



apt-get update && apt-get upgrade -y


๋จผ์ € ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด apt๋ฅผ update ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.



apt-get install openssh-server


์œ„์™€ ๊ฐ™์ด ssh๋ฅผ ์„ค์น˜ํ•ด ์ฃผ์„ธ์š”.




systemctl ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ssh ๊ธฐ๋™ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋ ค ํ•˜์˜€์œผ๋‚˜, ์œ„์™€ ๊ฐ™์ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”.

์ด๋ฒˆ์—๋Š” systemctl์„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.





ํ˜„์žฌ ssh๊ฐ€ ์ฃฝ์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




systemctl๋กœ ssh๊ฐ€ ์ž๋™ ๊ธฐ๋™๋˜๊ฒŒ ํ•˜๊ณ , ๋ฐ๋ชฌ์„ ์‹œ์ž‘ํ•ด ์ฃผ๋ ค ํ•˜๋Š”๋ฐ, ์œ„์™€ ๊ฐ™์ด ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค๋ฉด /etc/init.d/๋ฅผ ์ด์šฉํ•ด์„œ ๊ธฐ๋™ํ•  ์ˆ˜ ์žˆ์–ด์š”.




์œ„์™€ ๊ฐ™์ด ์ •์ƒ ๊ธฐ๋™์ค‘์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



 

์ด๋ฒˆ์—๋Š” ์ฃผ๋‹ˆํ•˜๋ž‘์ด ๋ฆฌ๋ˆ…์Šค์—์„œ ์ข‹์•„ํ•˜๋Š” Text Editor์ธ vim์„ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.



์œ„์˜ ๋ช…๋ น์–ด๋กœ ๋ช‡๊ฐ€์ง€ ์„ค์ •์„ ๋ฐ”๊ฟ”์ค„๊ฒŒ์š”.



์ตœ์ดˆ Port 22๋ผ๊ณ  ์จ์ง„ ๋ถ€๋ถ„์ด ์ฃผ์„์ฒ˜๋ฆฌ ๋˜์–ด ์žˆ์„ํ…๋ฐ, ์ฃผ์„์„ ํ•ด์ œํ•˜๊ณ , 10022๋กœ ๋ฐ”๊พธ์–ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค PermitRootLogin์„ yes๋กœ ๋ฐ”๊ฟ” Root ๊ณ„์ •์œผ๋กœ ssh ์ ‘์†์„ ํ—ˆ์šฉํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.
(์‹ค์ œ ์šด์˜ Server์™€ ๊ฐ™์€ ๊ณณ์—์„œ๋Š” ssh๋กœ Root์— ๋ฐ”๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ฉด ์•ˆ๋˜์š”.)



ํ•ด๋‹น ๋ช…๋ น์–ด๋กœ ssh๋ฅผ ์žฌ ๊ธฐ๋™ํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
docker ๊ธฐ๋™ ๋ช…๋ น์–ด

#docker run --privileged --name {docker container name} -itd -p 10022:10022 -p 8081:8080 -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup --cgroups=host {docker Image Name} /usr/sbin/init

privileged : root ๊ถŒํ•œ์„ ํš๋“ํ•˜๊ธฐ ์œ„ํ•œ Option
-itd -p : Port Fowarding์„ ์œ„ํ•œ Option





ํ˜„์žฌ ssh๊ฐ€ ์„ค์น˜๋œ Ubuntu ip๋Š” ์œ„์™€ ๊ฐ™์•„์š”.

ํ•œ๋ฒˆ ssh๋กœ ์ ‘์†ํ•ด ๋ณผ๊ฒŒ์š”.



๊ทธ ์ „์— ํ•ด๋‹น Container root ๊ณ„์ •์— Password๋ฅผ ์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด ์ฃผ์„ธ์š”.

Password๊ฐ€ ๋“ฑ๋ก๋˜์ง€ ์•Š์œผ๋ฉด ssh๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์—†์–ด์š”.



์œ„์™€ ๊ฐ™์ด ์ •์ƒ์ ์œผ๋กœ ssh๋กœ ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.







Jenkins ๊ด€๋ฆฌ์—์„œ ์‹œ์Šคํ…œ ์„ค์ •์— ๋“ค์–ด๊ฐ€ ์ค„๊ฒŒ์š”.



๋ฐ‘์— ๋‚ด๋ฆฌ๋‹ค ๋ณด๋ฉด ์œ„์™€ ๊ฐ™์ด Publish over SSH๊ฐ€ ๋‚˜์˜ฌ๊ฑฐ์—์š”. ์—ฌ๊ธฐ์„œ SSH Servers ๋ฐ‘์— ์ถ”๊ฐ€ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.


 
๋จผ์ € Name์—๋Š” ํ•ด๋‹น Docker Container ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ์„ธ์š”.
Hostname์—๋Š” Container์˜ IP๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”.
Username์—๋Š” ssh๋กœ ์ ‘์†ํ•  Container ๊ณ„์ • ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๋˜์š”.

Remote Directory๋Š” ํ˜„์žฌ ์œ„์น˜๋ฅผ ์˜๋ฏธํ•˜๋Š” . ์„ ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.



Use password ...๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ฉด Password๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ์ด ๋‚˜์˜ค๋Š”๋ฐ, root ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด๋˜์š”.

๊ทธ๋Ÿฐ ๋’ค Port์—๋Š” ํ•ด๋‹น Server์˜ ssh Port ๋ฒˆํ˜ธ๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.



์œ„์™€ ๊ฐ™์ด Test Button์„ ๋ˆŒ๋ €์„ ๋•Œ, Success๊ฐ€ ๋œฌ๋‹ค๋ฉด ์ •์ƒ ์„ค์ •ํ•œ ๊ฒƒ์ด์—์š”.


ํ•ด๋‹น ๊ณต๋ถ€๋ฅผ ์œ„ํ•ด ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์„ค์น˜ํ–ˆ๋˜ SSH Server์— Docker๋„ ์„ค์น˜ํ•ด ์ค˜์•ผ ํ•ด์š”.

์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.





        ๐Ÿ“ฆ Docker Container์— ๋ฐฐํฌํ•˜๊ธฐ โ‘ 


์ƒˆ๋กญ๊ฒŒ Item์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.

๊ธฐ์กด์— ๋งŒ๋“ค์—ˆ๋˜ Item๊ณผ ํฌ๊ฒŒ ์ฐจ์ด๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— Copy from์„ ํ†ตํ•ด ์ด ์ „์— ๋งŒ๋“  Project๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋„๋ก ํ• ๊ฒŒ์š”.




์ด ์ „์— Poll SCM์„ ํ†ตํ•ด Project๋ฅผ ์ง„ํ–‰ํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ์—๋Š” ์ œ์™ธํ•˜๋„๋ก ํ• ๊ฒŒ์š”.

๊ทธ๋ฆฌ๊ณ , ๋นŒ๋“œ ํ›„ ์กฐ์น˜์— Deploy war/ear to a container๋ฅผ ์‚ญ์ œํ•ด ์ค„๊ฒŒ์š”.



๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด ssh๋ฅผ ํ†ตํ•ด ๋ฐฐํฌ๊ฐ€ ๋˜๋„๋ก ์„ค์ •ํ•ด ์ค„ ๊ฒƒ์ด์—์š”.

Name์—๋Š” SSH Server ์ฆ‰, Docker Container ์ด๋ฆ„์„ ์ ์–ด์ฃผ๋ฉด ๋˜์š”.

Source file์—๋Š” war๊ฐ€ ๋‹ด๊ธด Directory ์ด๋ฆ„๊นŒ์ง€ ๋„ฃ์–ด์„œ ์ž…๋ ฅ์„ ํ•ด์ค„๊ฒŒ์š”.

target์ด๋ผ๋Š” Directory๋Š” ssh Container์—์„œ ๋ณต์‚ฌ๋  ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— Remove Prifix์— target์„ ๋„ฃ์–ด war File๋งŒ ๋ณต์‚ฌ๋˜๋„๋ก ํ•ด์ค„๊ฒŒ์š”.

ssh๋ฅผ ํ†ตํ•ด ํ•ด๋‹น Container์— root๋กœ ์ ‘์†ํ•˜๊ฒŒ ๋˜๋ฉด ์ตœ์ดˆ Directory ์œ„์น˜๊ฐ€ /root์—์š”. 
์ด ๊ณณ์— ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ๋˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ํ˜„์žฌ ์œ„์น˜๋ฅผ ์˜๋ฏธํ•˜๋Š” . ์„ ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.

Exec command์—๋Š” ํ•ด๋‹น Container์— ๋ณต์‚ฌ๊ฐ€ ์™„๋ฃŒ๋œ ๋’ค ์–ด๋–ค ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ• ์ง€๋ฅผ ์ ๋Š” ๊ณณ์ธ๋ฐ, ์ด๋ฒˆ์—๋Š” ๋ณต์‚ฌ๊ฐ€ ๋˜๋Š” ๊ฒƒ๊นŒ์ง€๋งŒ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๊ณต๋ž€์œผ๋กœ ๋‘๋„๋ก ํ• ๊ฒŒ์š”.

Apply -> save๋ฅผ ๋ˆŒ๋Ÿฌ ํ•ด๋‹น ์ฐฝ์„ ๋‚˜์™€ ์ฃผ์„ธ์š”.



ํ˜„์žฌ ssh Container์— File๋“ค์€ ์œ„์™€ ๊ฐ™์ด ์žˆ์–ด์š”.

์ด์ œ Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.



Jenkins๊ฐ€ Build / ๋ฐฐํฌ๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๊ณ  ํ•˜๋„ค์š”!



ssh Container์—์„œ ํ™•์ธ์„ ํ•ด๋ณด๋‹ˆ hello-word.war๊ฐ€ ์ƒ๊ธด๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.





์ด๋ฒˆ์—๋Š” Dockerfile์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ค„๊ฒŒ์š”.



From์—์„œ๋Š” Container ์ข…๋ฅ˜๋ฅผ ์ ๋Š” ๊ณณ์ธ๋ฐ, tomcat 9.0์ด ์„ค์น˜๋œ Container๋ฅผ ์ง€์ •ํ•ด ์ฃผ์—ˆ๊ณ ,

COPY ๋ถ€๋ถ„์— ํ˜„์žฌ Directory์— ์žˆ๋Š” hello-world.war File์„ ํ•ด๋‹น Container์— /usr/local/tomcat/webapps ์•ˆ์— ๋ณต์‚ฌํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.

์ฐธ๊ณ ๋กœ ์ง€๊ธˆ Docker Container ์•ˆ์— ๋˜ ๋‹ค๋ฅธ Container๋ฅผ ๋„ฃ๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์žŠ์œผ๋ฉด ์•ˆ๋˜๋Š” ๊ฒƒ์ด์—์š”.




๋‹ค์‹œ Jenkins์— ํ•ด๋‹น Project์— ๊ตฌ์„ฑ ์„ค์ •์„ ๋“ค์–ด์™€์„œ ์•„๊นŒ ๊ณต๋ฐฑ์œผ๋กœ ๋‚จ๊ฒจ๋‘์—ˆ๋˜ ๊ณณ์— ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.

๋ช…๋ น์–ด ๋‚ด์šฉ์€ docker๋ฅผ Buildํ• ๊ฑฐ๊ณ , Container ์ด๋ฆ„์€ docker-server๋กœ ํ•  ๊ฒƒ์ด๋ฉฐ, Dockerfile์„ ํ†ตํ•ด ํ˜„์žฌ ์œ„์น˜(.)์—์„œ buildํ•ด๋ผ ๋ผ๋Š” ์˜๋ฏธ์—์š”.

์—ฌ๊ธฐ์„œ -f Options์€ Dockerfile์„ ๋ช…์‹œ์ ์œผ๋กœ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” Option์ด์—์š”.




๋‹ค์‹œ Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.




์ž‘์—…์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ ๋˜์—ˆ์–ด์š”!



ssh Container๋ฅผ ํ™•์ธํ•ด๋ณด๋‹ˆ Tomcat Container๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ๊ฐ„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์œ„์— ๋ช…๋ น์–ด๋กœ Tomcat Container๋ฅผ ๊ธฐ๋™์‹œ์ผœ ๋ณผ๊ฒŒ์š”.

์ฐธ๊ณ ๋กœ ํ˜„์žฌ ssh Container์—์„œ๋Š” 8080 Port๋ฅผ ์“ฐ๊ณ  ์žˆ์ง€ ์•Š์•„์š”. ๊ทธ ๋ฐ–์— Host Server ๋“ฑ์—์„œ 8080 Port๋ฅผ ์“ฐ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋Œ๋‚  ์ผ์ด ์—†์–ด ์œ„์™€ ๊ฐ™์ด Port Forwarding์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.



๋ญ๊ฐ€ ์—„์ฒญ๋‚˜๊ฒŒ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


์œ„์™€ ๊ฐ™์ด ์ •์ƒ์ ์œผ๋กœ ์ ‘์†๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




์ฐธ๊ณ ๋กœ Container๋ฅผ ํ™•์ธํ•  ๋•Œ๋Š” ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

sudo docker ps
sudo docker ps -a



Container๋ฅผ ์ œ๊ฑฐํ•˜๋ ค๋ฉด ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

sudo docker rm {Container ID ๋˜๋Š” Container ์ด๋ฆ„}


Docker Image๋ฅผ ํ™•์ธํ•  ๋• ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

sudo docker images



Docker Image๋ฅผ ์‚ญ์ œํ•  ๋•Œ๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

sudo docker remove image {image Id ํ˜น์€ ์ด๋ฆ„}
# ๋˜๋Š”
sudo docker rmi {image Id ํ˜น์€ ์ด๋ฆ„}







๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•