apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: skaffold-image-leeroy-web-build-push-kaniko
spec:
  type: image
  params:
  - name: url
    value: localhost:5000/leeroy-web
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: skaffold-git-build-push-kaniko
spec:
  type: git
  params:
  - name: revision
    value: v0.32.0
  - name: url
    value: https://github.com/GoogleContainerTools/skaffold
---
# Builds an image via kaniko and pushes it to registry.
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: build-push-kaniko
spec:
  params:
  - name: pathToDockerFile
    description: The path to the dockerfile to build
    default: /workspace/workspace/Dockerfile
  - name: pathToContext
    description: The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)
    default: /workspace/workspace
  resources:
    inputs:
    - name: workspace
      type: git
    outputs:
    - name: builtImage
      type: image
  steps:
  - name: build-and-push
    image: gcr.io/kaniko-project/executor:v0.17.1
    # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential
    env:
    - name: "DOCKER_CONFIG"
      value: "/tekton/home/.docker/"
    args:
    - --dockerfile=$(inputs.params.pathToDockerFile)
    - --destination=$(outputs.resources.builtImage.url)
    - --context=$(inputs.params.pathToContext)
    - --oci-layout-path=$(inputs.resources.builtImage.path)
    securityContext:
      runAsUser: 0
  sidecars:
    - image: registry
      name: registry
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: build-push-kaniko
spec:
  taskRef:
    name: build-push-kaniko
  resources:
    inputs:
    - name: workspace
      resourceRef:
        name: skaffold-git-build-push-kaniko
    outputs:
    - name: builtImage
      resourceRef:
        name: skaffold-image-leeroy-web-build-push-kaniko
  params:
  - name: pathToDockerFile
    value: Dockerfile
  - name: pathToContext
    value: /workspace/workspace/examples/microservices/leeroy-web
