apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  generateName: buildah-test-pipeline-run-
spec:
  pipelineSpec:
    params:
      - name: git-repo
        type: string
        description: Repository URL to clone from.
        default: https://github.com/anithapriyanatarajan/demogitops
      - name: git-revision
        type: string
        default: master
        description: Revision to checkout. (branch, tag, sha, ref, etc...)
      - name: output-image
        type: string
        default: quay.io/rh-ee-anataraj/getting-started
        description: Reference of the image the pipeline will produce.
    workspaces:
      - name: shared-workspace
      - name: sslcertdir
        optional: true
      - name: dockerconfig-ws
        optional: true
    tasks:
      - name: fetch-repository
        taskRef:
          name: git-clone
        workspaces:
          - name: output
            workspace: shared-workspace
        params:
          - name: url
            value: https://github.com/anithapriyanatarajan/demogitops
          - name: subdirectory
            value: ""
          - name: deleteExisting
            value: "true"
      - name: buildah
        taskRef:
          name: buildah
        runAfter:
        - fetch-repository
        workspaces:
        - name: source
          workspace: shared-workspace
        - name: dockerconfig
          workspace: dockerconfig-ws
        matrix:
            params:
            - name: IMAGE
              value:
                  - "$(params.output-image)-arm64"
                  - "$(params.output-image)-ppc64le"
                  - "$(params.output-image)-s390x"
      - name: build-image-index
        taskRef:
          name: buildah
        runAfter:
        - buildah
        workspaces:
        - name: source
          workspace: shared-workspace
        - name: dockerconfig
          workspace: dockerconfig-ws
        params:
        - name: IMAGE
          value: $(params.output-image)
        - name: SCRIPT
          value: |
            buildah manifest create $(params.output-image)
            buildah manifest add $(params.output-image) docker://quay.io/rh-ee-anataraj/$(params.output-image)-arm64
            buildah manifest add $(params.output-image) docker://quay.io/rh-ee-anataraj/$(params.output-image)-ppc64le
            buildah manifest add $(params.output-image) docker://quay.io/rh-ee-anataraj/$(params.output-image)-s390x
            buildah manifest push --all $(params.output-image) docker://quay.io/rh-ee-anataraj/$(params.output-image)
    results: 
      - name: IMAGE_URL
        description: 'URL of the built image'
        value: $(tasks.build-image-index.results.IMAGE_URL)
      - name: IMAGE_DIGEST
        description: 'Digest of the built image'
        value: $(tasks.build-image-index.results.IMAGE_DIGEST)
      - name: CHAINS-GIT_URL
        description: ''
        value: "$(tasks.fetch-repository.results.url)"
      - name: CHAINS-GIT_COMMIT
        description: ''
        value: "$(tasks.fetch-repository.results.commit)"
  workspaces:
    - name: shared-workspace
      volumeClaimTemplate:
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 100Mi
    - name: dockerconfig-ws
      secret:
        secretName: dockerconfig-secret

