首页 > 解决方案 > 如何使用基于 kaniko 的 gitlab-runner 构建 node.js 映像?

问题描述

我正在使用一个自托管的 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>

标签: dockergitlab-ci-runnerkaniko

解决方案


你需要 kaniko 执行器的调试镜像,它提供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 的 docker executor

对于其他docker push,您可以按照示例在您的.gitlab-ci.yaml.


推荐阅读