๐Ÿคต ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค Jenkins ํ™œ์šฉ

๊น€์„ฑ์ธยท2023๋…„ 10์›” 22์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
56/62

์ฐธ๊ณ  ๋ธ”๋กœ๊ทธ: https://blog.naver.com/isc0304/222545722104

1. Google Cloud VM ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

๋จธ์‹  : E2 (CPU 2๊ฐœ, ๋ฉ”๋ชจ๋ฆฌ 4GB)
Ubuntu 20.04 100 GB
HTTP, HTTPS ํ—ˆ์šฉ

2. Jenkins ๊ตฌ์„ฑ

  • sudo -i : ๊ด€๋ฆฌ์ž ๊ถŒํ•œ
  • apt update && apt install -y docker.io : ๋„์ปค ๋ฐ๋ชฌ ์„ค์น˜
  • docker run -d -p 8080:8080 --name jenkins -v /home/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -u root jenkins/jenkins:lts : jenkins ๊ตฌ์„ฑ ๋ฐ ๋„์ปค ์†Œ์ผ“ ๊ณต์œ 
    (๋ณผ๋ฅจ ๋งˆ์šดํŠธ ์ฒซ๋ฒˆ์งธ : Jenkins ๋ฐ์ดํ„ฐ ๋ณด์กด, ๋‘๋ฒˆ์จฐ: jenkins๊ฐ€ ๋„์ปค๋ฅผ ์ œ์–ดํ•˜๋„๋ก ์†Œ์ผ“์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•จ)

3. cloud shell์„ ํ†ตํ•ด ๋ฐฉํ™”๋ฒฝ ์˜คํ”ˆ

  • gcloud compute firewall-rules create jenkins-ci --allow=tcp:8080 : ๋ฐฉํ™”๋ฒฝ ์˜คํ”ˆ

4. Jenkins ์™ธ๋ถ€ IP๋ฅผ ํ†ตํ•ด ํฌํŠธ ์ ‘์†

5. Docker CLI๋ฅผ ์œ„ํ•œ docker ์„ค์น˜

jenkins ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— Docker ์„ค์น˜

docker exec jenkins apt update
docker exec jenkins apt install -y docker.io

6. Jenkins ํŒจ์Šค์›Œ๋“œ ํ™•์ธ & ์ ‘์†

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

ํ•ด๋‹น ๋‚ด์šฉ unlokc jenkins์— ์ž…๋ ฅ

  • Install suggested plugins
    -> ๋ชจ๋“  ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ ์™„๋ฃŒ ํ›„ Admin ๊ณ„์ • ์ƒ์„ฑ

    -> IP ํ™•์ธ ํ›„ next

7. ์ ‘์† ์™„๋ฃŒ

Jenkins -> Plugins -> Available Plugins -> Docker Pipeline ์„ค์น˜ ํ›„ ์  ํ‚จ์Šค ์žฌ์‹œ์ž‘


8. git hub ์‚ฌ์šฉ

https://github.com/gasbugs/flask-example

9. Webhook ์„ค์ •

Jenkins ์™ธ๋ถ€ ๊ณต์ธ IP ์ฃผ์†Œ:8080/github-webhook/ ๋กœ ์„ค์ •

10. Jenkins ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์„ฑ

New Item -> pipeline -> ์ œ๋ชฉ์ž…๋ ฅ ํ›„ ok ->

  • ์ €์žฅ

11. ๋„์ปค ํ—ˆ๋ธŒ credential ์ƒ์„ฑ

Jenkins ๊ด€๋ฆฌ -> Credentials -> Stores scoped to Jenkins -> Jenkins | System -> GlobalCredentials -> Add Credentials

  • Username: ๋„์ปค ์•„์ด๋”” ๋ช…
  • password: ๋„์ปค ์ธ๊ฐ€ ํ† ํฐ
  • ID: JenkinsํŒŒ์ผ์— ์ž‘์„ฑํ•ด๋‘” ID์™€ ๋™์ผํ•˜๊ฒŒ ์ž‘์„ฑ

12. Jenkins ํŒŒ์ดํ”„๋ผ์ธ ์ฒซ ๋นŒ๋“œ ์ˆ˜๋™ ์ง„ํ–‰


Jenkins ์ปจํ…Œ์ด๋„ˆ ์žฌ์‹คํ–‰ํ•  ๋•Œ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— Docker CLI ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์„ค์ •๋˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ๊ฐ™์•„์„œ ๋‹ค์‹œ ์‹คํ–‰ํ•ด์ฃผ์—ˆ๋‹ค.


https://github.com/SUNGIN99/flask-example

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€