我正在尝试将 GitLab 管道移植到 GitHub Actions,我们使用 Docker 容器来提供运行时环境。在 GitLab 中,我们只使用一行 image: $DOCKER_TAG
。镜像是我们自己构建的,它使用脚本作为入口点ENTRYPOINT ["/run.sh"]
。该脚本设置环境(例如,通过为英特尔编译器获取 setvars.sh
脚本并调用 ulimit -s unlimited
等)并在最后调用 exec "$@"
。对于 GitHub,我正在使用
container:
image: ${{ matrix.DOCKER_TAG }}
但是,稍后要运行的命令无法找到所需的二进制文件。查看日志,似乎容器是使用 --entrypoint "tail"
创建的,导致 run.sh
脚本被忽略。我尝试在工作流 YAML 文件中添加 options: --entrypoint '/run.sh'
,但它没有反映在容器的创建方式中,命令仍然失败。
虽然我检查了文档和谷歌,但我可能遗漏了一些明显的东西。有没有什么方法可以使用镜像提供的入口点,而无需创建 Docker 容器操作?
更新我尝试了另外两件事:
/run.sh
脚本指定为 Custom shell:shell: '/run.sh {0}'
,但出现错误Error: Second path fragment must not be a drive or UNC name. (Parameter 'expression')
# Docker container action
image: docker://${{ inputs.docker_tag }}
或
# Job step
- uses: docker://${{ matrix.DOCKER_TAG }}
with:
args: ./.github/actions/build/build.sh
两者都会出错
Unrecognized named-value: 'inputs'. Located at position 1 within expression: inputs.docker_tag
答案 0 :(得分:0)
当您将图像传递给作业时,它将执行在此容器内的作业中定义的 steps
。您的容器映像仅提供执行步骤的环境。你失去了对入口点和参数的控制。
如果您只想将容器作为一个步骤运行,您可以执行以下操作:
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- uses: docker://myimage:latest
或者如果你想覆盖它:
steps:
- uses: docker://myimage:latest
with:
entrypoint: /run.sh
args: --help
答案 1 :(得分:0)
我已经按照下面的方法解决了。不理想/DRY,因为 run.sh
入口点脚本必须从 Docker 容器复制并保持最新。此外,upload-artifact GitHub 操作不保留可执行位,因此必须将所有内容压缩到 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