手動安裝gitlab-runner
在終端使用命令curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash,輸入sudo密碼,導入指紋秘鑰。速度有點慢。
安裝sudo yum install gitlab-runner。
打開自己搭建的GitLab網站,點擊頂欄的Snippets后面的小扳手,再點擊左側列表中Overview中的Runners,在打開的網頁下面,可以看到How to setup a shared Runner for a new project行,2是Runners設置時需要指定的URL,3是在設置是的Runners。
注冊gitlab-runner
sudo gitlab-runner register,
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):輸入域名或者服務器ip地址,格式為https://gitlab.com。和token Please enter the gitlab-ci token for this runner:。
Please enter the gitlab-ci description for this runner:輸入runner描述。
Please enter the gitlab-ci tags for this runner (comma separated):給這個Runner指定tags,稍后也可以在GitLab's UI中修改。
Whether to run untagged builds [true/false]:選擇Runner是否接受未指定tags的任務,稍后可修改。默認值為false。
Whether to lock the Runner to current project [true/false]: 選擇是否為當前項目鎖定Runner,可修改。通常用於被指定為某個項目的Runner,默認值為true。
Please enter the executor: docker, shell, virtualbox, kubernetes, docker-ssh, parallels, ssh, docker+machine, docker-ssh+machine: 選擇Runner executor(Runner執行器),使用shell,使用默認本地環境。
pep8檢查環境配置
在runner運行的服務器上配置python環境,基本上各大Linux發行版都默認帶有python2版本。
CentOS安裝pip的方法,使用命令sudo yum install python-pip安裝,如果沒有python-pip包,name先安裝epel倉庫sudo yum install epel-release,接受指紋。之后再執行一次命令安裝。
使用pip安裝flake8和pep8,推薦使用pipenv安裝。直接安裝的方式sudo pip install pep8 flake8,第一次使用pip可能需要更新sudo pip install --upgrade pip,如果不使用sudo會報權限不足。
更改pip源,提高下載速度。編輯$HOME/.pip/pip.conf,添加內容:
[global] index-url = https://mirrors.ustc.edu.cn/pypi/web/simple format = columns
如果文件不存在,創建新文件或目錄。
在項目中使用flake8進行風格檢查
需要在項目根目錄下添加兩個文件.flake8和.gitlab-ci.yml,提交到gitlab上。
添加.flake8配置文件
[flake8]
ignore = W292
exclude =
*migrations*,
# python related
*.pyc,
.git,
__pycache__,
max-line-length=120
max-complexity=12
format=pylint
show_source = True
statistics = True
count = True
說明
注意, .flake8里面不要帶中文
ignore = 忽略錯誤類型
exclude = 不檢查的文件正則列表
max-line-length = 單行最大字符數120
max-complexity = 代碼復雜度等級
format = 展示格式
show_source = 顯示源代碼
statistics = 展示統計
count = 展示總錯誤數
本地運行檢測測試$ flake8 .。
添加.gitlab-ci.yml配置文件
before_script:
- echo "Python靜態代碼檢查..."
pep8:
script:
- flake8 .
