Gitlab

จาก Morange Wiki
รุ่นแก้ไขเมื่อ 04:07, 29 กันยายน 2559 โดย Seksan Poltree (คุย | มีส่วนร่วม) (การอัปเกรดเป็นเวอร์ชัน 8.x)

Gitlab[1] เป็นเซิร์ฟเวอร์สำหรับจัดการ git โดยมีคุณสมบัติการใช้งานคล้ายกับ github โดยเป็น open source ที่เป็น community edition และแบบ support ที่เป็น Enterprise edition โดยที่ Community สามาระสร้างได้ 10,000 repository


การติดตั้ง

  • ไปที่ https://about.gitlab.com/gitlab-ce และเลือกดาวน์โหลด https://about.gitlab.com/downloads/archives/ โดยที่แพ็กเกจประกอบด้วย postgres และ nginx แบบ embed ในตัว
  • เลือก Ubuntu 14.04 และดาวน์โหลดสำหรับ Ubuntu 14.04 LTS 64bit และติดตั้ง
wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.3.2-omnibus-1_amd64.deb
[sudo] password for seksan: 
Selecting previously unselected package gitlab.
(Reading database ... 122590 files and directories currently installed.)
Preparing to unpack gitlab_7.3.2-omnibus-1_amd64.deb ...
Unpacking gitlab (7.3.2-omnibus-1) ...
Setting up gitlab (7.3.2-omnibus-1) ...
Thank you for installing GitLab!
You can configure GitLab for your system by running the following command:

sudo gitlab-ctl reconfigure
  • ตั้งค่าการใช้งาน ระบบจะทำการตั้งค่าฐานข้อมูล (Postgres) และ นำเข้าฐานข้อมูลพื้นฐาน
sudo gitlab-ctl reconfigure
  • แก้ไข hostname
sudo -e /etc/gitlab/gitlab.rb
  • (option) แก้ไข nginx /var/opt/gitlab/nginx/conf/gitlab-http.conf เพื่อทำ proxy
  • username และ password เริ่มต้น
Username: root 
Password: 5iveL!fe

การอัปเกรด

เนื่องจากเป็นการติดตั้งจาก source เราจะอัปเกรดโดยขั้นตอนตาม [2]

  • Backup
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
  • ปิด server
sudo service gitlab stop
  • ดึง code ล่าสุดจาก stable branch
cd /home/git/gitlab
sudo -u git -H git fetch --all
sudo -u git -H git checkout -- Gemfile.lock db/schema.rb
sudo -u git -H git checkout LATEST_TAG

LATEST_TAG เช่น v7.14.1

  • ปรุงปรุง gitlab-shell ตามรุ่นที่ต้องใช้
cd /home/git/gitlab-shell
sudo -u git -H git fetch
sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`
  • ติดตั้งไลบรารี่และอัปเกรดฐานข้อมูล
cd /home/git/gitlab

#PostgreSQL
sudo -u git -H bundle install --without development test mysql --with postgres --deployment

# MySQL
sudo -u git -H bundle install --without development test postgres  --with mysql  --deployment

sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
sudo -u git -H bundle exec rake assets:clean RAILS_ENV=production
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production
  • เริ่ม application
sudo service gitlab start
sudo service nginx restart
  • ตรวจสอบสถานะการติดตั้ง
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

ถ้าทุกรายการเป็นสีเขียวหรือผ่านทั้งหมด ถือว่าการอัปเกรดเสร็จสมบูรณ์

การอัปเกรดเป็นเวอร์ชัน 8.x

จาก [3] จะพบว่า ต้องติดตั้ง gitlab-git-http-server ซึ่งเป็นส่วนที่แยกด้าน authentication ออกจาก main process มีผลทำให้ ต้องตั้งค่าเพิ่ม

# ติดตั้ง go
curl -O --progress https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
echo '46eecd290d8803887dec718c691cc243f2175fe0  go1.5.1.linux-amd64.tar.gz' | shasum -c - && \
  sudo tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
rm go1.5.1.linux-amd64.tar.gz

ติดตั้ง gitlab-git-http-server

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git
cd gitlab-git-http-server
sudo -u git -H make

ในเวอร์ชันหลังๆ gitlab-http-server ได้เปลี่ยนชื่อเป็น gitlab-workhorse ติดตั้งโดย

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
sudo -u git -H make

จากนั้น ตั้งค่า /etc/default/gitlab ใหม่

 Copy this lib/support/init.d/gitlab.default.example file to
# /etc/default/gitlab in order for it to apply to your system.

# RAILS_ENV defines the type of installation that is running.
# Normal values are "production", "test" and "development".
RAILS_ENV="production"

# app_user defines the user that GitLab is run as.
# The default is "git".
app_user="git"

# app_root defines the folder in which gitlab and it's components are installed.
# The default is "/home/$app_user/gitlab"
app_root="/home/$app_user/gitlab"

# pid_path defines a folder in which the gitlab and it's components place their pids.
# This variable is also used below to define the relevant pids for the gitlab components.
# The default is "$app_root/tmp/pids"
pid_path="$app_root/tmp/pids"

# socket_path defines the folder in which gitlab places the sockets
#The default is "$app_root/tmp/sockets"
socket_path="$app_root/tmp/sockets"

# web_server_pid_path defines the path in which to create the pid file fo the web_server
# The default is "$pid_path/unicorn.pid"
web_server_pid_path="$pid_path/unicorn.pid"

# sidekiq_pid_path defines the path in which to create the pid file for sidekiq
# The default is "$pid_path/sidekiq.pid"
sidekiq_pid_path="$pid_path/sidekiq.pid"

gitlab_git_http_server_pid_path="$pid_path/gitlab-git-http-server.pid"
# The -listenXxx settings determine where gitlab-git-http-server
# listens for connections from NGINX. To listen on localhost:8181, write
# '-listenNetwork tcp -listenAddr localhost:8181'.
# The -authBackend setting tells gitlab-git-http-server where it can reach
# Unicorn.
gitlab_git_http_server_options="-listenUmask 0 -listenNetwork tcp -listenAddr 127.0.0.1:8181 -authBackend http://127.0.0.1:8888"
gitlab_git_http_server_repo_root="/home/git/repositories"
gitlab_git_http_server_log="$app_root/log/gitlab-git-http-server.log"

# mail_room_enabled specifies whether mail_room, which is used to process incoming email, is enabled.
# This is required for the Reply by email feature.
# The default is "false"
mail_room_enabled=false

# mail_room_pid_path defines the path in which to create the pid file for mail_room
# The default is "$pid_path/mail_room.pid"
mail_room_pid_path="$pid_path/mail_room.pid"

# shell_path defines the path of shell for "$app_user" in case you are using
# shell other than "bash"
# The default is "/bin/bash"
shell_path="/bin/bash"

โดยส่วนที่สำคัญคือ gitlab_git_http_server_options="-listenUmask 0 -listenNetwork tcp -listenAddr 127.0.0.1:8181 -authBackend http://127.0.0.1:8888" เปลี่ยนเป็น listen tcp และตั้งค่า http://127.0.0.1:8888 ให้ชี้ไปที่ port unicorn ของ gitlab

อีกส่วนคือ /home/git/gitlab-shell/config.yml ต้องแก้ไข ย้าย key ssh ไปที่ /var/opt/gitlab/.ssh/authorized_keys โดยอาจต้องเพิ่มลด key ใหม่ที่หน้าเว็บ

user: git
gitlab_url: https://git.morange.co.th/
http_settings:
  self_signed_cert: false
repos_path: "/home/git/repositories/"
#auth_file: "/home/git/.ssh/authorized_keys"
auth_file: "/var/opt/gitlab/.ssh/authorized_keys"
redis:
  bin: "/usr/bin/redis-cli"
  namespace: resque:gitlab
  socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false

อ้างอิง

ดึงข้อมูลจาก "https://wiki.morange.co.th/index.php?title=Gitlab&oldid=1057"