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 .
相关文章
相关标签/搜索