apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: s2i-java-8
spec:
  inputs:
    params:
      - default: .
        description: The location of the path to run s2i from
        name: PATH_CONTEXT
        type: string
      - default: 'true'
        description: >-
          Verify the TLS on the registry endpoint (for push/pull to a non-TLS
          registry)
        name: TLSVERIFY
        type: string
      - default: ''
        description: Additional Maven arguments
        name: MAVEN_ARGS_APPEND
        type: string
      - default: 'false'
        description: Remove the Maven repository after the artifact is built
        name: MAVEN_CLEAR_REPO
        type: string
      - default: ''
        description: The base URL of a mirror used for retrieving artifacts
        name: MAVEN_MIRROR_URL
        type: string
    resources:
      - name: source
        type: git
  outputs:
    resources:
      - name: image
        type: image
  steps:
    - args:
        - |-
          echo "MAVEN_CLEAR_REPO=$(inputs.params.MAVEN_CLEAR_REPO)" > env-file

          [[ '$(inputs.params.MAVEN_ARGS_APPEND)' != "" ]] &&
            echo "MAVEN_ARGS_APPEND=$(inputs.params.MAVEN_ARGS_APPEND)" >> env-file

          [[ '$(inputs.params.MAVEN_MIRROR_URL)' != "" ]] &&
            echo "MAVEN_MIRROR_URL=$(inputs.params.MAVEN_MIRROR_URL)" >> env-file

          echo "Generated Env file"
          echo "------------------------------"
          cat env-file
          echo "------------------------------"
      command:
        - /bin/sh
        - '-c'
      image: quay.io/openshift-pipeline/s2i
      name: gen-env-file
      resources: {}
      volumeMounts:
        - mountPath: /env-params
          name: envparams
      workingDir: /env-params
    - command:
        - s2i
        - build
        - $(inputs.params.PATH_CONTEXT)
        - registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift
        - '--image-scripts-url'
        - 'image:///usr/local/s2i'
        - '--as-dockerfile'
        - /gen-source/Dockerfile.gen
        - '--environment-file'
        - /env-params/env-file
      image: quay.io/openshift-pipeline/s2i
      name: generate
      resources: {}
      volumeMounts:
        - mountPath: /gen-source
          name: gen-source
        - mountPath: /env-params
          name: envparams
      workingDir: /workspace/source
    - command:
        - buildah
        - bud
        - '--tls-verify=$(inputs.params.TLSVERIFY)'
        - '--layers'
        - '-f'
        - /gen-source/Dockerfile.gen
        - '-t'
        - $(outputs.resources.image.url)
        - .
      image: 'quay.io/buildah/stable:v1.11.4'
      name: build
      resources: {}
      securityContext:
        privileged: true
      volumeMounts:
        - mountPath: /var/lib/containers
          name: varlibcontainers
        - mountPath: /gen-source
          name: gen-source
      workingDir: /gen-source
    - command:
        - buildah
        - push
        - '--tls-verify=$(inputs.params.TLSVERIFY)'
        - $(outputs.resources.image.url)
        - 'docker://$(outputs.resources.image.url)'
      image: 'quay.io/buildah/stable:v1.11.4'
      name: push
      resources: {}
      securityContext:
        privileged: true
      volumeMounts:
        - mountPath: /var/lib/containers
          name: varlibcontainers
  volumes:
    - emptyDir: {}
      name: varlibcontainers
    - emptyDir: {}
      name: gen-source
    - emptyDir: {}
      name: envparams
