Kaniko unable to resolve dockerfike path in concourse build pipeline

177 Views Asked by At

I'm trying to setup a concourse pipeline that builds an image and pushes it to a quay registry. However, it keeps failing with:

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

This is the pipeline file:

resources:
- name: source-code
  type: git
  source:
    uri: gitlab.git
    branch: main
    username: ((gitlab-auth.username))
    password: ((gitlab-auth.password))

- name: kaniko-image
  type: registry-image
  source:
    repository: gcr.io/kaniko-project/executor
    tag: debug

- name: push-image
  type: registry-image
  source:
    repository: quay.io/gitlab
    username: ((quay-gitlab-mr.username))
    password: ((quay-gitlab-mr.password))

jobs:
- name: build-and-push-image
  plan:
  - get: source-code
    trigger: true
  - get: kaniko-image
  - task: build-task-image
    config:
      platform: linux
      image_resource:
        type: registry-image
        source:
          repository: quay.io
          tag: kaniko-v1
      inputs:
      - name: source-code
      params:
        CONTEXT: source-code
        DOCKERFILE: Dockerfile
        IMAGE_NAME: quay.io/gitlab
        TAG: 1.0.5
      run:
        path: /kaniko/executor
        args:
        - --context=${CONTEXT}
        - --destination=${IMAGE_NAME}:${TAG}
        - --dockerfile=${DOCKERFILE}
        - --force
  - put: push-image
    params:
      image: source-code/image.tar

My understanding is that when concourse pulls the source code down into the worker, it does so in a directory called source-code so thats where the Dockerfile should be as it is in the root of my directory. I have tried using workspace, variations of directory structures and specifying the tmp dir where the concourse logs show it is cloning to. But all result in the same error

When I don't use Kaniko and just do a normal build in a privileged task, I can build the image fine and push. But it fails with Kaniko and I cannot run privileged in my use case.

Any ideas what is wrong?

1

There are 1 best solutions below

0
Martin On

Well, I had quite some trauma from this one. I got it working for a project so I can give you two essential tips when working with concourse and kaniko:

  1. Note that concourse will put inputs into a specifically named subfolder in /tmp, which is probably different every time. You can fix this (although I don't know if this is intended as the documentation seems to tell that absolute paths are not allowed) by providing an absolute path where the input should be put.

  2. The problem is you are not calling a shell, which means there is no substitution from environment variables. If you put the arguments directly into the args, it works.

Example:

  - task: kaniko-build-buildah
    config:
      platform: linux
      image_resource:
        type: registry-image
        source:
          repository: gcr.io/kaniko-project/executor
          tag: v1.22.0
      inputs:
        - name: repo
          path: /workspace/repo
      run:
        path: /kaniko/executor
        args:
          - --dockerfile=Containerfile
          - --context=dir:///workspace/repo/dockerfile_dir
          - --destination=registry/repo/image:latest
          - --cache=true