安裝 gitlab CI 服務.md

安裝 gitlab-ce

安裝依賴包

yum install curl policycoreutils openssh-server openssh-clients
systemctl enable sshd
systemctl start sshd
yum install postfix
systemctl enable postfix
systemctl start postfix
firewall-cmd --permanent --add-service=http
systemctl reload firewalld

下載 gitlab-ce 鏡像

vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
yum makecache
yum install gitlab-ce

配置

vi /etc/gitlab/gitlab.rblinux

external_url 'http://ip'

啓動gitlab

gitlab-ctl reconfigure

遇到報錯

Error executing action `run` on resource 'execute[semodule -i /opt/gitlab/embedded/selinux/rhel/7/gitlab-7.2.0-ssh-keygen.pp]
  1. stop gitlab
  2. yum install libsemanage-static libsemanage-devel

安裝CI服務

下載安裝CI

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-10.5.0-1.x86_64.rpm
rpm -ivh gitlab-runner-10.5.0-1.x86_64.rpm
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
gitlab-runner uninstall
gitlab-runner install --working-directory /home/gitlab-runner/ --user gitlab-runner
gitlab-runner restart
gitlab-runner status

註冊 runner

sudo gitlab-ci-multi-runner register
-- 輸入Gitlab CI地址, (e.g. https://gitlab.xunlei.cn/ci)
http://192.168.1.249/gitlab/
-- 輸入項目CI token
fuXXXXXXXXXX
-- 輸入 Runner 描述(e.g. home.xl9.xunlei.com 測試runner)
測試Runner
-- 輸入 Runner 標籤,能夠多個,用逗號隔開(e.g. 10.10.34.91-dev)
251-dev
-- 輸入 Runner 執行的語言 (e.g. shell)
shell
-- 認證是否註冊成功
sudo gitlab-ci-multi-runner verify

圖片描述

編寫腳本

在項目下面建立.gitlab-ci.ymlnginx

stages:
  - deploy

deploy_dev:
  stage: deploy
  tags:
    - 251-dev
  only:
    - develop
  script:
    - deploy_stage.sh

而後在部署服務器上的 gitlab-runner 用戶路徑下建立deploy_stage.shgit

echo "delete old xyj-admin-api"
sudo rm -rf /raid1/www/test
sudo git clone git@192.168.1.249:test/xyj-test-api.git /raid1/www/test
sudo git fetch --all
sudo git reset --hard origin/test
echo "=============重啓服務===================="
source /etc/profile
sudo supervisorctl restart test
time=`date`
echo "部署結束: $time."
echo "================================================"

其中 測試項目是被 supervisorctl 管理的web

要確保幾件事shell

  1. 改服務器可以正常從遠端克隆數據
  2. 命令幾點要帶上sudo
  3. 用戶sudo無密碼及在tty下能夠使用須要參考 Linux sudo 相關操做
  4. 若是克隆下來的文件放在掛載盤,須要在 ~/ 路徑下執行 clone 而後放到對應路徑,不然報錯 fatal: could not create work tree dir

遇到沒法克隆,且 gitlab 日誌爲vim

gitlab JWT::DecodeError (Nil JSON web token)

修改 nginx 配置api

upstream gitlab-workhorse {
      server unix:/var/opt/gitlab/gitlab-workhorse/socket;
 }

...
proxy_pass http://gitlab-workhorse;
...

git push develop 後觸發腳本
圖片描述bash

相關文章
相關標籤/搜索