docker安裝gitlab-runner
docker pull gitlab/gitlab-runner:latest
安裝gitlab-runner
打開自己搭建的GitLab
網站,點擊頂欄的Snippets
后面的小扳手,再點擊左側列表中Overview
中的Runners
,在打開的網頁下面,可以看到How to setup a shared Runner for a new project
行,2是Runners設置時需要指定的URL,3是在設置是的Runners
。
運行鏡像
docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:latest
注冊gitlab-runner
docker exec -it gitlab-runner 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
,使用gitlab-runner
環境。
重啟容器docker restart gitlab-runner
。
修改配置文件docker exec -it name vim /etc/gitlab-runner/config.toml
pep8檢查環境配置
進去docker容器環境docker exec -it name /bin/bash
,name
就是容器的名稱,如果沒有啟動容器,會報錯。
安裝python-pip
,apt-get update && apt-get install python-pip -y
。
使用pip安裝flake8
和pep8
,pip install pep8 flake8
,第一次使用pip
可能需要更新pip install --upgrade pip
。
更改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 = 展示總錯誤數
添加.gitlab-ci.yml
配置文件
before_script:
- echo "Python靜態代碼檢查..."
pep8:
script:
- flake8 .