简体   繁体   English

GitHub 操作忽略/覆盖 Docker 容器的入口点

[英]GitHub Actions ignores/overrides Docker container's entrypoint

I'm trying to port a GitLab Pipeline to GitHub Actions, where we use Docker containers to provide the runtime environment.我正在尝试将 GitLab 管道移植到 GitHub 操作,我们使用 Docker 容器来提供运行时环境。 In GitLab, we simply use a line image: $DOCKER_TAG .在 GitLab 中,我们简单地使用了一行image: $DOCKER_TAG The images are built by ourselves, which use a script as the entry point ENTRYPOINT ["/run.sh"] .图像是我们自己构建的,它使用脚本作为入口点ENTRYPOINT ["/run.sh"] The script sets up environment (eg, by sourcing the setvars.sh script for the Intel compilers and calling ulimit -s unlimited , etc.) and calls exec "$@" at the end.该脚本设置环境(例如,通过为英特尔编译器获取setvars.sh脚本并调用ulimit -s unlimited等)并在最后调用exec "$@" For GitHub, I am using对于 GitHub,我正在使用

container:
  image: ${{ matrix.DOCKER_TAG }}

However, the commands to be run later cannot find the needed binaries.但是,稍后要运行的命令找不到所需的二进制文件。 Looking at the log, it appears that the container was created with --entrypoint "tail" , causing the run.sh script to be ignored.查看日志,似乎容器是使用--entrypoint "tail"创建的,导致run.sh脚本被忽略。 I tried adding options: --entrypoint '/run.sh' in the Workflow YAML file, but it did not get reflected in how the container was created and the command still failed.我尝试在 Workflow YAML 文件中添加options: --entrypoint '/run.sh' ,但它没有反映在容器的创建方式中,并且命令仍然失败。

I may be missing something obvious, though I checked both the documentation and Google.尽管我检查了文档和谷歌,但我可能遗漏了一些明显的东西。 Is there any way to use the entrypoint provided by the image without creating a Docker container action?有什么方法可以使用图像提供的入口点而不创建 Docker 容器操作?

UPDATE Two more things I tried:更新我尝试了另外两件事:

  1. Specifying the /run.sh script as Custom shell : shell: '/run.sh {0}' , but got an error/run.sh脚本指定为Custom shell : shell: '/run.sh {0}' ,但出现错误
Error: Second path fragment must not be a drive or UNC name. (Parameter 'expression')
  1. Using Docker container action or specifying a Docker image to use for a job step .使用Docker 容器操作指定 Docker 图像用于作业步骤 But in both cases the Docker image has to be hard coded (or built fresh every time).但在这两种情况下,Docker 图像都必须进行硬编码(或每次都重新构建)。 Trying to use input arguments like尝试使用输入 arguments 之类的
# Docker container action
image: docker://${{ inputs.docker_tag }}

or或者

# Job step
- uses: docker://${{ matrix.DOCKER_TAG }}
  with:
    args: ./.github/actions/build/build.sh

will both get an error都会出错

Unrecognized named-value: 'inputs'. Located at position 1 within expression: inputs.docker_tag

When you pass a image to a job, it will execute the steps defined in your job inside this container.当您将图像传递给作业时,它将在此容器内执行您的作业中定义的steps Your container image only provides the environment in which your steps will be executed.您的容器映像仅提供执行步骤的环境。 You lose control of the entrypoint and arguments.您将失去对入口点和 arguments 的控制。

If you only want to run your container as a single step you could do something like this instead:如果您只想将容器作为一个步骤运行,则可以执行以下操作:

jobs:
  my-job:
    runs-on: ubuntu-latest
    steps:
      - uses: docker://myimage:latest

or if you want to overwrite it:或者如果你想覆盖它:

    steps:
      - uses: docker://myimage:latest
        with:
          entrypoint: /run.sh
          args: --help

I've settled along the lines below.我已经按照下面的思路解决了。 Not ideal/DRY, as the run.sh entrypoint script has to be duplicated from the Docker container and kept up to date.不理想/干燥,因为run.sh入口点脚本必须从 Docker 容器复制并保持最新。 Also, the upload-artifact GitHub Actions does not preserve executable bits, so have to zip everything in a tar file.此外,上传工件GitHub 操作不保留可执行位,因此必须将 zip 的所有内容都保存在 tar 文件中。

jobs:
  build:
    container:
      image: XX/compiler:${{ matrix.DOCKER_TAG }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: ./.github/scripts/run.sh ./.github/scripts/build.sh
      - uses: actions/upload-artifact@v2
        with:
          name: build-artifact
          path: 'build-*.tar.bz2'
          retention-days: 7
    strategy:
      fail-fast: false
      matrix:
        DOCKER_TAG: [gcc, nvhpc, intel]
        include:
          - DOCKER_TAG: gcc
            FC: gfortran
          - DOCKER_TAG: nvhpc
            FC: nvfortran
          - DOCKER_TAG: intel
            FC: ifort

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

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