【问题标题】:How to use a kaniko based gitlab-runner to build a node.js image?如何使用基于 kaniko 的 gitlab-runner 构建 node.js 映像?
【发布时间】:2019-04-26 02:26:05
【问题描述】:

我正在使用一个自托管的 Gitlab 存储库来推送我的代码。该代码包含一个 Dockerfile,它成功地在我的机器上本地创建了一个 docker-image。我现在的意图是自动化这个构建过程并将 docker-build 集成到 Gitlab-Pipeline 中。我绑定了共享的跑步者,所以我无法整合我自己的跑步者。而且这些跑步者不是为简单的 docker-in-docker 构建而设置的。 我看到另一个项目使用图像gcr.io/kaniko-project/executor:debug 来解决这个问题。它成功地启动了我的 Dockerfile 的构建过程,但是在执行了我的第一个 RUN 参数之后,它开始向层添加数百万个工件,直到它冻结。

我尝试用 node:slim 替换 node:latest 映像,它在 Dockerfile 中进一步执行了一次。所以我认为问题在于基础图像的加载。但我无法弄清楚原因。
Kaniko 不能下载基础镜像吗?
我需要以不同的方式提供基本图像吗?
有人有一个基于节点构建图像的功能 kaniko 管道的示例吗?

以下部分显示了跑步者的日志。

<pre>
>Resolved base name node:latest to node:latest
>Downloading base image node:latest
>No matching credentials were found, falling back on anonymous
>Error while retrieving image from cache: getting file info: stat /cache   /sha256:a954de83ca1e2dfee3bdb4fedd56df42646f6325f50347482724626327b187c6: no such file or directory
>Downloading base image node:latest       
>No matching credentials were found, falling back on anonymous
>Built cross stage deps: map[]               
>Downloading base image node:latest          
>No matching credentials were found, falling back on anonymous
>Error while retrieving image from cache: getting file info: stat /cache
/sha256:a954de83ca1e2dfee3bdb4fedd56df42646f6325f50347482724626327b187c6: no such file or directory
>Downloading base image node:latest          
>No matching credentials were found, falling back on anonymous
>Unpacking rootfs as cmd RUN http_proxy=$proxy apt-get update &&     http_proxy=$proxy apt-get -y --no-install-recommends install apt-utils build-essential libudev-dev && true requires it. 
>Taking snapshot of full filesystem...        
>Adding /usr/share/icons/gnome/48x48/mimetypes/tgz.png to layer, because it was changed. 
>Adding /usr/share/icons/gnome/32x32/actions/stock_select-all.png to layer, because it was changed. 
>...Continues with adding stuff till it freezes
</pre>

【问题讨论】:

    标签: docker gitlab-ci-runner kaniko


    【解决方案1】:

    你需要 kaniko 执行器的debug image,它提供了sh 供 gitlab-runner ci 执行

    build:
      image: gcr.io/kaniko-project/executor:debug
      stage: build
      script:
        - executor --dockerfile=Dockerfile --context=$PWD --no-push
    

    原因是如果镜像不允许使用CMD 运行脚本,则镜像将无法与 Docker 执行器一起使用。见参考gitlab runner's docker executor

    对于其他docker push,您可以按照示例在您的.gitlab-ci.yaml中添加额外的配置。

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 2023-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多