docker安裝gitlab-runner

docker安裝gitlab-runner

docker pull gitlab/gitlab-runner:latest安裝gitlab-runnerpython

打開本身搭建的GitLab網站,點擊頂欄的Snippets後面的小扳手,再點擊左側列表中Overview中的Runners,在打開的網頁下面,能夠看到How to setup a shared Runner for a new project行,2是Runners設置時須要指定的URL,3是在設置是的Runnersgit

運行鏡像

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:latestweb

註冊gitlab-runner

docker exec -it gitlab-runner gitlab-runner registerdocker

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,默認值爲truessh

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-runnergitlab

修改配置文件docker exec -it name vim /etc/gitlab-runner/config.toml

pep8檢查環境配置

進去docker容器環境docker exec -it name /bin/bashname就是容器的名稱,若是沒有啓動容器,會報錯。

安裝python-pipapt-get update && apt-get install python-pip -y

使用pip安裝flake8pep8pip 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 .
相關文章
相關標籤/搜索