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

Gitlab CI / Docker: Use custom image for job

这就是我做 linter 测试 (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 向我展示了那张图片...

您需要使用以下

编辑运行器机器上 /etc/gitlab-runner 中的 config.toml 文件
[runners.docker]
  pull_policy = "if-not-present"

参见相关问题 here