Gitlab CI / Docker:使用自定义镜像作业

14

这是我进行一些代码检查测试(eslint)的方法。

linter:
  image: ubuntu:16.04
  stage: test
  tags:
    - testing
  before_script:
    - apt-get update -y
    - apt-get install nodejs-legacy -yqq
    - apt-get install curl -yqq
    - curl https://install.meteor.com/ | sh
    - meteor npm install eslint eslint-plugin-react
  script:
    - ./node_modules/.bin/eslint --ext .js --ext .jsx .

但是,这样每个测试都需要在Ubuntu镜像中安装软件包,这需要时间。

因此,我想要构建一个含有这些软件包的镜像。我编写了以下Dockerfile:

FROM ubuntu:16.04
RUN apt-get update -y
RUN apt-get install nodejs-legacy -yqq
RUN apt-get install curl -yqq
RUN apt-get clean && apt-get autoclean && apt-get autoremove
RUN curl https://install.meteor.com/ | sh

然后我执行

$ docker build -t linter-testing:latest .

以及这个yml文件:

linter:
  image: linter-testing:latest
  stage: test
  tags:
    - testing
  before_script:
    - meteor npm install eslint eslint-plugin-react
  script:
    - ./node_modules/.bin/eslint --ext .js --ext .jsx .

但是它遇到了这个错误:

ERROR: Job failed: Error response from daemon: repository linter-testing not found: does not exist or no pull access

那么为什么这个镜像不存在,尽管docker images确实显示了这个镜像...

1个回答

8
您需要编辑位于runner机器上的/etc/gitlab-runner路径下的config.toml文件,使用以下内容进行修改。
[runners.docker]
  pull_policy = "if-not-present"

请参考这里相关问题。


文件应该在/etc/gitlab-runner中。我已经编辑了答案并加入了这个信息。 - Jawad
它应该已经存在。但你可能需要以root身份编辑它。只需找到[runners.docker]部分并添加/修改pull_policy = "if-not-present"即可。 - Jawad
如果[runners.docker]部分不存在怎么办?我的配置文件中有两行,但我还没有注册我的Runner。我将其用于本地CI配置开发和调试目的。 - ojrask
@ojrask[runners.docker] 是 runner 配置的一部分,因此如果您尚未注册任何 runner,则在其中没有它是正常的。但我不知道其他获取所需行为的方法。 - Jawad
听起来我需要安装完整的Gitlab实例才能让配置工作,因为配置甚至不能正确读取“exec docker”命令。这很傻,因为在本地使用runner的主要目的是测试CI配置和未发布的CI容器映像。 :) - ojrask

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接