【问题标题】:Provide arguments to docker container in composite GitHub action在复合 GitHub 操作中为 docker 容器提供参数
【发布时间】:2022-01-24 12:18:17
【问题描述】:

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

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

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

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

runs:
  using: 'composite'
  steps:
    - name: compose arguments
      id: compose-args
      shell: bash
      run: |
        encoded_github="$(echo '${{ inputs.github_context }}' | base64)"
        encoded_runner="$(echo '${{ inputs.runner_context }}' | base64)"

        args=('${{ inputs.command }}')
        args+=('${{ inputs.subcommand }}')
        args+=('--github-context')
        args+=("${encoded_github}")
        args+=('--runner-context')
        args+=("${encoded_runner}")
        args+=('${{ inputs.arguments }}')

        echo "::set-output name=provenance_args::$(echo "[$(printf "\"%s\"," ${args[*]})]" | sed 's/,]$/]/')"
    - name: Debug arguments
      shell: bash
      run: |
        echo Running slsa-provenance with following arguments
        echo ${{ steps.compose-args.outputs.provenance_args }}
    - uses: 'docker://ghcr.io/philips-labs/slsa-provenance:v0.5.0-draft'
      with:
        args: ${{ fromJSON(steps.compose-args.outputs.provenance_args) }}

fromJSON 从组合的 bash 参数数组中给了我一个 JSON 对象。我假设uses: 'docker://…part 应该以与基于 docker 的操作相同的方式接收它的参数。

例如:

runs:
  using: 'docker'
  image: 'docker://ghcr.io/philips-labs/slsa-provenance:v0.4.0'
  args:
    - "generate"
    - '${{ 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 }}'

很遗憾,我在 GitHub 操作工作流程中遇到以下错误。

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

在此处查看工作流程。 https://github.com/philips-labs/slsa-provenance-action/runs/4618706311?check_suite_focus=true

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

【问题讨论】:

    标签: docker github github-actions


    【解决方案1】:

    我认为你可以通过 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 }} 
    

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2021-11-27
      • 2021-07-05
      • 2023-04-03
      • 1970-01-01
      • 2021-08-17
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多