Passing buildah arguments

It is possible to pass arguments to buildah which is used to build container images in Konflux.

Using an arguments file

The Konflux buildah tasks accept BUILD_ARGS parameter that allows passing build arguments to the underlying buildah command through --build-arg-file flag. To enable this, make the following changes to the PipelineRuns under the .tekton/ directory:

  1. Create a build args file in your repository. This should contain lines of build arguments in the form of arg=value.

  2. Define a build-args-file Pipeline parameter (if not already present) in .spec.pipelineSpec.params to accept the passed-in build arguments.

    spec:
      # ...
      pipelineSpec:
        params:
        # ...
        - name: build-args-file
          type: string
          default: ""
  3. Pass the argument to buildah task. Add BUILD_ARGS_FILE to build-container.params (if not already present):

    spec:
      # ...
      pipelineSpec:
        tasks:
        # ...
        - name: build-container
          params:
          # ...
          - name: BUILD_ARGS_FILE
            value: "$(params.build-args-file)"
  4. Set the build arguments file in the PipelineRun .spec.params:

    spec:
      params:
      # ...
      - name: build-args-file
        value: path/to/args-file  # Add the real path to the build args file within the build context

Setting arguments in the pipeline parameters

The Konflux buildah tasks accept BUILD_ARGS parameter that allows passing build arguments to the underlying buildah command through --build-arg flag. To enable this, make the following changes to the PipelineRuns under the .tekton/ directory:

  1. Define a build-args Pipeline parameter (if not already present) in .spec.pipelineSpec.params to accept the passed-in build arguments.

    spec:
      # ...
      pipelineSpec:
        params:
        # ...
        - name: build-args
          type: array
          default: []
  2. Pass the argument to buildah task. Add BUILD_ARGS to build-container.params (if not already present):

    spec:
      # ...
      pipelineSpec:
        tasks:
        # ...
        - name: build-container
          params:
          # ...
          - name: BUILD_ARGS
            value: ["$(params.build-args[*])"]

    The value can also be in form tasks.<taskName>.results.<resultName>[*] if it is generated by another task dynamically.

    For example, you can do more creative things with the BUILD_ARGS parameter like this snippet of a pipeline that allows passing build-args through the pipeline parameter (as described above) but also incorporates build-args generated dynamically by other tasks:

    spec:
      # ...
      pipelineSpec:
        tasks:
        # ...
        - name: build-container
          params:
          # ...
          - name: BUILD_ARGS
            value:
            # pass the build args array from the pipeline param
            - $(params.build-args[*])
            # and a dynamically generated array of build args
            - $(tasks.my-build-arg-generator-task.results.BUILD_ARGS[*])
            # and a build arg with a static name and dynamic value
            - VERSION=$(tasks.my-get-version-task.results.VERSION)
    Ensure that the value of BUILD_ARGS has the correct syntax as described in Variable Substitutions Supported by Tasks and Pipelines.
  3. Pass the desired build arguments in the PipelineRun .spec.params:

    spec:
      params:
      # ...
      - name: build-args
        value: ["ARG1=val", "ARG2=val"]  # Add real argument name and value of each build argument