在复合 GitHub 操作中向 docker 容器提供参数

Mar*_*rco 7 github docker github-actions

我正在尝试在复合 GitHub Action 中传递一些动态创建的参数。

\n

然而,文档缺少有关如何在这种情况下将参数传递给 docker 容器的示例。

\n

https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsuses

\n

在这里看看我想要实现的目标。

\n
runs:\n  using: \'composite\'\n  steps:\n    - name: compose arguments\n      id: compose-args\n      shell: bash\n      run: |\n        encoded_github="$(echo \'${{ inputs.github_context }}\' | base64)"\n        encoded_runner="$(echo \'${{ inputs.runner_context }}\' | base64)"\n\n        args=(\'${{ inputs.command }}\')\n        args+=(\'${{ inputs.subcommand }}\')\n        args+=(\'--github-context\')\n        args+=("${encoded_github}")\n        args+=(\'--runner-context\')\n        args+=("${encoded_runner}")\n        args+=(\'${{ inputs.arguments }}\')\n\n        echo "::set-output name=provenance_args::$(echo "[$(printf "\\"%s\\"," ${args[*]})]" | sed \'s/,]$/]/\')"\n    - name: Debug arguments\n      shell: bash\n      run: |\n        echo Running slsa-provenance with following arguments\n        echo ${{ steps.compose-args.outputs.provenance_args }}\n    - uses: \'docker://ghcr.io/philips-labs/slsa-provenance:v0.5.0-draft\'\n      with:\n        args: ${{ fromJSON(steps.compose-args.outputs.provenance_args) }}\n
Run Code Online (Sandbox Code Playgroud)\n

fromJSON 从 bash 参数组成的数组中给我一个 JSON 对象。我假设这uses: \'docker://\xe2\x80\xa6部分应该以与基于 docker 的操作接收相同的方式接收它的参数。

\n

例如:

\n
runs:\n  using: \'docker\'\n  image: \'docker://ghcr.io/philips-labs/slsa-provenance:v0.4.0\'\n  args:\n    - "generate"\n    - \'${{ inputs.subcommand }}\'\n    - "-artifact_path"\n    - \'${{ inputs.artifact_path }}\'\n    - "-output_path"\n    - \'${{ inputs.output_path }}\'\n    - "-github_context"\n    - \'${{ inputs.github_context }}\'\n    - "-runner_context"\n    - \'${{ inputs.runner_context }}\'\n    - "-tag_name"\n    - \'${{ inputs.tag_name }}\'\n
Run Code Online (Sandbox Code Playgroud)\n

不幸的是,我在 GitHub 操作工作流程中收到以下错误。

\n
The template is not valid. philips-labs/slsa-provenance-action/v0.5.0-draft/action.yaml (Line: 47, Col: 15): A sequence was not expected\n
Run Code Online (Sandbox Code Playgroud)\n

请参阅此处的工作流程。https://github.com/philips-labs/slsa-provenance-action/runs/4618706311?check_suite_focus=true

\n
    \n
  • 我该如何解决这个错误?
  • \n
  • 用目前的方法可以解决吗?
  • \n
  • 这是缺少的功能吗?
  • \n
  • 有什么替代方案吗?
  • \n
\n

Euc*_*ues -2

我认为你可以通过 bash 命令运行:

- name: pull image
  shell: bash
  run: |
    docker pull ghcr.io/philips-labs/slsa-provenance:v0.4.0

- name: run container
  shell: bash
  run: |
    docker run --rm -i \
    --workdir /github/workspace \
    -v "/var/run/docker.sock":"/var/run/docker.sock" \
    -v ${{ runner.temp }}/_github_home:"/github/home" \
    -v ${{ github.workflow }}:"/github/workflow" \
    -v ${{ runner.temp }}/_runner_file_commands:"/github/file_commands" \
    -v ${{ github.workspace }}:"/github/workspace" \
    ghcr.io/philips-labs/slsa-provenance:v0.4.0 \ # image
    generate \ # start pass the args here, after the image
    ${{ inputs.subcommand }} \
    -artifact_path ${{ inputs.artifact_path }} \
    -output_path ${{ inputs.output_path }} \
    -github_context ${{ inputs.github_context }} \
    -runner_context ${{ inputs.runner_context }} \
    -tag_name ${{ inputs.tag_name }} 
Run Code Online (Sandbox Code Playgroud)