0

I am new to Tekton (https://tekton.dev/) and I am trying to

  1. Clone the repository
  2. Build a docker image with the Dockerfile

I have a Tekton pipeline and when I try to execute it, I get the following error:

Error: error resolving dockerfile path: please provide a valid path to a Dockerfile within the build context with --dockerfile

Please find the Tekton manifests below:

1. Pipeline.yml


apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: clone-read
spec:
  description: | 
    This pipeline clones a git repo, then echoes the README file to the stout.
  params:
  - name: repo-url
    type: string
    description: The git repo URL to clone from.

  - name: image-name
    type: string
    description: for Kaniko

  - name: image-path
    type: string
    description: path of Dockerfile for Kaniko

  workspaces:
  - name: shared-data
    description: | 
      This workspace contains the cloned repo files, so they can be read by the
      next task.

  tasks:
  - name: fetch-source
    taskRef:
      name: git-clone
    workspaces:
    - name: output
      workspace: shared-data
    params:
    - name: url
      value: $(params.repo-url)

  - name: show-readme
    runAfter: ["fetch-source"]
    taskRef:
      name: show-readme
    workspaces:
    - name: source
      workspace: shared-data

  - name: build-push
    runAfter: ["show-readme"]
    taskRef:
      name: kaniko
    workspaces:
    - name: source
      workspace: shared-data
    params:
    - name: IMAGE
      value: $(params.image-name)  
    - name: CONTEXT
      value: $(params.image-path)    

1. PipelineRun.yml

apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: clone-read-run
spec:
  pipelineRef:
    name: clone-read
  podTemplate:
    securityContext:
      fsGroup: 65532
  workspaces:
  - name: shared-data
    volumeClaimTemplate:
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
  # - name: git-credentials
  #   secret:
  #     secretName: git-credentials
  params:
  - name: repo-url
    value: https://github.com/iamdempa/tekton-demos.git

  - name: image-name
    value: "python-test"

  - name: image-path
    value: $(workspaces.shared-data.path)/BuildDockerImage2  

And here's my repository structure:

. . .
.
├── BuildDockerImage2
│   ├── 1.show-readme.yml
│   ├── 2. Pipeline.yml
│   ├── 3. PipelineRun.yml
│   └── Dockerfile
├── README.md

. . .

7 directories, 25 files

Could someone help me what is wrong here?

Thank you

Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105

1 Answers1

0

I was able to find the issue. Issue was with the way I have provided the path.

In the kaniko task, the CONTEXT variable determines the path of the Dockerfile. And the default value is set to ./ and with some additional prefix as below:

$(workspaces.source.path)/$(params.CONTEXT)

That mean, the path of the workspaces is already being appended and I don't need to append that part as I mentioned in the image-path value below:

$(workspaces.shared-data.path)/BuildDockerImage2  

Instead, I had to put just the folder name as below:

  - name: image-path
    value: BuildDockerImage2 

This fixed the problem I had.

Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105