docker安裝gitlab-runner
docker pull gitlab/gitlab-runner:latest
安裝gitlab-runner
python
打開本身搭建的GitLab
網站,點擊頂欄的Snippets
後面的小扳手,再點擊左側列表中Overview
中的Runners
,在打開的網頁下面,能夠看到How to setup a shared Runner for a new project
行,2是Runners設置時須要指定的URL,3是在設置是的Runners
。git
運行鏡像
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
web
註冊gitlab-runner
docker exec -it gitlab-runner gitlab-runner register
,docker
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:
。shell
Please enter the gitlab-ci description for this runner:
輸入runner
描述。vim
Please enter the gitlab-ci tags for this runner (comma separated):
給這個Runner
指定tags
,稍後也能夠在GitLab's UI
中修改。bash
Whether to run untagged builds [true/false]:
選擇Runner
是否接受未指定tags
的任務,稍後可修改。默認值爲false
。服務器
Whether to lock the Runner to current project [true/false]:
選擇是否爲當前項目鎖定Runner,可修改。一般用於被指定爲某個項目的Runner,默認值爲true
。ssh
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
。gitlab
修改配置文件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 .