由于“无此文件或目录”,导致gitlab CI失败 [英] Failing gitlab CI due to "no such file or directory"

查看:171
本文介绍了由于“无此文件或目录”,导致gitlab CI失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的 .gitlab-ci.yml 文件使用Gitlab容器注册表中的映像。我已经成功地将 Dockerfile 上传到注册表,并且可以从本地计算机上的注册表中提取图像并建立一个容器。但是,当将图像用于 .gitlab-ci.yml 文件时,出现此错误:

 使用工作负载中的凭据进行身份验证(GitLab注册表)
standard_init_linux.go:190:exec用户进程引起了没有此类文件或目录

我已经看到了很多有关Windows EOL字符的讨论,但是我在上运行Raspbian ,我不认为这是问题所在。但是,我对此很陌生,无法弄清楚问题出在哪里。感谢您的帮助。



.gitlab-ci.yml 文件:

  before_script:
-docker登录-u $ CI_REGISTRY_USER -p $ CI_REGISTRY_PASSWORD $ CI_REGISTRY

个阶段:
-测试版本

测试:
阶段:测试版本
图片:registry.gitlab.com/my/project/test:最新的
脚本:
-python --version

test.Dockerfile (在注册表中为 registry.gitlab.com/my/project/test:latest ):

  ARG base_img = python:3.6 
FROM $ {base_img}

#安装Python软件包
RUN pip install --upgrade pip

编辑:
要注意的另一件事是,如果我将 .gitlab-ci.yml 文件中的图像更改为只需 python:3.6 ,它就可以正常运行。

解决方案

正如您在注释中所确认的, gitlab.com/my/project 是一个私有存储库,因此不能直接使用 docker pull image :属性,其中 registry.gitlab.com/my/project/test:latest



但是,您应该能够使用 image修改 .gitlab-ci.yml :docker:latest ,并手动运行 docker 命令(包括 docker登录)。



这依赖于所谓的 Docker-in-Docker(dind)方法,它是由GitLab CI支持



< b lockquote>

这里是 .gitlab-ci.yml 的通用模板,它依赖于以下想法:




 阶段:
-测试版本

测试:
阶段:测试版本
图像:docker:最新
服务:
-docker:dind
变量:
#GIT_STRATEGY:无#如果不需要 git clone,则取消注释
图像: registry.gitlab.com/my/project/test:latest
before_script:
#-docker login -u $ CI_REGISTRY_USER -p $ CI_REGISTRY_PASSWORD $ CI_REGISTRY
#或更好的
-回显 $ CI_REGISTRY_PASSWORD | docker login -u $ CI_REGISTRY_USER --password-stdin $ CI_REGISTRY

脚本:
-docker pull $ IMAGE
-|
docker run --rm -v $ PWD:/ build -w / build $ IMAGE / bin / bash -c
export PS4 ='+ \e [33; 1m( 0 $ 0 @行\ $ LINENO)\ $ \e [0m'#可选
set -ex#强制
## TODO在此处插入多行shell脚本##
echo \一个注释\#引号必须在此处转义
:更好的注释
python --version
echo $ PWD#插在容器外
echo \ P $ PWD#插在容器中
##(续)##
$ CI_JOB_NAME
-回声完成

这会增加一些样板,但这是通用的,因此您只需替换 IMAGE 定义并用您自己的Bash脚本替换 TODO 区域,只需确保满足以下两项:




  • 如果您的外壳程序代码包含一些双引号,则需要转义它们,因为整个代码都被<$ c $包围c> docker run… 和 (最后一个变量 $ CI_JOB_NAME 是详细信息,它是可选的,仅允许覆盖Bash变量 PS4 )中引用的 $ 0 变量

  • 如果您的shell代码包含局部变量,则需要对其进行转义(参见<上面的\ $ PWD),否则这些变量将在运行 docker run… $ IMAGE / bin / sh -c ... 命令本身之前得到解析。 / li>

I'm attempting to have my .gitlab-ci.yml file use an image off the Gitlab container registry. I have successfully uploaded the Dockerfile to the registry and I can pull the image from the registry on my local machine and build a container just fine. However, when using the image for my .gitlab-ci.yml file, I get this error:

Authenticating with credentials from job payload (GitLab Registry)
standard_init_linux.go:190: exec user process caused "no such file or directory"

I've seen a bunch of discussion about Windows EOL characters, but I'm running on Raspbian and I don't believe that's the issue here. However, I'm pretty new at this and can't figure out what the issue is. I appreciate any help.

.gitlab-ci.yml file:

before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

stages:
    - test-version

test:
    stage: test-version
    image: registry.gitlab.com/my/project/test:latest
    script:
        - python --version 

test.Dockerfile (which is in the registry as registry.gitlab.com/my/project/test:latest):

ARG base_img="python:3.6"                                                                                                                                                                                                                    
FROM ${base_img}

# Install Python packages
RUN pip install --upgrade pip

Edit: Another thing to note is that if I change the image in the .gitlab-ci.yml file to just python:3.6, then it runs just fine. It's only when I attempt to link my image in the registry.

解决方案

As you confirmed in the comments, gitlab.com/my/project is a private repository, so that one cannot directly use docker pull or the image: property with registry.gitlab.com/my/project/test:latest.

However, you should be able to adapt your .gitlab-ci.yml by using the image: docker:latest and manually running docker commands (including docker login).

This relies on the so-called Docker-in-Docker (dind) approach, and it is supported by GitLab CI.

Here is a generic template of .gitlab-ci.yml relying on this idea:

stages:
  - test-version

test:
  stage: test-version
  image: docker:latest
  services:
    - docker:dind
  variables:
    # GIT_STRATEGY: none  # uncomment if "git clone" is unneeded
    IMAGE: "registry.gitlab.com/my/project/test:latest"
  before_script:
    # - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
    # or better
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"

  script:
    - docker pull "$IMAGE"
    - |
      docker run --rm -v "$PWD:/build" -w /build "$IMAGE" /bin/bash -c "
        export PS4='+ \e[33;1m(\$0 @ line \$LINENO) \$\e[0m '  # optional
        set -ex  # mandatory
        ## TODO insert your multi-line shell script here ##
        echo \"One comment\"  # quotes must be escaped here
        : A better comment
        python --version
        echo $PWD  # interpolated outside the container
        echo \$PWD  # interpolated inside the container
        ## (cont'd) ##
      " "$CI_JOB_NAME"
    - echo done

This leads to a bit more boilerplate, but this is generic so you can just replace the IMAGE definition and replace the TODO area with your own Bash script, just ensuring that the two items are fulfilled:

  • If your shell code contains some double quotes, you need to escape them, because the whole code is surrounded by docker run … " and " (the last variable "$CI_JOB_NAME" is a detail, it is optional and just allows one to override the $0 variable referenced within the Bash variable PS4)
  • If your shell code contains local variables, they need to be escaped (cf. the \$PWD above), otherwise these variables will be resolved prior running the docker run … "$IMAGE" /bin/sh -c "…" command itself.

这篇关于由于“无此文件或目录”,导致gitlab CI失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆