我正在尝试设置一个大厅管道来构建图像并将其推送到码头注册表。然而,它一直失败:
Error: error resolving dockerfile path: please provide a valid path to a Dockerfile within the build context with --dockerfile
这是管道文件:
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
我的理解是,当 concourse 将源代码拉入工作程序时,它会在名为 source-code 的目录中执行此操作,因此 Dockerfile 应该位于我的目录根目录中。我尝试过使用工作区、目录结构的变体并指定大厅日志显示它正在克隆到的 tmp 目录。但所有结果都会导致相同的错误
当我不使用 Kaniko 而只是在特权任务中进行正常构建时,我可以很好地构建图像并推送。但 Kaniko 失败了,我无法在我的用例中以特权运行。
有什么想法是错的吗?
嗯,这件事给我带来了很大的创伤。我让它在一个项目中工作,所以我可以在使用 concourse 和 kaniko 时为您提供两个基本提示:
请注意,concourse 会将输入放入 /tmp 中专门命名的子文件夹中,该子文件夹每次可能都不同。您可以通过提供应放置输入的绝对路径来解决此问题(尽管我不知道这是否是有意为之,因为文档似乎告诉不允许绝对路径)。
问题是您没有调用 shell,这意味着没有环境变量的替换。如果将参数直接放入 args 中,它就可以工作。
示例:
- 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