简体   繁体   English

gitlab-runner local - 没有这样的命令

[英]gitlab-runner locally - No such command sh

I have gitlab-runner installed locally. 我在本地安装了gitlab-runner。

km@Karls-MBP ~ $ gitlab-runner --version
Version:      10.4.0
Git revision: 857480b6
Git branch:   10-4-stable
GO version:   go1.8.5
Built:        Mon, 22 Jan 2018 09:47:12 +0000
OS/Arch:      darwin/amd64

Docker: 泊坞窗:

km@Karls-MBP ~ $ docker --version
Docker version 17.12.0-ce, build c97c6d6

.gitlab-ci.yml: .gitlab-ci.yml:

image: docker/compose:1.19.0

before_script:
  - echo wtf

test:
  script:
    - echo test

Results: 结果:

km@Karls-MBP ~ $ sudo gitlab-runner exec docker --docker-privileged test
WARNING: Since GitLab Runner 10.0 this command is marked as DEPRECATED and will be removed in one of upcoming releases 
WARNING: You most probably have uncommitted changes. 
WARNING: These changes will not be tested.         
Running with gitlab-runner 10.4.0 (857480b6)
  on  ()
Using Docker executor with image docker/compose:1.19.0 ...
Using docker image sha256:be4b46f2adbc8534c7f6738279ebedd6106969695f5e596079e89e815d375d9c for predefined container...
Pulling docker image docker/compose:1.19.0 ...
Using docker image docker/compose:1.19.0 ID=sha256:e06b58ce9de2ea3f11634e022ec814984601ea3a5180440c2c28d9217b713b30 for build container...
Running on runner--project-0-concurrent-0 via x.x.x...
Cloning repository...
Cloning into '/builds/project-0'...
done.
Checking out b5a262c9 as km/ref...
Skipping Git submodules setup
No such command: sh

Commands:
  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information

Don't really know what the issue is. 真的不知道问题是什么。

It seems that the docker/compose image is configured with docker-compose as an entrypoint. 似乎docker/compose图像配置了docker-compose作为入口点。

You can override the default entrypoint of the docker/compose image in your .gitlab-ci.yml file : 您可以覆盖 .gitlab-ci.yml文件中docker / compose图像的默认入口点:

image: 
  name: docker/compose:1.19.0
  entrypoint: [""]

before_script:
  - echo wtf

test:
  script:
    - echo test

The docker/compose image has the command docker-compose as its entrypoint (until version 1.24.x), which enables a usage similar to this (assuming a compatible volume mount): docker / compose图像使用命令docker docker-compose作为其入口点(直到版本1.24.x),这将启用与此类似的用法(假设兼容的卷装入):

docker run --rm -t docker/compose -f some-dir/compose-file.yml up

Unfortunately that same feature makes it incompatible with usage within GitLab CI's Docker Runner. 不幸的是,相同的功能使其与GitLab CI的Docker Runner中的使用不兼容。 Theoretically you could have a construct like this: 从理论上讲,你可以有这样的结构:

job-name:
    image: docker/compose:1.24.1
    script:
        - up
        - --build
        - --force-recreate

But the GitLab Docker Runner assumes the entrypoint is /bin/bash - or at least functions likewise (many Docker images thoughtfully use a shell script with "$@" as its final line for the entrypoint) - and from the array elements that you specify for the script it creates its own temporary shell script on the fly. 但是GitLab Docker Runner假设入口点是/bin/bash - 或者至少是函数(许多Docker镜像使用带有"$@"的shell脚本作为入口点的最后一行) - 以及您指定的数组元素对于脚本,它会动态创建自己的临时shell脚本。 It starts with statements like set -e and set -o pipeline and will be used in a statement like sh temporary-script.sh as the container command. 它以set -eset -o pipeline类的语句开头,并将在sh temporary-script.sh类的语句中用作容器命令。 That's what causes the unexpected error message you got. 这就是导致您获得意外错误消息的原因。

This behaviour was recently documented more clearly : 最近更清楚地记录了这种行为:

The Docker executor doesn't overwrite the ENTRYPOINT of a Docker image. Docker执行程序不会覆盖Docker镜像的ENTRYPOINT。

That means that if your image defines the ENTRYPOINT and doesn't allow to run scripts with CMD, the image will not work with the Docker executor. 这意味着如果您的图像定义了ENTRYPOINT并且不允许使用CMD运行脚本,则该图像将无法与Docker执行程序一起使用。

Overriding the entrypoint with [""] will allow usage of docker/docker-compose (before version 1.25.x) with the Docker Runner, but the script that GitLab will create on the fly is not going to run as process 1 and because of that the container will not stop at the end of the script. 使用[""]覆盖入口点将允许使用Docker Runner使用docker docker/docker-compose docker docker/docker-compose (版本1.25.x之前),但GitLab将动态创建的脚本不会作为进程1运行,因为容器不会在脚本结束时停止。 Example: 例:

job-name:
    image:
        name: docker/docker-compose
        entrypoint: [""]
    script:
        - docker-compose
        - up
        - --build
        - --force-recreate

At the time I write this the latest version of docker/docker-compose is 1.25.0-rc2. 当我写这个时,最新版本的docker docker/docker-compose docker- docker/docker-compose是1.25.0-rc2。 Your mileage may vary, but it suffices for my purposes and entirely resolves both problems. 您的里程可能会有所不同,但它足以满足我的目的并完全解决这两个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM