apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: kaniko labels: app.kubernetes.io/version: "0.1" annotations: tekton.dev/pipelines.minVersion: "0.12.1" tekton.dev/categories: Image Build tekton.dev/tags: image-build tekton.dev/platforms: "linux/amd64" tekton.dev/deprecated: "true" spec: description: >- This Task builds source into a container image using Google's kaniko tool. Kaniko doesn't depend on a Docker daemon and executes each command within a Dockerfile completely in userspace. This enables building container images in environments that can't easily or securely run a Docker daemon, such as a standard Kubernetes cluster. params: - name: IMAGE description: Name (reference) of the image to build. - name: DOCKERFILE description: Path to the Dockerfile to build. default: ./Dockerfile - name: CONTEXT description: The build context used by Kaniko. default: ./ - name: EXTRA_ARGS default: "" - name: BUILDER_IMAGE description: The image on which builds will run default: gcr.io/kaniko-project/executor@sha256:e36c9fa99279217c4bb8ee172819b441c3ca8ef946dc0e28b21721eefb2ba70a workspaces: - name: source results: - name: IMAGE-DIGEST description: Digest of the image just built. steps: - name: build-and-push workingDir: $(workspaces.source.path) image: $(params.BUILDER_IMAGE) # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential # https://github.com/tektoncd/pipeline/pull/706 env: - name: DOCKER_CONFIG value: /tekton/home/.docker command: - /kaniko/executor - $(params.EXTRA_ARGS) - --dockerfile=$(params.DOCKERFILE) - --context=$(workspaces.source.path)/$(params.CONTEXT) # The user does not need to care the workspace and the source. - --destination=$(params.IMAGE) - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest # kaniko assumes it is running as root, which means this example fails on platforms # that default to run containers as random uid (like OpenShift). Adding this securityContext # makes it explicit that it needs to run as root. securityContext: runAsUser: 0 - name: write-digest workingDir: $(workspaces.source.path) image: ghcr.io/tektoncd/github.com/tektoncd/pipeline/cmd/imagedigestexporter:v0.16.2 # output of imagedigestexport [{"key":"digest","value":"sha256:eed29..660","resourceRef":{"name":"myrepo/myimage"}}] command: ["/ko-app/imagedigestexporter"] args: - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] - -terminationMessagePath=$(params.CONTEXT)/image-digested securityContext: runAsUser: 0 - name: digest-to-results workingDir: $(workspaces.source.path) image: docker.io/stedolan/jq@sha256:a61ed0bca213081b64be94c5e1b402ea58bc549f457c2682a86704dd55231e09 script: | cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee $(results.IMAGE-DIGEST.path)