[Ubuntu] Docker gitlab ์„ค์น˜ ๋ฐ Mail ๊ธฐ๋Šฅ ํ™œ์„ฑํ™”

2023. 8. 2. 12:28ใ†System ์ž‘์—…์‹ค/Docker

728x90
๋ฐ˜์‘ํ˜•

 

 

 



 

 

(์˜๋ฌธ๋„์„œ) Automating DevOps with GitLab CI/CD Pipelines: Build efficient CI/CD pipelines to verify sec... Paperback

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

๐Ÿš€ Ubuntu 22.04 LTS Gitlab Docker ์„ค์น˜ 

    ๐Ÿ”ฝ ๊ฐœ์š”

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ฃผ๋‹ˆ๊ฐ€ ํ˜„์žฌ ์šด์˜์ค‘์ธ ํ”„๋กœ์ ํŠธ ๋ชจ์ž„์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ˜•์ƒ๊ด€๋ฆฌ ํˆด์€ ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” github(๊นƒํ—™), gitlab(๊นƒ๋žฉ)์ด ์•„๋‹Œ gitea(๊นƒํ‹ฐ)๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์š”.

์ด๋Š” ๊ตฌ์„ฑ์›์˜ ์ฝ”๋“œ ํ•˜๋‚˜ํ•˜๋‚˜๊ฐ€ ์šฐ๋ฆฌ์˜ ์†Œ์ค‘ํ•œ ์ž์‚ฐ์ด๊ณ , ์ตœ๋Œ€ํ•œ ๋ณด์•ˆ์ ์œผ๋กœ ๋ฐฉ์–ดํ•˜์—ฌ ์™ธ๋ถ€ ์œ ์ถœ์„ ๋ง‰๊ธฐ ์œ„ํ•จ์ด์—์š”.

ํ•˜์ง€๋งŒ, ์‹ค๋ฌด์—์„œ๋Š” AWS Code Commit(์ฝ”๋“œ ์ปค๋ฐ‹)์ด๋‚˜, ๊นƒํ—™, ๊นƒ๋žฉ์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‹ค๋ฌด ๊ธฐ๋ฐ˜์˜ ์ง€์‹์„ ์ตํžˆ๊ธฐ ์œ„ํ•ด์„œ ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ? ๋ฅผ ๊ณ ๋ฏผํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.

๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ์ค‘์ธ ์„œ๋ฒ„์˜ ๋ฉ”๋ชจ๋ฆฌ๋„ ์ถฉ๋ถ„ํ•˜๊ณ , ๊นƒ๋žฉ์„ ๋‚ด๋ถ€์ ์œผ๋กœ ์„ค์น˜ํ•˜๋ฉด ์ข‹๊ฒ ๋‹ค! ๋ผ๋Š” ๊ฒฐ๋ก ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ , ์ด๋ฅผ ํ†ตํ•ด ๋„์ปค ๊ธฐ๋ฐ˜์˜ ๊นƒ๋žฉ์„ ์„ค์น˜ํ•˜์—ฌ ์šด์˜ํ•ด ๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ ๊นƒ๋žฉ ๊ด€๋ จ ์ด๋ฏธ์ง€๋Š” gitlab-ce์™€ gitlab-ee๊ฐ€ ์žˆ๋Š”๋ฐ, ce๋Š” community (๋ฌด๋ฃŒ),
ee๋Š” enterprise (์œ ๋ฃŒ) ์ „์šฉ์ด์—์š”.

์•„์ง ์œ ๋ฃŒ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•  ์ด์œ ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ๋‹ˆ๋Š” ce๋ฅผ ์„ค์น˜ํ•  ๊ฒƒ์ด๊ณ , ์ถ”ํ›„ ์œ ๋ฃŒ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ, ๋‹ค์‹œ ee ๋ฒ„์ „์„ ์„ค์น˜ํ•  ํ•„์š”๊ฐ€ ์—†์–ด์š”.

 

GitLab CE vs EE | InfoGrab, DevOps ์ „๋ฌธ ๊ธฐ์ˆ  ๊ธฐ์—… | ์ธํฌ๊ทธ๋žฉ | GitLab๊ธฐ๋ฐ˜ DevSecOps ๊ตฌ์ถ•,์ปจ์„คํŒ…,๊ต์œก,๊ธฐ์ˆ 

GitLab์„ ์‚ฌ์šฉํ•˜๋ ค๋Š” ๊ฒฝ์šฐ, GitLab Enterprise Edition(EE)์„ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. GitLab CE vs EE์—์„œ๋Š” GitLab์˜ ๋ฐฐํฌํŒ์— ๋Œ€ํ•œ ์„ค๋ช…์„ ํ•ฉ๋‹ˆ๋‹ค.

insight.infograb.net

 

 

    ๐Ÿ”ฝ ์„ค์น˜ํ•˜๊ธฐ

        ๐Ÿ“ฆ ๋„์ปค ์ด๋ฏธ์ง€ ๋‚ด๋ ค๋ฐ›๊ธฐ

์ตœ์ดˆ ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋‚ด๋ ค ๋ฐ›์•„ ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.

docker pull gitlab/gitlab-ce:latest

728x90

 

 

 

        ๐Ÿ“ฆ ๋„์ปค ๊ธฐ๋™

๋„์ปค ์ด๋ฏธ์ง€ ๊ธฐ๋ฐ˜์œผ๋กœ ๋„์ปค๋ฅผ ๊ธฐ๋™ํ•˜๋Š”๋ฐ๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์–ด์š”.
์ฒซ๋ฒˆ์งธ๋กœ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์„œ ๊ธฐ๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๊ณ , ๋‘๋ฒˆ์งธ๋Š” Docker Compose(๋„์ปค ์ปดํฌ์ฆˆ)๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์—์š”.

๋งŒ์•ฝ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ €์žฅํ•ด ๋†“๋Š”๊ฑธ ์ถ”์ฒœํ•ด์š”.

docker run --detach \
  --hostname gitlab.example.com \
  -p 1980:80 \ 
  -p 1922:22 \
  -p 1443:443 \
  -v $HOME/gitlab/config:/etc/gitlab \
  -v $HOME/gitlab/logs:/var/log/gitlab \
  -v $HOME/gitlab/data:/var/opt/gitlab \
  --name gitlab \
  --restart=unless-stopped \
  gitlab/gitlab-ce:latest


๋ช…๋ น์–ด๋Š” ์œ„์™€ ๊ฐ™์•„์š”.

๋ช…๋ น์–ด Option ์ƒ์„ธ ๋‚ด์šฉ
detach Back Ground ์‹คํ–‰
hostname gitlab ์ „์šฉ ๋„๋ฉ”์ธ ์„ค์ • ๋ฐ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€ ํ˜ธ์ŠคํŠธ ๋„ค์ž„ ์„ค์ •
p(publish) gitlab์—์„œ๋Š” 22(ssh), 80(http), 443(https) ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ํฌํŠธํฌ์›Œ๋”ฉ ํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜
name ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„
restart server๊ฐ€ ๊ธฐ๋™๋  ๋•Œ ์ž๋™์œผ๋กœ ์‹คํ–‰ํ•˜๋ผ๊ณ  ์˜ต์…˜์œผ๋กœ ๋ถ€ํŒ…์‹œ ์ž๋™์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๋ฉฐ, ์‚ฌ์šฉ์ž๊ฐ€ ์ข…๋ฃŒํ–ˆ์„ ๋•Œ๋Š” ๋ถ€ํŒ…ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •.
v(volume) ํ˜ธ์ŠคํŠธ ์„œ๋ฒ„์™€ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๊ฐ„ ๋ณผ๋ฅจ ๋งคํ•‘.
ํ˜ธ์Šค ์„œ๋ฒ„์˜ $HOME/gitlab ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ณ , ๊ทธ ๊ณณ์— ์ปจํ…Œ์ด๋„ˆ์— ์ƒ์„ฑ๋˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ ๋‚ด์šฉ์„ ์ €์žฅํ•˜์—ฌ ๋งคํ•‘

 

์ฃผ๋‹ˆ๋Š” ๋„์ปค ์ปดํฌ์ฆˆ๋ฅผ ์ด์šฉํ•ด์„œ ์ง„ํ–‰ํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.

mkdir config & mkdir logs & mkdir data & mkdir backup


์œ„์™€ ๊ฐ™์ด ํ˜ธ์ŠคํŠธ ์„œ๋ฒ„์— ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ณผ๋ฅจ ๋งคํ•‘์„ ์œ„ํ•œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.


docker-compose.yml



docker-compose.yml

๋ฐ˜์‘ํ˜•


์ฃผ๋‹ˆ๋Š” ์ฒซ๋ฒˆ์งธ ์‚ฌ์ง„๊ณผ  ๊ฐ™์ด ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.
๋งŒ์•ฝ ๋„๋ฉ”์ธ์ด ์žˆ๋‹ค๋ฉด ๋‘๋ฒˆ์งธ ์‚ฌ์ง„์ฒ˜๋Ÿผ ํ•ด ์ฃผ์–ด๋„ ๋˜์š”.

environment์˜ GITLAB_OMNIBUS_CONFIG์— gitlab.rb์— ์žˆ๋Š” ๋‚ด์šฉ์„ ๋ณ€๊ฒฝ ํ˜น์€ ์‚ฝ์ž…ํ•  ๋‚ด์šฉ์„ ๋„ฃ์–ด ์ค„ ์ˆ˜ ์žˆ์–ด์š”.

์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ๋’ค ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ /etc/gitlab ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ gitlab.rb๋ฅผ ํ™•์ธํ•˜๋ฉด ์œ„ ๋‚ด์šฉ์ด ์„ค์ •๋œ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



docker-compose up -d


๋„์ปค๋ฅผ ๊ธฐ๋™ ์‹œ์ผœ ๋ณด์•˜์–ด์š”.


docker ps -a



http:{์„œ๋ฒ„ IP}:Web Port ๋ฒˆํ˜ธ


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







 
   ๐Ÿ”ฝ ์„ค์ •ํ•˜๊ธฐ

        ๐Ÿ“ฆ ๊นƒ๋žฉ ๋ฃจํŠธ ๊ณ„์ • ์ •๋ณด ํ™•์ธ ๋ฐ ์ ‘์†

์ด์ œ ๊นƒ๋žฉ์˜ ๋ฃจํŠธ ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ฐพ์•„ ๋ณผ๊ฒŒ์š”.

์ตœ์ดˆ ๊นƒ๋žฉ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•ด ์ค˜์•ผ ํ•ด์š”.

docker exec -it {Docker ID ํ˜น์€ ์ด๋ฆ„} /bin/bash

 

cat /etc/gi tlab/initial_root_password


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


root // ์ดˆ๊ธฐ ๋น„๋ฐ€๋ฒˆํ˜ธ



์ดˆ๊ธฐ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ


์œ„์™€ ๊ฐ™์ด ์ดˆ๊ธฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ณ€๊ฒฝํ•ด ์ฃผ์—ˆ์–ด์š”.




์ด๋ ‡๊ฒŒ ๊นƒ๋žฉ์„ ์„ค์น˜ํ•ด ๋ณด์•˜์–ด์š”.

ํ˜น์‹œ๋ผ๋„ ๊ถ๊ธˆํ•˜์‹œ๊ฑฐ๋‚˜, ํ”ผ๋“œ๋ฐฑ ์ฃผ์‹ค ๋‚ด์šฉ์ด ์žˆ์œผ์‹œ๋‹ค๋ฉด ๋Œ“๊ธ€ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”!

 

 

 

๐Ÿš€ Mail ๊ธฐ๋Šฅ

    ๐Ÿ”ฝ Gitlab Mail

        ๐Ÿ“ฆ Gmail

Gitlab์„ ํ†ตํ•ด ์ž‘์—… ๋“ฑ์— ๋Œ€ํ•œ ์•Œ๋ฆผ์„ ์ด์šฉ์ž๋“ค์ด ๋“ฑ๋กํ•œ Mail๋กœ ๋ฐœ์†ก๋  ์ˆ˜ ์žˆ๋„๋ก ์ž‘์—…ํ•ด ์ค„๊ฒŒ์š”.

์ตœ์ดˆ ์ฃผ๋‹ˆ๋Š” Gmail์„ ์ด์šฉํ•ด์„œ Mail์ด ๋ฐœ์†ก๋˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์ž‘์—…์„ ํ•ด์ค„๊ฑฐ์—์š”.


๊ตฌ๊ธ€์—์„œ ์œ„์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜ค๋ฉด ๊ณ„์ •์„ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค.

 


๊ทธ๋Ÿฐ ๋’ค ๋ณด์•ˆ Tab์—์„œ 2๋‹จ๊ณ„ ์ธ์ฆ์„ ํด๋ฆญํ•ด ์ค„๊ฒŒ์š”.

 


๋ฐ‘์œผ๋กœ ๋‚ด๋ฆฌ๋ฉด ์œ„์™€ ๊ฐ™์ด ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์žˆ์„๊ฑฐ์—์š”.
์ด ๊ณณ์„ ํด๋ฆญํ•ด ์ค„๊ฒŒ์š”.

 


์œ„์™€ ๊ฐ™์ด ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ , ๋งŒ๋“ค๊ธฐ๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.


 

๊ทธ๋Ÿผ ์œ„์™€ ๊ฐ™์ด ๋‚˜์˜ฌํ…๋ฐ, ๊ธฐ๊ธฐ์šฉ ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ Git Lab์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋ ๊ฑฐ์—์š”.

 

 

 

        ๐Ÿ“ฆ Gitlab ์„ค์ •

docker exec -it <Container ์ด๋ฆ„> /bin/bash


์œ„์™€ ๊ฐ™์ด Gitlab Docker์— ์ ‘์†ํ•ด ์ค๋‹ˆ๋‹ค.

 

vim /etc/gitlab/gitlab.rb

 

/etc/gitlab/gitlab.rb ์ˆ˜์ • ์ „


์ตœ์ดˆ ์œ„์™€ ๊ฐ™์ด Email ์„ค์ • ๋ถ€๋ถ„์ด ์ฃผ์„ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์–ด ์žˆ์„ ๊ฑฐ์—์š”.
์ด ๋ถ€๋ถ„์„ ์†๋ด์ฃผ๋ ค๊ณ  ํ•ด์š”.

 

/etc/gitlab/gitlab.rb ์ˆ˜์ • ๋’ค


์œ„์™€ ๊ฐ™์ด Gmail๋กœ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ์„ค์ • ํ•ด ์ฃผ์—ˆ์–ด์š”.
์—ฌ๊ธฐ์„œ Password ๋ถ€๋ถ„์€ ์œ„์—์„œ ์•ฑ ๋น„๋นŒ๋ฒˆํ˜ธ๋กœ ๋ฐ›์€ ๋‚ด์šฉ์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋ผ์š”.

 

gitlab-ctl reconfigure


์œ„ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์„ค์ •ํ•œ ๋‚ด์šฉ์ด ์ธ์‹๋  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.


gitlab-rails console

 

Notify.test_email('junyharang8592@gmail.com', 'Gitlab Mail ํ…Œ์ŠคํŠธ', 'GitLab Mailing ํ™•์ธ ์ค‘ ์ž…๋‹ˆ๋‹ค.').deliver_now

 


์œ„์™€ ๊ฐ™์ด Mail์ด ์ •์ƒ์ ์œผ๋กœ ๊ฐ€๋Š”์ง€ ํ™•์ธํ•ด ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด ๋ฉ”์ผ๋„ ์ž˜ ๋„์ฐฉํ•œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค.

๋งŒ์•ฝ Mail์ด ์˜ค์ง€ ์•Š๊ฑฐ๋‚˜, Mail Test ์ค‘ Error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด Docker Host Server์˜ ๋ฐฉํ™”๋ฒฝ์ด ์ฐจ๋‹จํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹Œ์ง€ ํ™•์ธํ•ด ๋ณผ ํ•„์š”๊ฐ€ ์žˆ์–ด์š”.

 

 

 

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

 

[Docker] GitLab ์„ค์น˜ ๋ฐ ์ ‘์†ํ•˜๊ธฐ

๋„์ปค๋กœ GitLab ์ ‘์†ํ•˜๊ธฐ

velog.io

 

 



 

(์˜๋ฌธ๋„์„œ) Automating DevOps with GitLab CI/CD Pipelines: Build efficient CI/CD pipelines to verify sec... Paperback

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•