基礎架構三:程式碼倉庫gitlab
01 step1 docker搭建gitlab
#JUST RUN:
mkdir /opt/cmp_gitlab;cd /opt/cmp_gitlab
wget https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/dockerrun.sh
#gitlab程式碼倉庫-docker指令碼, 修改image行,適應你的情況
sh dockerrun.sh
或者使用compose
wget https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/docker-compose.yml
#[gitlab程式碼倉庫-compose], 修改image行,適應你的情況
docker-compose up -d && docker-compose logs
#注意:
#1.筆記本里啟動大約5分鐘,docker ps -a 檢視gitlab容器狀態由starting轉為healthy即完成;
#2.需要使用域名,沒有DNS可以在HOSTS裡新增代替;
#3.最好用80埠,也可以用nginx轉,避免以後配置的麻煩;
02 step2 頁面登陸與設定[參考配圖]
登陸:gitlab.yunwei.edu
-
設定root的密碼
-
建一個group
-
組下新建專案project
-
增加user/設定passwd/使用者第一次登陸會要求改密碼
-
將使用者新增至專案,並分配角色和許可權
-
使用git 客戶端示例
-
git clone http://gitlab.yunwei.edu/yunwei/python.git
-
cd python/
-
git config --global user.name "Thomas"
-
git config --global user.email "[email protected]"
-
touch README.md
-
git add README.md
-
git commit -m "add README"
-
git push -u origin master
-
03 step3 安裝gitlab-runner並註冊
關於: https://about.gitlab.com/features/gitlab-ci-cd/#gitlab-runner
1. 在gitlab專案頁面裡
-
-
開啟auto devops的setting cicd項 http://gitlab.yunwei.edu/yunwei/python/settings/ci_cd
-
取得 runner token: <gwHDYqzVVu6Spyvvc1Nu>
-
記下http url :http://gitlab.yunwei.edu/
-
2.安裝runner: (建議先用linux版)
-
-
linux版參考
https://docs.gitlab.com/runner/install/linux-manually.html
wget https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/gitlab-runner/linuxrun.sh
sh linuxrun.sh
-
#docker參考 https://docs.gitlab.com/runner/install/docker.html
curl https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/gitlab-runner/dockerrun.sh |sh
-
3.註冊: (建議先用linux版)
https://docs.gitlab.com/runner/register/index.html
#各種執行器比較:
https://docs.gitlab.com/runner/executors/README.html 選擇不同的執行器,.gitlab-ci.yml檔案的寫法也不同,先選用SHELL型別
# linux版註冊指令碼
-
-
輸入Gitlab CI地址, (e.g. http://gitlab.yunwei.edu/)
-
輸入專案CI token
-
輸入 Runner 描述
-
輸入 Runner 標籤,可以多個,用逗號隔開(docker,shell等)
-
輸入 Runner 執行器 (e.g. shell、docker、kubernetes等)
wget https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/gitlab-runner/registry-shell.sh
sh registry-shell.sh
cat /etc/gitlab-runner/config.toml
-
# docker容器版註冊指令碼
-
wget https://raw.githubusercontent.com/Thomas-YangHT/docker-compose/master/cmp_gitlab/gitlab-runner/registry.sh
sh registry.sh
cat config/config.toml
04 step4 編輯 .gitlab-ci.yml檔案
-
shell exector的示例:https://raw.githubusercontent.com/Thomas-YangHT/python/master/uwsgi/.gitlab-ci.yml.shell
-
docker exector的示例:https://raw.githubusercontent.com/Thomas-YangHT/python/master/uwsgi/.gitlab-ci.yml.docker
注:將此檔案放在專案根目錄
參考:
using docker build: https://docs.gitlab.com.cn/ce/ci/docker/using_docker_build.html
shell執行器參考 https://www.jianshu.com/p/705428ca1410
docker執行器參考 https://blog.csdn.net/sqzhao/article/details/71330523
各種gitlab-ci.yml https://gitlab.com/gitlab-org/gitlab-ci-yml/blob/master/Python.gitlab-ci.yml
—END—
Linux命令速查,輸入命令,如:lsof