Skip to content

Commit

Permalink
Pass image with digest to the deploy task (#1756)
Browse files Browse the repository at this point in the history
* fix: deploy task explicitly sets --image flag

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fix: PaC with `pack` sets image param for deploy task

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: unify output of s2i and pack build task

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: unify passing of produced image by build tasks

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: style

Signed-off-by: Matej Vasek <mvasek@redhat.com>

---------

Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed May 25, 2023
1 parent 2656a7e commit f8e976c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
default: empty-dir

results:
- name: APP_IMAGE_DIGEST
- name: IMAGE_DIGEST
description: The digest of the built `APP_IMAGE`.

stepTemplate:
Expand Down Expand Up @@ -189,13 +189,13 @@ spec:
script: |
#!/usr/bin/env bash
set -e
cat /layers/report.toml | grep "digest" | cut -d'"' -f2 | cut -d'"' -f2 | tr -d '\n' | tee $(results.APP_IMAGE_DIGEST.path)
cat /layers/report.toml | grep "digest" | cut -d'"' -f2 | cut -d'"' -f2 | tr -d '\n' | tee $(results.IMAGE_DIGEST.path)
############################################
##### Added part for Knative Functions #####
############################################
digest=$(cat $(results.APP_IMAGE_DIGEST.path))
digest=$(cat $(results.IMAGE_DIGEST.path))
func_file="$(workspaces.source.path)/func.yaml"
if [ "$(params.SOURCE_SUBPATH)" != "" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ spec:
- name: func-deploy
image: "ghcr.io/knative/func/func:latest"
script: |
export FUNC_IMAGE="$(params.image)"
func deploy --verbose --build=false --push=false --path=$(params.path) --remote=false
func deploy --verbose --build=false --push=false --path=$(params.path) --remote=false --image="$(params.image)"
6 changes: 1 addition & 5 deletions pkg/pipelines/tekton/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ func generatePipeline(f fn.Function, labels map[string]string) *pplnv1beta1.Pipe

var taskBuild pplnv1beta1.PipelineTask

// Deploy step that uses an image produced by S2I builds needs explicit reference to the image
referenceImageFromPreviousTaskResults := false

var tasks []pplnv1beta1.PipelineTask
var buildPreReq []string

Expand All @@ -104,11 +101,10 @@ func generatePipeline(f fn.Function, labels map[string]string) *pplnv1beta1.Pipe
Default: pplnv1beta1.NewArrayOrString("image:///usr/libexec/s2i")})

taskBuild = taskS2iBuild(buildPreReq)
referenceImageFromPreviousTaskResults = true
}

// ----- Pipeline definition
tasks = append(tasks, taskBuild, taskDeploy(taskNameBuild, referenceImageFromPreviousTaskResults))
tasks = append(tasks, taskBuild, taskDeploy(taskNameBuild))

return &pplnv1beta1.Pipeline{
ObjectMeta: v1.ObjectMeta{
Expand Down
8 changes: 3 additions & 5 deletions pkg/pipelines/tekton/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@ func taskS2iBuild(runAfter []string) pplnv1beta1.PipelineTask {

}

func taskDeploy(runAfter string, referenceImageFromPreviousTaskResults bool) pplnv1beta1.PipelineTask {
func taskDeploy(runAfter string) pplnv1beta1.PipelineTask {

params := []pplnv1beta1.Param{{Name: "path", Value: *pplnv1beta1.NewArrayOrString("$(workspaces.source.path)/$(params.contextDir)")}}

// Deploy step that uses an image produced by S2I builds needs explicit reference to the image
if referenceImageFromPreviousTaskResults {
params = append(params, pplnv1beta1.Param{Name: "image", Value: *pplnv1beta1.NewArrayOrString(fmt.Sprintf("$(params.imageName)@$(tasks.%s.results.IMAGE_DIGEST)", runAfter))})
}
// Deploy step that uses an image produced by builds needs explicit reference to the image
params = append(params, pplnv1beta1.Param{Name: "image", Value: *pplnv1beta1.NewArrayOrString(fmt.Sprintf("$(params.imageName)@$(tasks.%s.results.IMAGE_DIGEST)", runAfter))})

return pplnv1beta1.PipelineTask{
Name: taskNameDeploy,
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipelines/tekton/templates_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ spec:
params:
- name: path
value: $(workspaces.source.path)/$(params.contextDir)
- name: image
value: $(params.imageName)@$(tasks.build.results.IMAGE_DIGEST)
runAfter:
- build
taskRef:
Expand Down

0 comments on commit f8e976c

Please sign in to comment.