我是Tekton
的新手(https://tekton.dev/)我正在尝试
- 克隆存储库
- 使用
Dockerfile
构建docker映像
我有一个Tekton
管道,当我尝试执行它时,我会得到以下错误:
错误:解析dockerfile路径时出错:请使用--dockerfile 在构建上下文中提供一个dockerfile的有效路径
请在下面找到Tekton
清单:
1.管道.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
这是我的存储库结构:
. . .
.
├── BuildDockerImage2
│ ├── 1.show-readme.yml
│ ├── 2. Pipeline.yml
│ ├── 3. PipelineRun.yml
│ └── Dockerfile
├── README.md
. . .
7 directories, 25 files
有人能帮我这里怎么了吗?
谢谢
我找到了这个问题。问题在于我提供路径的方式。
在kaniko
任务中,CONTEXT
变量确定Dockerfile
的路径。默认值设置为./
,并带有一些附加前缀,如下所示:
$(workspaces.source.path)/$(params.CONTEXT)
这意味着,workspaces
的路径已经被附加,我不需要像下面的image-path
值中提到的那样附加该部分:
$(workspaces.shared-data.path)/BuildDockerImage2
相反,我不得不将文件夹名称如下:
- name: image-path
value: BuildDockerImage2
这解决了我的问题。